From af75ef41cb7d6683d6629942cd5a9bf70475d0e9 Mon Sep 17 00:00:00 2001 From: Timon de Groot Date: Thu, 21 Jul 2022 13:26:43 +0200 Subject: [PATCH 1/2] Add basic unit tests --- composer.json | 6 +++ phpunit.xml | 10 +++++ tests/unit/Command/BuildTest.php | 52 +++++++++++++++++++++ tests/unit/Command/ComposerAuthTest.php | 52 +++++++++++++++++++++ tests/unit/Command/DeployTest.php | 60 +++++++++++++++++++++++++ tests/unit/Command/RunTaskTest.php | 60 +++++++++++++++++++++++++ 6 files changed, 240 insertions(+) create mode 100644 phpunit.xml create mode 100644 tests/unit/Command/BuildTest.php create mode 100644 tests/unit/Command/ComposerAuthTest.php create mode 100644 tests/unit/Command/DeployTest.php create mode 100644 tests/unit/Command/RunTaskTest.php diff --git a/composer.json b/composer.json index 463353e..7c0d0df 100644 --- a/composer.json +++ b/composer.json @@ -31,7 +31,13 @@ "src/Deployer/functions.php" ] }, + "autoload-dev": { + "psr-4": { + "Hypernode\\Deploy\\": "tests/unit" + } + }, "require-dev": { + "php-mock/php-mock-phpunit": "^2.6", "phpunit/phpunit": "^8.5", "roave/security-advisories": "dev-master" }, diff --git a/phpunit.xml b/phpunit.xml new file mode 100644 index 0000000..a9b17c3 --- /dev/null +++ b/phpunit.xml @@ -0,0 +1,10 @@ + + + + tests/unit + + + diff --git a/tests/unit/Command/BuildTest.php b/tests/unit/Command/BuildTest.php new file mode 100644 index 0000000..4b64b7d --- /dev/null +++ b/tests/unit/Command/BuildTest.php @@ -0,0 +1,52 @@ +deployRunner = $this->createMock(DeployRunner::class); + $this->input = $this->createMock(InputInterface::class); + $this->output = $this->createMock(OutputInterface::class); + $this->command = new Build($this->deployRunner); + } + + public function test_it_calls_deploy_runner_correctly() + { + $this->deployRunner->expects($this->once()) + ->method('run') + ->with($this->output, 'build', 'build'); + + $this->command->run($this->input, $this->output); + } + + public function test_it_returns_zero() + { + $this->assertEquals(0, $this->command->run($this->input, $this->output)); + } +} diff --git a/tests/unit/Command/ComposerAuthTest.php b/tests/unit/Command/ComposerAuthTest.php new file mode 100644 index 0000000..2b981cb --- /dev/null +++ b/tests/unit/Command/ComposerAuthTest.php @@ -0,0 +1,52 @@ +deployRunner = $this->createMock(DeployRunner::class); + $this->input = $this->createMock(InputInterface::class); + $this->output = $this->createMock(OutputInterface::class); + $this->command = new ComposerAuth($this->deployRunner); + } + + public function test_it_calls_deploy_runner_correctly() + { + $this->deployRunner->expects($this->once()) + ->method('run') + ->with($this->output, 'build', 'deploy:vendors:auth'); + + $this->command->run($this->input, $this->output); + } + + public function test_it_returns_zero() + { + $this->assertEquals(0, $this->command->run($this->input, $this->output)); + } +} diff --git a/tests/unit/Command/DeployTest.php b/tests/unit/Command/DeployTest.php new file mode 100644 index 0000000..3948c8f --- /dev/null +++ b/tests/unit/Command/DeployTest.php @@ -0,0 +1,60 @@ +deployRunner = $this->createMock(DeployRunner::class); + $this->input = $this->createMock(InputInterface::class); + $this->output = $this->createMock(OutputInterface::class); + $this->command = new Deploy($this->deployRunner); + } + + protected function assertPreConditions(): void + { + $this->input->expects($this->once()) + ->method('getArgument') + ->with('stage') + ->willReturn('production'); + } + + public function test_it_calls_deploy_runner_correctly() + { + $this->deployRunner->expects($this->once()) + ->method('run') + ->with($this->output, 'production', 'deploy'); + + $this->command->run($this->input, $this->output); + } + + public function test_it_returns_zero() + { + $this->assertEquals(0, $this->command->run($this->input, $this->output)); + } +} diff --git a/tests/unit/Command/RunTaskTest.php b/tests/unit/Command/RunTaskTest.php new file mode 100644 index 0000000..d8c188e --- /dev/null +++ b/tests/unit/Command/RunTaskTest.php @@ -0,0 +1,60 @@ +deployRunner = $this->createMock(DeployRunner::class); + $this->input = $this->createMock(InputInterface::class); + $this->output = $this->createMock(OutputInterface::class); + $this->command = new RunTask($this->deployRunner); + } + + protected function assertPreConditions(): void + { + $this->input->expects($this->exactly(2)) + ->method('getArgument') + ->withConsecutive(['stage'], ['task']) + ->willReturnOnConsecutiveCalls('production', 'sample_task'); + } + + public function test_it_calls_deploy_runner_correctly() + { + $this->deployRunner->expects($this->once()) + ->method('run') + ->with($this->output, 'production', 'sample_task'); + + $this->command->run($this->input, $this->output); + } + + public function test_it_returns_zero() + { + $this->assertEquals(0, $this->command->run($this->input, $this->output)); + } +} From 29a2ee38e941468a5024b4de25adffcdea9fc91f Mon Sep 17 00:00:00 2001 From: Timon de Groot Date: Thu, 21 Jul 2022 13:27:27 +0200 Subject: [PATCH 2/2] Remove obselete dev dependency --- composer.json | 1 - 1 file changed, 1 deletion(-) diff --git a/composer.json b/composer.json index 7c0d0df..acc3fe4 100644 --- a/composer.json +++ b/composer.json @@ -37,7 +37,6 @@ } }, "require-dev": { - "php-mock/php-mock-phpunit": "^2.6", "phpunit/phpunit": "^8.5", "roave/security-advisories": "dev-master" },