public function testShouldReturnErrorIfThereIsFilesWithWrongStyle() { $kernel = $this->getMock(\stdClass::class); /* @var \Behat\Gherkin\Parser|\PHPUnit_Framework_MockObject_MockObject $parser */ $parser = $this->getMockBuilder(Parser::class)->disableOriginalConstructor()->getMock(); /* @var \Behat\Gherkin\Node\FeatureNode|\PHPUnit_Framework_MockObject_MockObject $feature */ $feature = $this->getMockBuilder(FeatureNode::class)->disableOriginalConstructor()->getMock(); $feature->expects(self::once())->method('hasTags')->willReturn(true); $feature->expects(self::once())->method('getKeyword')->willReturn('Feature'); $feature->expects(self::once())->method('getTags')->willReturn(['users', 'another-feature', 'another-tag']); $feature->expects(self::once())->method('getTitle')->willReturn('User registration'); $feature->expects(self::once())->method('hasDescription')->willReturn(true); $feature->expects(self::once())->method('getDescription')->willReturn("In order to order products\n" . "As a visitor\n" . "I need to be able to create an account in the store"); $feature->expects(self::once())->method('hasBackground')->willReturn(true); $feature->expects(self::once())->method('getBackground')->willReturn($this->getBackground()); $feature->expects(self::once())->method('hasScenarios')->willReturn(false); $parser->expects(self::once())->method('parse')->willReturn($feature); $application = new Application($kernel); $application->add(new CheckGherkinCodeStyle(null, $parser)); $command = $application->find('gherkin:check'); $commandTester = new CommandTester($command); $commandTester->execute(['directory' => __DIR__ . '/../assets/left-aligned.feature']); self::assertRegExp('/Wrong style/', $commandTester->getDisplay()); self::assertNotRegExp('/I need to be able to create an account in the store/', $commandTester->getDisplay()); }
public function testExecute() { // Lets create a workflow manager $workflowManager = new WorkflowManager(); // Lets create a mock DI container $mockContainer = $this->getMockBuilder('Symfony\\Component\\DependencyInjection\\Container')->disableOriginalConstructor()->setMethods(array('get'))->getMock(); $mockContainer->expects($this->any())->method('get')->with($this->equalTo('tyhand_workflow.manager'))->will($this->returnValue($workflowManager)); // Lets start the application $application = new Application(); $commandObject = new WorkflowManagerDebugCommand(); $commandObject->setContainer($mockContainer); $application->add($commandObject); $command = $application->find('tyhand_workflow:manager:debug'); $commandTester = new CommandTester($command); $commandTester->execute(array('command' => $command->getName())); $this->assertRegExp('/.../', $commandTester->getDisplay()); // Lets add some mock definitions to the workflow manager $mockDefinition = $this->getMockBuilder('TyHand\\WorkflowBundle\\Workflow\\AbstractWorkflowDefinition')->setMethods(array('getName', 'getContextClass', 'build'))->getMock(); $mockDefinition->expects($this->any())->method('getName')->will($this->returnValue('fake')); $mockDefinition->expects($this->any())->method('getContextClass')->will($this->returnValue('TyHand\\WorkflowBundle\\Tests\\DummyContext')); $mockDefinition->expects($this->any())->method('build')->will($this->returnValue(false)); $workflowManager->addWorkflowDefinition($mockDefinition); $mockDefinition2 = $this->getMockBuilder('TyHand\\WorkflowBundle\\Workflow\\AbstractWorkflowDefinition')->setMethods(array('getName', 'getContextClass', 'build'))->getMock(); $mockDefinition2->expects($this->any())->method('getName')->will($this->returnValue('abstract')); $mockDefinition2->expects($this->any())->method('getContextClass')->will($this->returnValue('TyHand\\WorkflowBundle\\Tests\\DummyContext')); $mockDefinition2->expects($this->any())->method('build')->will($this->returnValue(false)); $workflowManager->addWorkflowDefinition($mockDefinition2); // Test the command again $commandTester->execute(array('command' => $command->getName())); $this->assertRegExp('/fake/', $commandTester->getDisplay()); $this->assertRegExp('/abstract/', $commandTester->getDisplay()); $this->assertRegExp('/TyHand\\\\WorkflowBundle\\\\Tests\\\\DummyContext/', $commandTester->getDisplay()); $this->assertRegExp('/Mock_AbstractWorkflowDefinition/', $commandTester->getDisplay()); }
public function testCommand() { $this->converter->expects($this->once())->method('convert')->with('Document\\MyClass', array('en'), array(), 'none')->will($this->returnValue(false)); $this->mockSession->expects($this->once())->method('save'); $this->commandTester->execute(array('classname' => 'Document\\MyClass', '--locales' => array('en'), '--force' => true)); $this->assertEquals('.' . PHP_EOL . 'done' . PHP_EOL, $this->commandTester->getDisplay()); }
/** * @dataProvider dataProviderTestExecute * @param string $moduleName * @param int $all * @param array $contains * @param array $notContains */ public function testExecute($moduleName, $all, array $contains, array $notContains) { $application = $this->getApplication(); $application->add(new FromCommand()); $command = $this->getApplication()->find('dev:module:dependencies:from'); $commandTester = new CommandTester($command); $input = array('command' => $command->getName(), 'moduleName' => $moduleName); switch ($all) { case 2: $input['-a'] = true; break; case 1: $input['--all'] = true; break; default: break; } $commandTester->execute($input); foreach ($contains as $expectation) { $this->assertContains($expectation, $commandTester->getDisplay()); } foreach ($notContains as $expectation) { $this->assertNotContains($expectation, $commandTester->getDisplay()); } }
public function testWillShowQuery() { $this->_em->persist(new DateTimeModel()); $this->_em->flush(); $this->assertSame(0, $this->tester->execute(array('command' => $this->command->getName(), 'dql' => 'SELECT e FROM ' . DateTimeModel::CLASSNAME . ' e', '--show-sql' => 'true'))); $this->assertStringMatchesFormat('string%sSELECT %a', $this->tester->getDisplay()); }
public function testMultipleSitemapsExecute() { $templating = m::mock('Symfony\\Component\\Templating\\EngineInterface'); $templating->shouldReceive('render')->times(3); $router = m::mock('Symfony\\Component\\Routing\\RouterInterface'); $router->shouldReceive('getContext')->once()->andReturn(new RequestContext()); $manager = new SitemapManager(array(), 5, $templating); $manager->addGenerator(new TestGenerator(10)); $application = new Application(); $application->add(new DumpCommand($manager, $router, sys_get_temp_dir())); $command = $application->find('dpn:xml-sitemap:dump'); $commandTester = new CommandTester($command); $this->assertFileNotExists($this->getSitemapIndexFile()); $this->assertFileNotExists($this->getSitemapFile()); $this->assertFileNotExists($this->getSitemap1File()); $this->assertFileNotExists($this->getSitemap2File()); $commandTester->execute(array('command' => $command->getName(), 'host' => 'http://localhost', '--target' => sys_get_temp_dir())); $this->assertFileExists($this->getSitemapIndexFile()); $this->assertFileNotExists($this->getSitemapFile()); $this->assertFileExists($this->getSitemap1File()); $this->assertFileExists($this->getSitemap2File()); $this->assertContains(sprintf('[file+] %s', $this->getSitemapIndexFile()), $commandTester->getDisplay()); $this->assertContains(sprintf('[file+] %s', $this->getSitemap1File()), $commandTester->getDisplay()); $this->assertContains(sprintf('[file+] %s', $this->getSitemap2File()), $commandTester->getDisplay()); }
/** * Runs the command and returns it's output. * * @param array $input Command input. * @param array $options Command tester options. * * @return string */ protected function runCommand(array $input = array(), array $options = array()) { $input['command'] = $this->command->getName(); $options['interactive'] = true; $this->commandTester->execute($input, $options); return $this->commandTester->getDisplay(); }
/** * @covers ::execute */ public function testExecute() { $client = new ClientMock(); $client->queueResponse('packagist/list.json')->queueResponse('packagist/list.json')->queueResponse('packagist/list.empty.json'); $command = new SearchCommand($client); $console = new Application(); $console->add($command); $tester = new CommandTester($console->get('search')); $tester->execute([]); $expected = <<<RESPONSE Available Init Templates: clippings/package-template harp-orm/harp-template openbuildings/jam-template RESPONSE; $this->assertEquals($expected, $tester->getDisplay()); $tester->execute(['filter' => 'clip']); $expected = <<<RESPONSE Available Init Templates: clippings/package-template RESPONSE; $this->assertEquals($expected, $tester->getDisplay()); $expected = <<<RESPONSE No templates found RESPONSE; $tester->execute([]); $this->assertEquals($expected, $tester->getDisplay()); }
public function testShowSpecificFuzzySingle() { $this->tester->execute(array('command' => $this->command->getName(), 'entityName' => 'AttractionInfo')); $display = $this->tester->getDisplay(); $this->assertContains('Doctrine\\Tests\\Models\\Cache\\AttractionInfo', $display); $this->assertContains('Root entity name', $display); }
/** * @test */ public function exceptionWhileParsingLongUrlOutputsError() { $this->urlShortener->urlToShortCode(Argument::cetera())->willThrow(new InvalidUrlException())->shouldBeCalledTimes(1); $this->commandTester->execute(['command' => 'shortcode:generate', 'longUrl' => 'http://domain.com/invalid']); $output = $this->commandTester->getDisplay(); $this->assertTrue(strpos($output, 'Provided URL "http://domain.com/invalid" is invalid. Try with a different one.') === 0); }
/** * @covers \Ilios\CliBundle\Command\ListRootUsersCommand::execute */ public function testListUsersNoResults() { $this->userManager->shouldReceive('findDTOsBy')->with(['root' => true])->andReturn([]); $this->commandTester->execute(['command' => ListRootUsersCommand::COMMAND_NAME]); $output = $this->commandTester->getDisplay(); $this->assertEquals('No users with root-level privileges found.', trim($output)); }
public function testNonInteractiveCommand() { $command = $this->console->find('new'); $tester = new CommandTester($command); $tester->execute(array('command' => $command->getName(), 'title' => 'The Origin of Species', '--dir' => $this->tmpDir)); $this->assertRegExp('/.* OK .* You can start writing your book in the following directory/', $tester->getDisplay(), 'The book skeleton has been generated'); $this->assertRegExp('/.*\\/the-origin-of-species/', $tester->getDisplay(), 'The name of the new book directory is correct'); $bookDir = $this->tmpDir . '/the-origin-of-species'; $files = array('config.yml', 'Contents/chapter1.md', 'Contents/chapter2.md', 'Contents/images', 'Output'); foreach ($files as $file) { $this->assertFileExists($bookDir . '/' . $file, sprintf('%s has been generated', $file)); } $bookConfig = Yaml::parse($bookDir . '/config.yml'); // --- test basic config ---------------------------------------------- $this->assertEquals($bookConfig['book']['title'], 'The Origin of Species', 'The title of the new book is "The Origin of Species"'); $this->assertEquals($bookConfig['book']['author'], 'Change this: Author Name', 'The author of the new book is unset'); $this->assertEquals($bookConfig['book']['language'], 'en', 'The language of the new book is English'); $this->assertEquals($bookConfig['book']['publication_date'], null, 'The publication date of the new book is unset'); // --- test contents config ------------------------------------------- $contents = array(array('element' => 'cover'), array('element' => 'toc'), array('element' => 'chapter', 'number' => 1, 'content' => 'chapter1.md'), array('element' => 'chapter', 'number' => 2, 'content' => 'chapter2.md')); $this->assertEquals($bookConfig['book']['contents'], $contents, 'The default contents of the new book are correct'); // --- test editions config ------------------------------------------- $this->assertEquals(count($bookConfig['book']['editions']), 5, 'The new book has 5 editions configured'); $this->assertArrayHasKey('ebook', $bookConfig['book']['editions'], 'The new book has an "ebook" (.epub) edition'); $this->assertArrayHasKey('kindle', $bookConfig['book']['editions'], 'The new book has a "kindle" (.mobi) edition'); $this->assertArrayHasKey('print', $bookConfig['book']['editions'], 'The new book has a "print" (.pdf) edition'); $this->assertArrayHasKey('web', $bookConfig['book']['editions'], 'The new book has a "web" (.html) edition'); $this->assertArrayHasKey('website', $bookConfig['book']['editions'], 'The new book has a "website"(.html) edition'); // --- test second book generation ------------------------------------ $tester->execute(array('command' => $command->getName(), 'title' => 'The Origin of Species', '--dir' => $this->tmpDir)); $tester->execute(array('command' => $command->getName(), 'title' => 'The Origin of Species', '--dir' => $this->tmpDir)); $this->assertRegExp('/.* OK .* You can start writing your book in the following directory/', $tester->getDisplay(), 'The second book skeleton has been generated'); $this->assertRegExp('/.*\\/the-origin-of-species-\\d{1}\\s+/', $tester->getDisplay(), 'The name of the second book directory is correct'); }
public function testItemCountDoesntMatter() { $returnCode = $this->runCommand('file2.yml', 'file3.yml'); $output = $this->tester->getDisplay(); $this->assertEmpty($output, 'There is no output'); $this->assertEquals(0, $returnCode, 'Success exit code'); }
/** * @Then /^I should get the following products after apply the following updater to it:$/ * * @param TableNode $updates * * @throws \Exception */ public function iShouldGetTheFollowingProductsAfterApplyTheFollowingUpdaterToIt(TableNode $updates) { $application = $this->getApplicationsForUpdaterProduct(); $updateCommand = $application->find('pim:product:update'); $updateCommand->setContainer($this->getMainContext()->getContainer()); $updateCommandTester = new CommandTester($updateCommand); $getCommand = $application->find('pim:product:get'); $getCommand->setContainer($this->getMainContext()->getContainer()); $getCommandTester = new CommandTester($getCommand); foreach ($updates->getHash() as $update) { $username = isset($update['username']) ? $update['username'] : null; $updateCommandTester->execute(['command' => $updateCommand->getName(), 'identifier' => $update['product'], 'json_updates' => $update['actions'], 'username' => $username]); $expected = json_decode($update['result'], true); if (isset($expected['product'])) { $getCommandTester->execute(['command' => $getCommand->getName(), 'identifier' => $expected['product']]); unset($expected['product']); } else { $getCommandTester->execute(['command' => $getCommand->getName(), 'identifier' => $update['product']]); } $actual = json_decode($getCommandTester->getDisplay(), true); if (null === $actual) { throw new \Exception(sprintf('An error occured during the execution of the update command : %s', $getCommandTester->getDisplay())); } if (null === $expected) { throw new \Exception(sprintf('Looks like the expected result is not valid json : %s', $update['result'])); } $diff = $this->arrayIntersect($actual, $expected); assertEquals($expected, $diff); } }
/** * Asserts that the output contains the give regex * * @param $regex */ public function seeOutput($regex) { if (empty($this->commandTester)) { throw new \RuntimeException('You need to call runTheCommand() before checking the output'); } $this->assertRegExp('/' . preg_quote($regex, '/') . '/', $this->commandTester->getDisplay()); }
public function testExecute() { $session = $this->buildSession(); $application = new Application(); $application->add($this->newTestedInstance()->setSession($session)); $command = $application->find('pomm:generate:model'); $command_args = ['command' => $command->getName(), 'config-name' => 'pomm_test', 'schema' => 'pomm_test', 'relation' => 'beta', '--prefix-ns' => 'Model', '--prefix-dir' => 'tmp']; $tester = new CommandTester($command); $options = ['decorated' => false]; $tester->execute($command_args, $options); $this->string($tester->getDisplay())->isEqualTo(" ✓ Creating file 'tmp/Model/PommTest/PommTestSchema/BetaModel.php'." . PHP_EOL)->string(file_get_contents('tmp/Model/PommTest/PommTestSchema/BetaModel.php'))->isEqualTo(file_get_contents('sources/tests/Fixture/BetaModel.php'))->exception(function () use($tester, $command, $command_args) { $tester->execute($command_args); })->isInstanceOf('\\PommProject\\ModelManager\\Exception\\GeneratorException')->message->contains('--force'); $tester->execute(array_merge($command_args, ['--force' => null]), $options); $this->string($tester->getDisplay())->isEqualTo(" ✓ Overwriting file 'tmp/Model/PommTest/PommTestSchema/BetaModel.php'." . PHP_EOL)->string(file_get_contents('tmp/Model/PommTest/PommTestSchema/BetaModel.php'))->isEqualTo(file_get_contents('sources/tests/Fixture/BetaModel.php')); $tester->execute(array_merge($command_args, ['relation' => 'dingo']), $options); $this->string($tester->getDisplay())->isEqualTo(" ✓ Creating file 'tmp/Model/PommTest/PommTestSchema/DingoModel.php'." . PHP_EOL)->string(file_get_contents('tmp/Model/PommTest/PommTestSchema/DingoModel.php'))->isEqualTo(file_get_contents('sources/tests/Fixture/DingoModel.php')); $inspector = new Inspector(); $inspector->initialize($session); if (version_compare($inspector->getVersion(), '9.3', '>=') === true) { $tester->execute(array_merge($command_args, ['relation' => 'pluto']), $options); $this->string($tester->getDisplay())->isEqualTo(" ✓ Creating file 'tmp/Model/PommTest/PommTestSchema/PlutoModel.php'." . PHP_EOL)->string(file_get_contents('tmp/Model/PommTest/PommTestSchema/PlutoModel.php'))->isEqualTo(file_get_contents('sources/tests/Fixture/PlutoModel.php')); } $command_args['--prefix-dir'] = "tmp/Model"; $tester->execute(array_merge($command_args, ['--psr4' => null, '--force' => null]), $options); $this->string($tester->getDisplay())->isEqualTo(" ✓ Overwriting file 'tmp/Model/PommTest/PommTestSchema/BetaModel.php'." . PHP_EOL)->string(file_get_contents('tmp/Model/PommTest/PommTestSchema/BetaModel.php'))->isEqualTo(file_get_contents('sources/tests/Fixture/BetaModel.php')); }
/** * @dataProvider inputInteractiveCommandToOutputFilesProvider */ public function testInteractiveOutputs($inputCommandFilepath, $outputFilepath) { $code = (require $inputCommandFilepath); $this->command->setCode($code); $this->tester->execute(array(), array('interactive' => true, 'decorated' => false)); $this->assertStringEqualsFile($outputFilepath, $this->tester->getDisplay(true)); }
public function testExecuteNoOptions() { $this->deploymentConfig->expects($this->once())->method('isAvailable')->will($this->returnValue(false)); $this->tester->execute([]); $expected = 'Enabling maintenance mode' . PHP_EOL . 'Not enough information provided to take backup.' . PHP_EOL . 'Disabling maintenance mode' . PHP_EOL; $this->assertSame($expected, $this->tester->getDisplay()); }
/** * @test * @group integration */ public function testDiffWithEnv() { $exit_status = $this->_commandTester->execute(array('command' => $this->_commandName, '--magento-root' => $this->_magentoRoot, '--env' => "prod", 'config-yaml-file' => __DIR__ . "/data/base_prodenv_GBP.yaml")); $this->assertNotEmpty($this->_commandTester->getDisplay()); $this->assertCount(3, explode("\n", trim($this->_commandTester->getDisplay()))); $this->assertEquals(3, $exit_status); }
/** * @test * @group functional */ public function execute() { $application = new Application(static::$kernel); $application->add(new SyncSchemaCommand()); $command = $application->find('eav:schema:sync'); $commandTester = new CommandTester($command); // FIRST PASS $commandTester->execute(array('command' => $command->getName())); $output = <<<OUTPUT +-----------+------------------------------------------------+ | Created: | Padam87\\AttributeBundle\\Tests\\Model\\Subscriber | +-----------+------------------------------------------------+ | Existing: | | +-----------+------------------------------------------------+ OUTPUT; $this->assertSame(str_replace(PHP_EOL, "\n", $output), $commandTester->getDisplay(true)); // SECOND PASS $commandTester->execute(array('command' => $command->getName())); $output = <<<OUTPUT +-----------+------------------------------------------------+ | Created: | | +-----------+------------------------------------------------+ | Existing: | Padam87\\AttributeBundle\\Tests\\Model\\Subscriber | +-----------+------------------------------------------------+ OUTPUT; $this->assertSame(str_replace(PHP_EOL, "\n", $output), $commandTester->getDisplay(true)); }
public function testExecuteWithTiming() { $command = $this->getCommand(); $commandTester = new CommandTester($command); $commandTester->execute(array('command' => $command->getName(), '--dry-run' => true, '--timing' => true)); $this->assertContains('[TIMING]:', $output = $commandTester->getDisplay()); $this->assertContains('[TIMING - GLOBAL]:', $output = $commandTester->getDisplay()); }
/** * Same as above, but with some options aswell * * @return void * @author Dan Cox */ public function test_withOptions() { $command = $this->app->find('example:command'); $CT = new CommandTester($command); $CT->execute(['command' => $command->getName(), 'name' => 'Tester', '--bind' => TRUE, '--print' => TRUE]); $this->assertContains('bind found', $CT->getDisplay()); $this->assertContains('print found', $CT->getDisplay()); }
public function testExecuteForApplicationCommandWithXmlOption() { $application = new Application(); $commandTester = new CommandTester($application->get('help')); $commandTester->execute(array('command_name' => 'list', '--format' => 'xml')); $this->assertContains('list [--xml] [--raw] [--format FORMAT] [--] [<namespace>]', $commandTester->getDisplay(), '->execute() returns a text help for the given command'); $this->assertContains('<command', $commandTester->getDisplay(), '->execute() returns an XML help text if --format=xml is passed'); }
/** * @test */ public function errorIsReturnedIfServiceThrowsException() { $apiKey = 'abcd1234'; $this->apiKeyService->disable($apiKey)->willThrow(InvalidArgumentException::class)->shouldBeCalledTimes(1); $this->commandTester->execute(['command' => 'api-key:disable', 'apiKey' => $apiKey]); $output = $this->commandTester->getDisplay(); $this->assertEquals('API key "abcd1234" does not exist.' . PHP_EOL, $output); }
/** * @Then I should see the following JSON: * * @param PyStringNode $string * @throws \Exception */ public function iShouldSeeTheFollowingJson(PyStringNode $string) { $expectedData = json_decode($string, true); $actualData = json_decode($this->tester->getDisplay(), true); if ($actualData !== $expectedData) { throw new \Exception("the expected data was:\n{$string}\n\nbut the returned data was:\n" . $this->tester->getDisplay()); } }
/** * @test */ public function wrongShortCodeFormatOutputsErrorMessage() { $shortCode = 'abc123'; $this->urlShortener->shortCodeToUrl($shortCode)->willThrow(new InvalidShortCodeException())->shouldBeCalledTimes(1); $this->commandTester->execute(['command' => 'shortcode:parse', 'shortCode' => $shortCode]); $output = $this->commandTester->getDisplay(); $this->assertEquals('Provided short code "' . $shortCode . '" has an invalid format.' . PHP_EOL, $output); }
public function testCommandWithFilterMethodOption() { $this->executeCommand('examples', 'examples', array('--filter-methods' => 'OtherClass::hello,foo4::bar')); $this->executeCommand('examples', 'examples', array('--filter-methods' => 'OtherClass::hello,foo4::bar')); $display = $this->commandTester->getDisplay(); $this->assertNotRegExp('/foo4->bar\\(\\)/', $display); $this->assertNotRegExp('/OtherClass->hello\\(\\)/', $display); }
public function testICanExecuteCommand() { $command = new RunMetricsCommand(); $commandTester = new CommandTester($command); $commandTester->execute(array('path' => $this->toExplore)); $this->assertRegExp('/PHPMetrics by Jean-François Lépine/', $commandTester->getDisplay()); $this->assertRegExp('/Maintenability/', $commandTester->getDisplay()); }
public function testExecute() { $command = $this->getCommand(); $commandTester = new CommandTester($command); $commandTester->execute(array('command' => $command->getName(), '--format' => 'csv', '--type' => 'quick', '--table' => 'catalogsearch_*')); $this->assertContains('catalogsearch_fulltext,check,QUICK', $commandTester->getDisplay()); $this->assertContains('catalogsearch_result,check,QUICK', $commandTester->getDisplay()); }
public function testExecuteForApplicationCommandWithXmlOption() { $application = new Application(); $commandTester = new CommandTester($application->get('help')); $commandTester->execute(array('command_name' => 'list', '--format' => 'xml')); $this->assertRegExp('/list \\[--xml\\] \\[--raw\\] \\[--format="\\.\\.\\."\\] \\[namespace\\]/', $commandTester->getDisplay(), '->execute() returns a text help for the given command'); $this->assertRegExp('/<command/', $commandTester->getDisplay(), '->execute() returns an XML help text if --format=xml is passed'); }