diff --git a/src/Mage/Tests/Command/BuiltIn/DeployCommandMiscTasksTest.php b/src/Mage/Tests/Command/BuiltIn/DeployCommandMiscTasksTest.php index a7fb063..c813e21 100644 --- a/src/Mage/Tests/Command/BuiltIn/DeployCommandMiscTasksTest.php +++ b/src/Mage/Tests/Command/BuiltIn/DeployCommandMiscTasksTest.php @@ -97,4 +97,61 @@ class DeployCommandMiscTasksTest extends TestCase $this->assertEquals(7, $tester->getStatusCode()); $this->assertContains('Invalid task name "invalid/task"', $tester->getDisplay()); } + + public function testBrokenGitBranch() + { + $application = new MageApplicationMockup(); + $application->configure(__DIR__ . '/../../Resources/broken-git-branch.yml'); + + /** @var AbstractCommand $command */ + $command = $application->find('deploy'); + $this->assertTrue($command instanceof DeployCommand); + + $tester = new CommandTester($command); + + $application->getRuntime()->forceFail('git branch | grep "*"'); + + $tester->execute(['command' => $command->getName(), 'environment' => 'test']); + + $this->assertContains('Running [Git] Change Branch (broken-test) ... FAIL', $tester->getDisplay()); + $this->assertNotEquals(0, $tester->getStatusCode()); + } + + public function testBrokenGitCheckout() + { + $application = new MageApplicationMockup(); + $application->configure(__DIR__ . '/../../Resources/broken-git-branch.yml'); + + /** @var AbstractCommand $command */ + $command = $application->find('deploy'); + $this->assertTrue($command instanceof DeployCommand); + + $tester = new CommandTester($command); + + $application->getRuntime()->forceFail('git checkout broken-test'); + + $tester->execute(['command' => $command->getName(), 'environment' => 'test']); + + $this->assertContains('Running [Git] Change Branch (broken-test) ... FAIL', $tester->getDisplay()); + $this->assertNotEquals(0, $tester->getStatusCode()); + } + + public function testBrokenGitUpdate() + { + $application = new MageApplicationMockup(); + $application->configure(__DIR__ . '/../../Resources/broken-git-branch.yml'); + + /** @var AbstractCommand $command */ + $command = $application->find('deploy'); + $this->assertTrue($command instanceof DeployCommand); + + $tester = new CommandTester($command); + + $application->getRuntime()->forceFail('git pull'); + + $tester->execute(['command' => $command->getName(), 'environment' => 'test']); + + $this->assertContains('Running [Git] Update ... FAIL', $tester->getDisplay()); + $this->assertNotEquals(0, $tester->getStatusCode()); + } } diff --git a/src/Mage/Tests/Resources/broken-git-branch.yml b/src/Mage/Tests/Resources/broken-git-branch.yml new file mode 100644 index 0000000..7263cf7 --- /dev/null +++ b/src/Mage/Tests/Resources/broken-git-branch.yml @@ -0,0 +1,15 @@ +magephp: + log_dir: /tmp + environments: + test: + user: tester + branch: broken-test + host_path: /var/www/test + exclude: + - ./var/cache/* + - ./var/log/* + - ./web/app_dev.php + hosts: + - githost1 + pre-deploy: + - git/update diff --git a/src/Mage/Tests/Runtime/ProcessMockup.php b/src/Mage/Tests/Runtime/ProcessMockup.php index ede851d..d076467 100644 --- a/src/Mage/Tests/Runtime/ProcessMockup.php +++ b/src/Mage/Tests/Runtime/ProcessMockup.php @@ -14,6 +14,7 @@ use Symfony\Component\Process\Process; class ProcessMockup extends Process { + public $forceFail = []; protected $commandline; protected $timeout; protected $success = true; @@ -30,6 +31,10 @@ class ProcessMockup extends Process public function run($callback = null) { + if (in_array($this->commandline, $this->forceFail)) { + $this->success = false; + } + if ($this->commandline == 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@host1 sh -c \"readlink -f /var/www/test/current\"') { $this->success = false; } diff --git a/src/Mage/Tests/Runtime/RuntimeMockup.php b/src/Mage/Tests/Runtime/RuntimeMockup.php index 23a05bf..622da0c 100644 --- a/src/Mage/Tests/Runtime/RuntimeMockup.php +++ b/src/Mage/Tests/Runtime/RuntimeMockup.php @@ -16,6 +16,7 @@ use Symfony\Component\Process\Process; class RuntimeMockup extends Runtime { protected $ranCommands = []; + protected $forceFail = []; public function getRanCommands() { @@ -45,6 +46,7 @@ class RuntimeMockup extends Runtime $this->ranCommands[] = $cmd; $process = new ProcessMockup($cmd); + $process->forceFail = $this->forceFail; $process->setTimeout($timeout); $process->run(); @@ -72,4 +74,9 @@ class RuntimeMockup extends Runtime $this->environment = $environment; return $this; } + + public function forceFail($cmd) + { + $this->forceFail[] = $cmd; + } }