本文整理匯總了PHP中Symfony\Component\Console\Tester\CommandTester類的典型用法代碼示例。如果您正苦於以下問題:PHP CommandTester類的具體用法?PHP CommandTester怎麽用?PHP CommandTester使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了CommandTester類的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: shouldExecuteConsumeCommand
/**
* @test
*/
public function shouldExecuteConsumeCommand()
{
$application = new Application('prod');
// Add command
$command = new TestableConsumerCommand('fake:consumer', $this->getMockForAbstractClass('Boot\\RabbitMQ\\Consumer\\AbstractConsumer', [$this->queueTemplate], 'MockConsumer'), $this->createLogger());
$application->add($command);
// Create command tester
$commandTester = new CommandTester($command);
// Execute consumer
$commandTester->execute(['command' => $command->getName()]);
// Should have declared the queue once
$this->assertEquals(1, $this->basicQueueDeclareInvocations->getInvocationCount());
$args = $this->basicQueueDeclareInvocations->getInvocations()[0]->parameters;
// Make sure that the queue name is correct
$this->assertEquals('some_test_queue', $args[0]);
// Make sure that the queue is durable
$this->assertTrue($args[2], 'The queue is not durable!');
// Make sure that the queue is not automatically deleted
$this->assertFalse($args[4], 'The queue is automatically deleted!');
// Should have declared the quality of service once
$this->assertEquals(1, $this->basicQosInvocations->getInvocationCount());
// Should have declared the quality of service once
$this->assertEquals(1, $this->basicConsumeInvocations->getInvocationCount());
// The wait method should have been invoked once
$this->assertEquals(1, $this->waitInvocations->getInvocationCount());
// Should have status code 0
$this->assertEquals(0, $commandTester->getStatusCode());
}
示例3: testExecute
public function testExecute()
{
$expected = 'Connection opened to foo:22/path/';
$commandTester = new CommandTester($this->instance->find('haytool:file-upload'));
$commandTester->execute(array());
$this->assertStringStartsWith($expected, $commandTester->getDisplay());
}
示例4: testExecution
/**
* @dataProvider getFormat
* @runInSeparateProcess
*/
public function testExecution($format)
{
$tmpDir = sys_get_temp_dir() . '/sf_hello';
$filesystem = new Filesystem();
$filesystem->remove($tmpDir);
$filesystem->mkdirs($tmpDir);
chdir($tmpDir);
$tester = new CommandTester(new InitCommand());
$tester->execute(array('--name' => 'Hello' . $format, '--app-path' => 'hello' . $format, '--web-path' => 'web', '--src-path' => 'src', '--format' => $format));
// autoload
$content = file_get_contents($file = $tmpDir . '/src/autoload.php');
$content = str_replace("__DIR__.'/vendor", "'" . __DIR__ . "/../../../../src/vendor", $content);
file_put_contents($file, $content);
// Kernel
$class = 'Hello' . $format . 'Kernel';
$file = $tmpDir . '/hello' . $format . '/' . $class . '.php';
$this->assertTrue(file_exists($file));
$content = file_get_contents($file);
$content = str_replace("__DIR__.'/../src/vendor/Symfony/src/Symfony/Bundle'", "'" . __DIR__ . "/../../../../src/vendor/Symfony/src/Symfony/Bundle'", $content);
file_put_contents($file, $content);
require_once $file;
$kernel = new $class('dev', true);
$response = $kernel->handle(Request::create('/'));
$this->assertRegExp('/successfully/', $response->getContent());
$filesystem->remove($tmpDir);
}
示例5: testExecute
public function testExecute()
{
$application = $this->getApplication();
$application->add(new ListCommand());
$command = $this->getApplication()->find('dev:module:create');
$root = getcwd();
// delete old module
if (is_dir($root . '/N98Magerun_UnitTest')) {
$filesystem = new Filesystem();
$filesystem->recursiveRemoveDirectory($root . '/N98Magerun_UnitTest');
clearstatcache();
}
$commandTester = new CommandTester($command);
$commandTester->execute(array('command' => $command->getName(), '--add-all' => true, '--add-setup' => true, '--add-readme' => true, '--add-composer' => true, '--modman' => true, '--description' => 'Unit Test Description', '--author-name' => 'Unit Test', '--author-email' => 'n98-magerun@example.com', 'vendorNamespace' => 'N98Magerun', 'moduleName' => 'UnitTest'));
$this->assertFileExists($root . '/N98Magerun_UnitTest/composer.json');
$this->assertFileExists($root . '/N98Magerun_UnitTest/readme.md');
$moduleBaseFolder = $root . '/N98Magerun_UnitTest/src/app/code/local/N98Magerun/UnitTest/';
$this->assertFileExists($moduleBaseFolder . 'etc/config.xml');
$this->assertFileExists($moduleBaseFolder . 'Block');
$this->assertFileExists($moduleBaseFolder . 'Model');
$this->assertFileExists($moduleBaseFolder . 'Helper');
$this->assertFileExists($moduleBaseFolder . 'data/n98magerun_unittest_setup');
$this->assertFileExists($moduleBaseFolder . 'sql/n98magerun_unittest_setup');
// delete old module
if (is_dir($root . '/N98Magerun_UnitTest')) {
$filesystem = new Filesystem();
$filesystem->recursiveRemoveDirectory($root . '/N98Magerun_UnitTest');
clearstatcache();
}
}
示例6: getCommandTester
/**
* @param string $commandName
* @param array $options
* @return CommandTester
*/
protected function getCommandTester($commandName, array $options = [])
{
$command = $this->getApplication()->find($commandName);
$commandTester = new CommandTester($command);
$commandTester->execute(['command' => $commandName], $options);
return $commandTester;
}
示例7: 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);
}
}
示例8: testExecute
public function testExecute()
{
$expected = '/^Hashing pid data/';
$commandTester = new CommandTester($this->instance->find('haytool:pid-obfuscation'));
$commandTester->execute(array());
$this->assertRegExp($expected, $commandTester->getDisplay());
}
示例9: runCommand
/**
* Runa a command in and returns the commandTester object. This method can
* run either a blend command or a sub-application command
* @param string $projectFolder
* @param string $commandName
* @param string $params
* @param string $app In case of null it will be set to blend. In case of
* className as string, the application's class name will be used
* @return CommandTester
*/
public static function runCommand($projectFolder, $commandName, array $params = [], $app = null, $runOptions = [])
{
$loader = new ClassLoader();
$curDir = getcwd();
chdir($projectFolder);
if ($app === null) {
$app = new SetupApplication($projectFolder);
} else {
if (is_string($app)) {
$classes = explode('\\', $app);
$loader->addPsr4("{$classes[0]}\\", $projectFolder . '/src/');
$loader->register(true);
$c = new Container();
$c->defineSingletonWithInterface('app', $app, ['scriptPath' => $projectFolder . '/bin']);
$app = $c->get('app');
}
}
$commandTester = new CommandTester($app->find($commandName));
$commandTester->execute($params, $runOptions);
chdir($curDir);
$c = null;
if ($loader) {
$loader->unregister();
}
return $commandTester;
}
示例10: testExecute
public function testExecute()
{
$this->moduleList->expects($this->once())->method('getNames')->willReturn([]);
$commandTester = new CommandTester($this->command);
$commandTester->execute([]);
$this->assertContains('List of active modules', $commandTester->getDisplay());
}
示例11: test_options
/**
* Test setting the flag option on the test command..
*
* @return void
* @author Dan Cox
*/
public function test_options()
{
$command = $this->DI->get('console')->find('test:command');
$CT = new CommandTester($command);
$CT->execute(['command' => $command->getName(), 'test' => 'foo', '--flag' => true]);
$this->assertContains('flag set', $CT->getDisplay());
}
示例12: testSites
/**
* @dataProvider provideSites
* @param string $root Root directory of site
* @param string|null $config Path to configuration file
*/
public function testSites($root, $config = null)
{
$application = new Application();
$application->add(new BuildCommand());
/** @var \CastlePointAnime\Brancher\Command\BuildCommand $command */
$command = $application->find('build');
$commandTester = new CommandTester($command);
$outputDir = self::$outputDir;
$commandTester->execute(array_filter(['--config' => $config, '--exclude' => '_site', 'root' => $root, 'output' => $outputDir]));
// Test to make sure existing files match
$finder = new Finder();
$finder->files()->in("{$root}/_site");
/** @var \Symfony\Component\Finder\SplFileInfo $fileInfo */
foreach ($finder as $fileInfo) {
$this->assertFileEquals($fileInfo->getPathname(), "{$outputDir}/{$fileInfo->getRelativePathname()}", $fileInfo->getPathname());
}
// Test to make sure excluded files do not exist
$excludeDirs = $command->getContainer()->getParameter('castlepointanime.brancher.build.excludes');
if (count($excludeDirs)) {
$finder = new Finder();
$finder->files()->in($root)->exclude('_site')->exclude('_templates');
array_map([$finder, 'path'], $excludeDirs);
/** @var \Symfony\Component\Finder\SplFileInfo $fileInfo */
foreach ($finder as $fileInfo) {
$this->assertFileNotExists("{$outputDir}/{$fileInfo->getRelativePathname()}");
}
}
}
示例13: getCommandTester
/**
* @param string $commandName
* @return CommandTester
*/
protected function getCommandTester($commandName)
{
$command = $this->getApplication()->find($commandName);
$commandTester = new CommandTester($command);
$commandTester->execute(array_merge(array('command' => $commandName)));
return $commandTester;
}
示例14: testExecute
public function testExecute()
{
$application = $this->getApplication();
$application->add(new DumpCommand());
$setCommand = $this->getApplication()->find('config:set');
$deleteCommand = $this->getApplication()->find('config:delete');
/**
* Add a new entry
*/
$commandTester = new CommandTester($setCommand);
$commandTester->execute(array('command' => $setCommand->getName(), 'path' => 'imi_conrun/foo/bar', 'value' => '1234'));
$this->assertContains('imi_conrun/foo/bar => 1234', $commandTester->getDisplay());
$commandTester = new CommandTester($deleteCommand);
$commandTester->execute(array('command' => $deleteCommand->getName(), 'path' => 'imi_conrun/foo/bar'));
$this->assertContains('| imi_conrun/foo/bar | default | 0 |', $commandTester->getDisplay());
/**
* Delete all
*/
foreach (\Mage::app()->getStores() as $store) {
// add multiple entries
$commandTester = new CommandTester($setCommand);
$commandTester->execute(array('command' => $setCommand->getName(), 'path' => 'imi_conrun/foo/bar', '--scope' => 'stores', '--scope-id' => $store->getId(), 'value' => 'store-' . $store->getId()));
}
$commandTester = new CommandTester($deleteCommand);
$commandTester->execute(array('command' => $deleteCommand->getName(), 'path' => 'imi_conrun/foo/bar', '--all' => true));
foreach (\Mage::app()->getStores() as $store) {
$this->assertContains('| imi_conrun/foo/bar | stores | ' . $store->getId() . ' |', $commandTester->getDisplay());
}
}
示例15: testExecute
public function testExecute()
{
/**
* Check autoloading
*/
/* @var $application Application */
$application = (require __DIR__ . '/../../../src/bootstrap.php');
$application->setMagentoRootFolder($this->getTestMagentoRoot());
$this->assertInstanceOf('\\N98\\Magento\\Application', $application);
$loader = $application->getAutoloader();
$this->assertInstanceOf('\\Composer\\Autoload\\ClassLoader', $loader);
/**
* Check version
*/
$this->assertEquals(Application::APP_VERSION, trim(file_get_contents(__DIR__ . '/../../../version.txt')));
/* @var $loader \Composer\Autoload\ClassLoader */
$prefixes = $loader->getPrefixes();
$this->assertArrayHasKey('N98', $prefixes);
$distConfigArray = Yaml::parse(file_get_contents(__DIR__ . '/../../../config.yaml'));
$configArray = array('autoloaders' => array('N98MagerunTest' => __DIR__ . '/_ApplicationTestSrc'), 'commands' => array('customCommands' => array(0 => 'N98MagerunTest\\TestDummyCommand'), 'aliases' => array(array('ssl' => 'sys:store:list'))), 'init' => array('options' => array('config_model' => 'N98MagerunTest\\AlternativeConfigModel')));
$application->setAutoExit(false);
$application->init(ArrayFunctions::mergeArrays($distConfigArray, $configArray));
$application->run(new StringInput('list'), new NullOutput());
// Check if autoloaders, commands and aliases are registered
$prefixes = $loader->getPrefixes();
$this->assertArrayHasKey('N98MagerunTest', $prefixes);
$testDummyCommand = $application->find('n98mageruntest:test:dummy');
$this->assertInstanceOf('\\N98MagerunTest\\TestDummyCommand', $testDummyCommand);
$commandTester = new CommandTester($testDummyCommand);
$commandTester->execute(array('command' => $testDummyCommand->getName()));
$this->assertContains('dummy', $commandTester->getDisplay());
$this->assertTrue($application->getDefinition()->hasOption('root-dir'));
// check alias
$this->assertInstanceOf('\\N98\\Magento\\Command\\System\\Store\\ListCommand', $application->find('ssl'));
}