/** * Test that flo does not work without hub & process mocking. * * @expectedException \RuntimeException * @expectedExceptionMessageRegExp #hub not found# */ function testMissingHubApplication() { // Create a Mock Process Object. $process = $this->getMockBuilder('Symfony\\Component\\Process\\Process')->disableOriginalConstructor()->getMock(); // Make sure the isSuccessful method return FALSE so flo throws an exception. $process->method('isSuccessful')->willReturn(FALSE); $process->method('getErrorOutput')->willReturn('hub not found'); $app = new Console\Application(); // Set autoExit to false when testing & do not let it catch exceptions. $app->setAutoExit(TRUE); $app->setCatchExceptions(FALSE); // Overwrite Symfony\Component\Process\Process with our mock Process. $app->setProcess($process); // Run a command and wait for the exception. $appTester = new ApplicationTester($app); $appTester->run(array('command' => 'help')); $this->assertEquals(0, $appTester->getStatusCode()); }
/** * Test run-script sh process failing. */ public function testSHScripException() { $this->writeConfig(); // Create scripts/post-deploy.sh. $post_deploy_script = <<<EOT #!/usr/bin/env bash echo "hello \$1" EOT; $this->fs->dumpFile($this->root . "/scripts/post-deploy.sh", $post_deploy_script); // Create a Mock Process Object. $process = $this->getMockBuilder('Symfony\\Component\\Process\\Process')->disableOriginalConstructor()->getMock(); // Make sure the isSuccessful method return FALSE so flo throws an exception. $process->method('isSuccessful')->willReturn(FALSE); $process->method('getErrorOutput')->willReturn('sh failed'); // Run the command. $app = new Application(); // Set autoExit to false when testing & do not let it catch exceptions. $app->setAutoExit(TRUE); $app->setCatchExceptions(FALSE); $app->setProcess($process); $command_run_script = $app->find('run-script'); $command_tester = new CommandTester($command_run_script); $command_tester->execute(array('command' => $command_run_script->getName(), 'script' => 'post_deploy_cmd', 'args' => array('world'))); // Check the output of the command. $this->assertEquals("sh failed", trim($command_tester->getDisplay())); }