public function testExecute() { $application = new Stratum(); $application->setAutoExit(false); $tester = new ApplicationTester($application); $tester->run(['config file' => 'test/MySql/etc/stratum.cfg']); $this->assertSame(0, $tester->getStatusCode(), $tester->getDisplay()); }
/** * Test Successful doRun. */ function testExistingHubApplication() { // 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(TRUE); $app = new Console\Application(); // Set autoExit to false when testing & do not let it catch exceptions. $app->setAutoExit(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()); }
public function testRunWithErrorFailingStatusCode() { $application = new Application(); $application->setDispatcher($this->getDispatcher()); $application->setAutoExit(false); $application->register('dus')->setCode(function (InputInterface $input, OutputInterface $output) { $output->write('dus.'); throw new \Error('duserr'); }); $tester = new ApplicationTester($application); $tester->run(array('command' => 'dus')); $this->assertSame(1, $tester->getStatusCode(), 'Status code should be 1'); }
public function testRunAsRoot() { $stub = $this->getMock('SugarCli\\Console\\Application', array('isRunByRoot'), array('test', 'test')); $stub->method('isRunByRoot')->willReturn(true); $stub->setAutoExit(false); $stub->add(new TestCommand()); $selfupdate_cmd = new TestCommand(); $selfupdate_cmd->setName('list'); $stub->add($selfupdate_cmd); $tester = new ApplicationTester($stub); $tester->run(array('command' => 'test:command')); $this->assertEquals(6, $tester->getStatusCode()); $this->assertEquals('You are not allowed to run this command as root.' . PHP_EOL, $tester->getDisplay()); $tester = new ApplicationTester($stub); $tester->run(array('command' => 'list')); $this->assertEquals(0, $tester->getStatusCode()); $this->assertEquals(PHP_EOL, $tester->getDisplay()); }
/** * @return int 0 success otherwise fail */ public function getExitCode() { return $this->tester->getStatusCode() !== null ? $this->tester->getStatusCode() : 1; }