本文整理匯總了PHP中Symfony\Component\Console\Tester\CommandTester::getDisplay方法的典型用法代碼示例。如果您正苦於以下問題:PHP CommandTester::getDisplay方法的具體用法?PHP CommandTester::getDisplay怎麽用?PHP CommandTester::getDisplay使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Symfony\Component\Console\Tester\CommandTester
的用法示例。
在下文中一共展示了CommandTester::getDisplay方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: testShouldReturnErrorIfThereIsFilesWithWrongStyle
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());
}
示例2: testExecute
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());
}
示例3: testCommand
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());
}
示例4: testExecute
/**
* @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());
}
}
示例5: testWillShowQuery
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());
}
示例6: testMultipleSitemapsExecute
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());
}
示例7: runCommand
/**
* 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();
}
示例8: testExecute
/**
* @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());
}
示例9: testShowSpecificFuzzySingle
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);
}
示例10: exceptionWhileParsingLongUrlOutputsError
/**
* @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);
}
示例11: testListUsersNoResults
/**
* @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));
}
示例12: testNonInteractiveCommand
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');
}
示例13: testItemCountDoesntMatter
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');
}
示例14: iShouldGetTheFollowingProductsAfterApplyTheFollowingUpdaterToIt
/**
* @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);
}
}
示例15: seeOutput
/**
* 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());
}