/** * Execute command with tester. * * @param string $command * @param array $args * @param array $options * @return string Display result. */ protected function exec($command, $args = [], $options = []) { $this->tester->run(['command' => $command] + $args, $options); // Clear realpath cache. clearstatcache(self::$deployPath); return $this->tester->getDisplay(); }
/** * @Then I should see: */ public function iShouldSee(PyStringNode $content) { $displayArray = explode("\n", $this->tester->getDisplay()); array_walk($displayArray, function (&$line) { $line = rtrim($line); }); expect($displayArray)->shouldBeLike($content->getStrings()); }
public function test_CommandSkipsExisitingUsers_IfSkipExistingOptionUsed() { $this->addPreexistingSuperUser(); $result = $this->applicationTester->run(array('command' => 'loginldap:synchronize-users', '--login' => array('ironman', 'captainamerica'), '--skip-existing' => true, '-v' => true)); $this->assertEquals(0, $result, $this->getCommandDisplayOutputErrorMessage()); $this->assertContains("Skipping 'captainamerica', already exists in Piwik...", $this->applicationTester->getDisplay()); $users = $this->getLdapUserLogins(); $this->assertEquals(array('ironman'), $users); }
/** * @param string $command * @param string $file * @param PyStringNode $options * * @When /^I run (?P<command>[a-zA-Z0-9\.\:]*) command with file \"(?P<file>[^\"]*)\"$/ * @When /^I run (?P<command>[a-zA-Z0-9\.\:]*) command with file \"(?P<file>[^\"]*)\" and options:$/ */ public function iRunCommand($command, $file = null, PyStringNode $options = null) { $arguments = array('command' => $command, 'name' => 'Test'); $arguments['configuration-file'] = __DIR__ . "/../../" . $file; $options = $this->parseOptions($options); $arguments += $options; $runOptions = array('interactive' => false, 'decorated' => false); $this->lastExitCode = $this->tester->run($arguments, $runOptions); $this->lastDisplay = $this->tester->getDisplay(); }
public function testLimit() { $app = new Application(); $app->add(new FizzBuzzCommand()); $app->setAutoExit(false); // For testing $tester = new ApplicationTester($app); $tester->run(array('--limit' => '15'), array('decorated' => false)); $this->assertContains("14", $tester->getDisplay(true)); $this->assertContains("Fizz Buzz", $tester->getDisplay(true)); $this->assertNotContains("16", $tester->getDisplay(true)); }
public function test_FixDuplicateLogActions_CorrectlyRemovesDuplicates_AndFixesReferencesInOtherTables() { $result = $this->applicationTester->run(array('command' => 'core:fix-duplicate-log-actions', '--invalidate-archives' => 0, '-vvv' => false)); $this->assertEquals(0, $result, "Command failed: " . $this->applicationTester->getDisplay()); $this->assertDuplicateActionsRemovedFromLogActionTable(); $this->assertDuplicatesFixedInLogLinkVisitActionTable(); $this->assertDuplicatesFixedInLogConversionTable(); $this->assertDuplicatesFixedInLogConversionItemTable(); $this->assertContains("Found and deleted 7 duplicate action entries", $this->applicationTester->getDisplay()); $expectedAffectedArchives = array(array('idsite' => '1', 'server_time' => '2012-01-01'), array('idsite' => '2', 'server_time' => '2013-01-01'), array('idsite' => '1', 'server_time' => '2012-02-01'), array('idsite' => '2', 'server_time' => '2012-01-09'), array('idsite' => '2', 'server_time' => '2012-03-01')); foreach ($expectedAffectedArchives as $archive) { $this->assertContains("[ idSite = {$archive['idsite']}, date = {$archive['server_time']} ]", $this->applicationTester->getDisplay()); } }
public function testRunWithConfigThrowExceptionIfExtensionClassDoesNotImplementsInterface() { $application = new ApplicationTester($this->carew); $statusCode = $application->run(array('command' => 'list', '--base-dir' => __DIR__ . '/Command/fixtures/config-exception-class-not-implements')); $this->assertSame(1, $statusCode); $this->assertContains('The class "stdClass" does not implements ExtensionInterface. See "config.yml".', $application->getDisplay()); }
private function checkApplicationOutput($output) { $expected = $this->normalize($output); $actual = $this->normalize($this->tester->getDisplay(true)); if (strpos($actual, $expected) === false) { throw new \Exception(sprintf("Application output did not contain expected '%s'. Actual output:\n'%s'", $expected, $this->tester->getDisplay())); } }
public function testRun() { $application = new Application(); $application->setAutoExit(false); $applicationTester = new ApplicationTester($application); $applicationTester->run([]); $this->assertContains('WebHelper version 0.2', $applicationTester->getDisplay([])); }
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()); }
public function testLoadedCommandRuns() { $this->markTestSkipped('The ' . __CLASS__ . ' Symfony ... Console App ... so difficult to extend and test :['); $consoleApp = new Console(); $consoleApp->setAutoExit(false); $tester = new ApplicationTester($consoleApp); $tester->run(array('command' => 'test:command', 'name' => 'Skip', '--skip-app-path' => './tests/fixtures/app')); $this->assertContains('Nice name you got there, Skip.', $tester->getDisplay()); }
/** * Confirm that all the core commands with bootstrap level * `BOOT_SUGAR_ROOT` will be available by default. */ public function testDebugOutput() { $kernel = $this->getKernel(Kernel::BOOT_INSULIN, null, true); $insulin = new Application($kernel); $insulin->setAutoExit(false); $insulinTester = new ApplicationTester($insulin); $insulinTester->run(array('command' => 'list')); $this->assertRegExp('/Memory usage: (.*)MB \\(peak: (.*)MB\\), time: (.*)s/', $insulinTester->getDisplay()); }
public function testInvalidConnectionCausesError() { $kernel = $this->createKernel('badconn.yml'); $console = new Application($kernel); $console->setAutoExit(false); $tester = new ApplicationTester($console); $this->assertGreaterThan(0, $tester->run(['pheanstalk:stats', 'tube' => ['default']])); $this->assertContains('Pheanstalk\\Exception', $tester->getDisplay()); }
/** * @covers ImboCli\Application::__construct */ public function testAddsCommands() { $application = new Application(); $application->setAutoExit(false); $applicationTester = new ApplicationTester($application); $applicationTester->run(array('command' => 'list')); $output = $applicationTester->getDisplay(); $this->assertContains('generate-private-key', $output); }
public function testTestBeforeAndAfterAncestryCommand() { $application = new Application($this->container); $application->setAutoExit(false); $applicationTester = new ApplicationTester($application); $applicationTester->run(array("command" => "testAncestry1", "--verbose" => 3)); $output = $applicationTester->getDisplay(); $this->assertRegExp("/Skip a before task testAncestry1 to prevent infinite loop. Because of existing it in ancestry tasks./", $output); // echo $output; }
public function testVerboseBuildForProject() { $project = $this->getMockBuilder('Sismo\\Project')->disableOriginalConstructor()->getMock(); $this->app['sismo']->expects($this->once())->method('hasProject')->will($this->returnValue(true)); $this->app['sismo']->expects($this->once())->method('getProject')->will($this->returnValue($project)); $this->app['sismo']->expects($this->once())->method('build'); $tester = new ApplicationTester($this->console); $this->assertEquals(0, $tester->run(array('command' => 'build', 'slug' => 'Twig', '--verbose' => true))); $this->assertEquals('Building Project "" (into "d41d8c")', trim($tester->getDisplay())); }
public function testExecute() { self::bootKernel(); $application = new Application(static::$kernel); $application->setCatchExceptions(false); $application->setAutoExit(false); $tester = new ApplicationTester($application); $tester->run(['command' => 'api:swagger:export']); $this->assertJson($tester->getDisplay()); }
public function testProfileRun() { $application = new Application('1337'); $application->setAutoExit(false); $application->setCatchExceptions(false); $tester = new ApplicationTester($application); $tester->run(array('--profile' => true), array('decorated' => false)); $output = $tester->getDisplay(true); $this->assertContains('Environaut version 1337', $output); $this->assertContains('Memory usage: ', $output); }
/** * @covers ::getCommandName * @covers ::getDefinition */ public function testCanRunCommandWithoutSpecifyingName() { // Replace command by a mock. $mock = $this->getMockBuilder('MaartenStaa\\PHPTA\\CLI\\Command')->setMethods(array('execute'))->getMock(); $mock->expects($this->once())->method('execute'); $application = new Application(); $application->setAutoExit(false); $application->add($mock); $tester = new ApplicationTester($application); $tester->run(array()); $this->assertEquals('', $tester->getDisplay()); }
public function testConsoleInjectsContainer() { $console = new ConsoleApplication(); $console->setAutoExit(false); $console->setConfigLoaderCallback(function (InputInterface $input, $env = false, $devUser = false) { // test config $mockConfigLoader = $this->getMock('Skip\\ConfigLoader', array('load'), array(), '', FALSE); $mockConfigLoader->expects($this->once())->method('load')->will($this->returnValue(array('settings' => array('env' => $env, 'dev.user' => $devUser), 'console' => array('commands' => array('Skip\\Test\\Helper\\TestConsoleCommand'))))); return $mockConfigLoader; }); $tester = new ApplicationTester($console); $tester->run(array('command' => 'test:command', '--env' => 'test-env', '--devuser' => 'test-user')); $output = $tester->getDisplay(); $this->assertRegExp('/runtime env is test-env/', $output); $this->assertRegExp('/runtime dev.user is test-user/', $output); }
public function testRunningMigrations() { static::bootKernel(); $container = static::$kernel->getContainer(); $app = new ApplicationTester($a = new Application(static::$kernel)); $a->setAutoExit(false); // reset, in case tests were run previously $container->get('wouterj_eloquent.migrator')->reset($container->get('wouterj_eloquent.migrator')->paths()); $app->run(['command' => 'eloquent:migrate', '--seed' => true], ['decorated' => false]); $this->assertContains('Migrated: 2015_02_16_203700_CreateUsersTable', $app->getDisplay()); $result = Db::select('select * from users'); $this->assertCount(1, $result); $user = $result[0]; $this->assertEquals('John Doe', $user->name); $this->assertEquals('*****@*****.**', $user->email); $this->assertEquals('pa$$word', $user->password); }
public function testGenerateUnitTestCommand() { $kernel = $this->createKernel(); $command = new GenerateUnitTestCommand(); $application = new Application($kernel); $application->setAutoExit(false); $tester = new ApplicationTester($application); $bundle = 'Sweet\\ScaffoldBundle'; $filename = 'indexControllerTest'; $path = 'Controller'; $tester->run(array('command' => $command->getFullName(), 'bundle' => $bundle, 'filename' => $filename, 'path' => $path)); $this->assertRegExp('/\\[File\\+\\]/', $tester->getDisplay()); $fullpath = 'src/Sweet/ScaffoldBundle/Tests/Controller/indexControllerTest.php'; $this->assertFileExists($fullpath); $content = fread(fopen($fullpath, 'r'), filesize($fullpath)); $this->assertContains('namespace Sweet\\ScaffoldBundle\\Tests\\Controller;', $content); $this->assertContains('class indexControllerTest extends \\PHPUnit_Framework_TestCase', $content); }
/** * @dataProvider viewProvider * * @param string $view Command view option value * @param array $expectedMethodsCount Expected resource methods count * @param array $expectedMethodValues Expected resource method values */ public function testDumpWithViewOption($view, array $expectedMethodsCount, array $expectedMethodValues) { $this->getContainer(); $application = new Application(static::$kernel); $application->setCatchExceptions(false); $application->setAutoExit(false); $tester = new ApplicationTester($application); $input = array('command' => 'api:doc:dump', '--view' => $view, '--format' => 'json'); $tester->run($input); $display = $tester->getDisplay(); $this->assertJson($display); $json = json_decode($display); $accessor = PropertyAccess::createPropertyAccessor(); foreach ($expectedMethodsCount as $propertyPath => $expectedCount) { $this->assertCount($expectedCount, $accessor->getValue($json, $propertyPath)); } foreach ($expectedMethodValues as $propertyPath => $expectedValue) { $this->assertEquals($expectedValue, $accessor->getValue($json, $propertyPath)); } }
public function testApplicationLifeCycle() { // run the command application $recipe = (include realpath(__DIR__ . '/../Stubs/Shuntfile')); $shuntApp = new Application($recipe, true); $applicationTester = new ApplicationTester($shuntApp); // Check the collector - recipe life-cycle $applicationTester->run(array('command' => 'list')); // Ensure it contains all specified hosts within recipe stub $this->assertContains('mirror', $applicationTester->getDisplay()); // Ensure it contains all specified tasks within recipe stub $this->assertContains('read_home_dir', $applicationTester->getDisplay()); $this->assertContains('print_php_info', $applicationTester->getDisplay()); $this->assertContains('whoami', $applicationTester->getDisplay()); // Check shunt task life-cycle $applicationTester->run(array('command' => 'whoami', 'host' => '.')); $this->assertContains('localhost > shunt', $applicationTester->getDisplay()); $applicationTester->run(array('command' => 'whoami', 'host' => 'mirror')); $this->assertContains('localhost > shunt', $applicationTester->getDisplay()); // Invalid shunt task $this->setExpectedException('InvalidArgumentException', 'Invalid host:non-exists-host'); $applicationTester->run(array('command' => 'whoami', 'host' => 'non-exists-host')); }
public function testSetRunCustomDefaultCommand() { $command = new \FooCommand(); $application = new Application(); $application->setAutoExit(false); $application->add($command); $application->setDefaultCommand($command->getName()); $tester = new ApplicationTester($application); $tester->run(array()); $this->assertEquals('interact called' . PHP_EOL . 'called' . PHP_EOL, $tester->getDisplay(), 'Application runs the default set command if different from \'list\' command'); $application = new CustomDefaultCommandApplication(); $application->setAutoExit(false); $tester = new ApplicationTester($application); $tester->run(array()); $this->assertEquals('interact called' . PHP_EOL . 'called' . PHP_EOL, $tester->getDisplay(), 'Application runs the default set command if different from \'list\' command'); }
protected function getCommandDisplayOutputErrorMessage() { return "Command did not behave as expected. Command output: " . $this->applicationTester->getDisplay(); }
public function testSetRunCustomSingleCommand() { $command = new \FooCommand(); $application = new Application(); $application->setAutoExit(false); $application->add($command); $application->setDefaultCommand($command->getName(), true); $tester = new ApplicationTester($application); $tester->run(array()); $this->assertContains('called', $tester->getDisplay()); $tester->run(array('--help' => true)); $this->assertContains('The foo:bar command', $tester->getDisplay()); }
public function testRun() { $application = new Application(); $application->setAutoExit(false); $application->setCatchExceptions(false); $application->add($command = new \Foo1Command()); $_SERVER['argv'] = array('cli.php', 'foo:bar1'); ob_start(); $application->run(); ob_end_clean(); $this->assertEquals('Symfony\\Component\\Console\\Input\\ArgvInput', get_class($command->input), '->run() creates an ArgvInput by default if none is given'); $this->assertEquals('Symfony\\Component\\Console\\Output\\ConsoleOutput', get_class($command->output), '->run() creates a ConsoleOutput by default if none is given'); $application = new Application(); $application->setAutoExit(false); $application->setCatchExceptions(false); $tester = new ApplicationTester($application); $tester->run(array()); $this->assertStringEqualsFile(self::$fixturesPath . '/application_run1.txt', $this->normalize($tester->getDisplay()), '->run() runs the list command if no argument is passed'); $tester->run(array('--help' => true)); $this->assertStringEqualsFile(self::$fixturesPath . '/application_run2.txt', $this->normalize($tester->getDisplay()), '->run() runs the help command if --help is passed'); $tester->run(array('-h' => true)); $this->assertStringEqualsFile(self::$fixturesPath . '/application_run2.txt', $this->normalize($tester->getDisplay()), '->run() runs the help command if -h is passed'); $application = new Application(); $application->setAutoExit(false); $application->setCatchExceptions(false); $tester = new ApplicationTester($application); $tester->run(array('command' => 'list', '--help' => true)); $this->assertStringEqualsFile(self::$fixturesPath . '/application_run3.txt', $this->normalize($tester->getDisplay()), '->run() displays the help if --help is passed'); $tester->run(array('command' => 'list', '-h' => true)); $this->assertStringEqualsFile(self::$fixturesPath . '/application_run3.txt', $this->normalize($tester->getDisplay()), '->run() displays the help if -h is passed'); $application = new Application(); $application->setAutoExit(false); $application->setCatchExceptions(false); $tester = new ApplicationTester($application); $tester->run(array('--ansi' => true)); $this->assertTrue($tester->getOutput()->isDecorated(), '->run() forces color output if --ansi is passed'); $tester->run(array('-a' => true)); $this->assertTrue($tester->getOutput()->isDecorated(), '->run() forces color output if -a is passed'); $application = new Application(); $application->setAutoExit(false); $application->setCatchExceptions(false); $tester = new ApplicationTester($application); $tester->run(array('--version' => true)); $this->assertStringEqualsFile(self::$fixturesPath . '/application_run4.txt', $this->normalize($tester->getDisplay()), '->run() displays the program version if --version is passed'); $tester->run(array('-V' => true)); $this->assertStringEqualsFile(self::$fixturesPath . '/application_run4.txt', $this->normalize($tester->getDisplay()), '->run() displays the program version if -v is passed'); $application = new Application(); $application->setAutoExit(false); $application->setCatchExceptions(false); $tester = new ApplicationTester($application); $tester->run(array('command' => 'list', '--quiet' => true)); $this->assertEquals('', $this->normalize($tester->getDisplay()), '->run() removes all output if --quiet is passed'); $tester->run(array('command' => 'list', '-q' => true)); $this->assertEquals('', $this->normalize($tester->getDisplay()), '->run() removes all output if -q is passed'); $application = new Application(); $application->setAutoExit(false); $application->setCatchExceptions(false); $tester = new ApplicationTester($application); $tester->run(array('command' => 'list', '--verbose' => true)); $this->assertEquals(Output::VERBOSITY_VERBOSE, $tester->getOutput()->getVerbosity(), '->run() sets the output to verbose is --verbose is passed'); $tester->run(array('command' => 'list', '-v' => true)); $this->assertEquals(Output::VERBOSITY_VERBOSE, $tester->getOutput()->getVerbosity(), '->run() sets the output to verbose is -v is passed'); $application = new Application(); $application->setAutoExit(false); $application->setCatchExceptions(false); $application->add(new \FooCommand()); $tester = new ApplicationTester($application); $tester->run(array('command' => 'foo:bar', '--no-interaction' => true)); $this->assertEquals("called\n", $this->normalize($tester->getDisplay()), '->run() does not called interact() if --no-interaction is passed'); $tester->run(array('command' => 'foo:bar', '-n' => true)); $this->assertEquals("called\n", $this->normalize($tester->getDisplay()), '->run() does not called interact() if -n is passed'); }
public function testRunDispatchesAllEventsWithException() { if (!class_exists('Symfony\\Component\\EventDispatcher\\EventDispatcher')) { $this->markTestSkipped('The "EventDispatcher" component is not available'); } $application = new Application(); $application->setDispatcher($this->getDispatcher()); $application->setAutoExit(false); $application->register('foo')->setCode(function (InputInterface $input, OutputInterface $output) { $output->write('foo.'); throw new \RuntimeException('foo'); }); $tester = new ApplicationTester($application); $tester->run(array('command' => 'foo')); $this->assertContains('before.foo.after.caught.', $tester->getDisplay()); }
public function testRunDispatchesAllEventsWithException() { $application = new Application(); $application->setDispatcher($this->getDispatcher()); $application->setAutoExit(false); $application->register('foo')->setCode(function (InputInterface $input, OutputInterface $output) { $output->write('foo.'); throw new \RuntimeException('foo'); }); $tester = new ApplicationTester($application); $tester->run(array('command' => 'foo')); $this->assertContains('before.foo.after.caught.', $tester->getDisplay()); }