diff --git a/composer.json b/composer.json index 463353e..acc3fe4 100644 --- a/composer.json +++ b/composer.json @@ -31,6 +31,11 @@ "src/Deployer/functions.php" ] }, + "autoload-dev": { + "psr-4": { + "Hypernode\\Deploy\\": "tests/unit" + } + }, "require-dev": { "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)); + } +}