find() public method

Contrary to get, this command tries to find the best match if you give it an abbreviation of a name or alias.
public find ( string $name ) : Command
$name string A command name or a command alias
return Symfony\Component\Console\Command\Command A Command instance
 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());
 }
 /**
  * Setup tests
  * @return void
  */
 protected function setUp()
 {
     $application = new Application();
     $application->add(new SearchCommand());
     $this->command = $application->find('search');
     $this->commandTester = new CommandTester($this->command);
 }
 public function setUp()
 {
     $application = new Application();
     $application->add(new UserTokenGenerateCommand());
     $this->command = $application->find('user:token:generate');
     $this->commandTester = new CommandTester($this->command);
 }
 public function testCommandInsideWrongDirectory()
 {
     $command = $this->application->find('run');
     $commandTester = new CommandTester($command);
     $commandTester->execute(array('command' => $command->getName(), 'route' => 'catalog/attribute'));
     $this->assertRegExp("/^.*ERROR: No Opencart installation found!.*\$/", $commandTester->getDisplay());
 }
 public function testGenerateProxies()
 {
     $this->setExpectedException('Exception');
     $command = $this->app->find('generate-proxies');
     $test = new CommandTester($command);
     $test->execute(array('command' => $command->getName()));
 }
 protected function setUp()
 {
     $this->application = new Application();
     $this->application->add(new CalculatePomodorosCommand());
     $this->command = $this->application->find('pomodoro:calculate');
     $this->commandTester = new CommandTester($this->command);
 }
 protected function getCommandTester()
 {
     $this->application->add($this->command);
     $command = $this->application->find('phpci:create-build');
     $commandTester = new CommandTester($command);
     return $commandTester;
 }
 public function testFlushRegionName()
 {
     $command = $this->application->find('orm:clear-cache:region:entity');
     $tester = new CommandTester($command);
     $tester->execute(array('command' => $command->getName(), 'entity-class' => 'Doctrine\\Tests\\Models\\Cache\\Country', '--flush' => true), array('decorated' => false));
     $this->assertEquals('Flushing cache provider configured for entity named "Doctrine\\Tests\\Models\\Cache\\Country"' . PHP_EOL, $tester->getDisplay());
 }
 protected function createTester(ContainerAwareInterface $obj, $shortcat)
 {
     $this->app->add($obj);
     $command = $this->app->find($shortcat);
     $obj->setContainer($this->container);
     return new CommandTester($command);
 }
 /**
  * @param string $command
  * @param array  $args
  */
 public function runTheCommand($command, array $args = [])
 {
     $command = $this->application->find($command);
     $testArguments = array_merge($args, ['command' => $command->getName()]);
     $this->commandTester = new CommandTester($command);
     $this->commandTester->execute($testArguments);
 }
 public function testFlushRegionName()
 {
     $command = $this->application->find('orm:clear-cache:region:query');
     $tester = new CommandTester($command);
     $tester->execute(array('command' => $command->getName(), 'region-name' => 'my_region', '--flush' => true), array('decorated' => false));
     $this->assertEquals('Flushing cache provider configured for second-level cache query region named "my_region"' . PHP_EOL, $tester->getDisplay());
 }
 public function testFlushRegionName()
 {
     $command = $this->application->find('orm:clear-cache:region:collection');
     $tester = new CommandTester($command);
     $tester->execute(array('command' => $command->getName(), 'owner-class' => 'Doctrine\\Tests\\Models\\Cache\\State', 'association' => 'cities', '--flush' => true), array('decorated' => false));
     $this->assertEquals('Flushing cache provider configured for "Doctrine\\Tests\\Models\\Cache\\State#cities"' . PHP_EOL, $tester->getDisplay());
 }
 public function setUp()
 {
     parent::setUp();
     $this->application = new Application();
     $this->application->add(new \BackgroundCommandStub($this->commandName));
     $this->command = $this->application->find($this->commandName);
     $this->tester = new CommandTester($this->command);
 }
 /**
  * @param  string        $command_class
  * @return CommandTester
  */
 protected function getCommandTesterFor($command_class) : CommandTester
 {
     /** @var Command $command */
     $command = new $command_class();
     $command->setContainer($this->getContainer());
     $this->application->add($command);
     return new CommandTester($this->application->find($command->getName()));
 }
 /**
  * Build and execute the command tester.
  *
  * @param string $name   command name
  * @param array  $args   command arguments
  * @param int    $status expected return status
  *
  * @return CommandTester
  */
 protected function executeCommand($name, $args, $status = 0)
 {
     $command = $this->application->find($name);
     $commandTester = new CommandTester($command);
     $args = array_merge(array('command' => $command->getName()), $args);
     $this->assertEquals($status, $commandTester->execute($args));
     return $commandTester;
 }
 /**
  * @return CommandTester
  */
 protected function getCommandTester()
 {
     $this->application->getHelperSet()->set($this->dialog, 'dialog');
     $this->application->add($this->command);
     $command = $this->application->find('phpci:create-admin');
     $commandTester = new CommandTester($command);
     return $commandTester;
 }
 /**
  * Checks a single definition.
  *
  * @param Definition $definition
  * @return bool
  */
 public function check(Definition $definition)
 {
     try {
         $this->application->find($definition->getCommand());
     } catch (\InvalidArgumentException $e) {
         $this->result = self::RESULT_INCORRECT_COMMAND;
         return false;
     }
     return true;
 }
Example #18
0
 protected function setUp()
 {
     parent::setUp();
     $this->application = new Application();
     $command = new InfoCommand();
     $this->application->setHelperSet(new HelperSet(array('em' => new EntityManagerHelper($this->_em))));
     $this->application->add($command);
     $this->command = $this->application->find('orm:info');
     $this->tester = new CommandTester($command);
 }
 public function setUp()
 {
     parent::setUp();
     $this->application = new Application();
     $this->application->add(new \DaemonCommandStub($this->commandName));
     $this->command = $this->application->find($this->commandName);
     $this->tester = new CommandTester($this->command);
     $this->command->setOutputCallback(function () {
         return $this->tester->getOutput();
     });
 }
Example #20
0
 /**
  * @runInSeparateProcess
  * @preserveGlobalState disabled
  */
 public function testBackingUpCatalogImagesAndDatabase()
 {
     chdir($this->execDir);
     $command = $this->application->find('backup');
     $commandTester = new CommandTester($command);
     $commandTester->execute(array('--images' => null, '--database' => null));
     foreach (glob("ocok_backup_" . date("Y_m_d_") . "*.zip") as $file) {
         $this->assertGreaterThan(0, filesize($file));
         unlink($file);
         $this->assertFalse(is_file($file));
     }
 }
 private function createCommand($payload)
 {
     if ($payload instanceof Command) {
         return $payload;
     }
     if ($this->accessor->isReadable($payload, '[command]')) {
         return $this->application->find($this->accessor->getValue($payload, '[command]'));
     }
     if ($this->accessor->isReadable($payload, 'command')) {
         return $this->application->find($this->accessor->getValue($payload, 'command'));
     }
     throw new \InvalidArgumentException('Unsupported payload type.');
 }
Example #22
0
 public function setup()
 {
     $app = new Application();
     $app->add(new CheckCommand());
     $this->cmd = $app->find('check');
     $this->tester = new CommandTester($this->cmd);
 }
 /**
  * Set up the command tester
  */
 protected function setUp()
 {
     $application = new Application();
     $application->add(new AmendSwaggerDocumentCommand(new DocumentRepository(), new SwaggerBundleResponseFixer()));
     $command = $application->find(AmendSwaggerDocumentCommand::NAME);
     $this->commandTester = new CommandTester($command);
 }
 /**
  * prepare our mocks and cmdtester
  *
  * @return void
  */
 public function setUp()
 {
     $clientMock = $this->getMockBuilder('\\MongoClient')->disableOriginalConstructor()->getMock();
     $collectionData = [[['_id' => 'Record1', 'name' => 'Fred', 'date' => new \MongoDate(strtotime("1982-02-05 00:00:00"))], ['_id' => 'Record2', 'name' => 'Franz']], [['_id' => 'Record3', 'name' => 'Hans'], ['_id' => 'Record4', 'name' => 'Ilein']]];
     $collectionOne = $this->getMockBuilder('\\MongoCollection')->disableOriginalConstructor()->getMock();
     $collectionOne->expects($this->exactly(4))->method('getName')->willReturn('Dude');
     $collectionOne->expects($this->once())->method('find')->willReturn($collectionData[0]);
     $collectionTwo = $this->getMockBuilder('\\MongoCollection')->disableOriginalConstructor()->getMock();
     $collectionTwo->expects($this->exactly(4))->method('getName')->willReturn('Dudess');
     $collectionTwo->expects($this->once())->method('find')->willReturn($collectionData[1]);
     // this one is filtered out and gets called differently
     $collectionThree = $this->getMockBuilder('\\MongoCollection')->disableOriginalConstructor()->getMock();
     $collectionThree->expects($this->exactly(1))->method('getName')->willReturn('Franz');
     $collectionThree->expects($this->never())->method('find')->willReturn($collectionData[1]);
     $dbMock = $this->getMockBuilder('\\MongoDb')->disableOriginalConstructor()->getMock();
     $dbMock->expects($this->once())->method('listCollections')->willReturn([$collectionOne, $collectionTwo, $collectionThree]);
     $clientMock->db = $dbMock;
     $sut = new CoreExportCommand('db', new Filesystem(), new JsonSerializer(), new FrontMatter());
     $sut->setClient($clientMock);
     $app = new Application();
     $app->add($sut);
     $cmd = $app->find('graviton:core:export');
     $this->cmdTester = new CommandTester($cmd);
     $this->fs = new Filesystem();
     $this->destinationDir = __DIR__ . DIRECTORY_SEPARATOR . 'exportTemp' . DIRECTORY_SEPARATOR;
 }
Example #25
0
 public function setUp()
 {
     $application = new Application();
     $application->add(new ConvertCommand());
     $this->command = $application->find('convert');
     $this->commandTester = new CommandTester($this->command);
 }
Example #26
0
 /**
  * @return CommandTester
  */
 protected function createCommandTester()
 {
     $application = new Application();
     $application->add(new LintCommand());
     $command = $application->find('lint:yaml');
     return new CommandTester($command);
 }
 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'));
 }
Example #28
0
 public function setup()
 {
     $app = new Application();
     $app->add(new UpdateCommand());
     $this->cmd = $app->find('update');
     $this->tester = new CommandTester($this->cmd);
 }
 /**
  * {@inheritdoc}
  */
 public function setUp()
 {
     $this->application = new Application('Drupal Code Generator', '@git-version@');
     $discovery = new GeneratorDiscovery([DCG_ROOT . '/src/Commands'], [DCG_ROOT . '/src/Templates'], new Filesystem());
     $generators = $discovery->getGenerators();
     $this->application->addCommands($generators);
     $navigation = new Navigation();
     $navigation->init($generators);
     $this->application->add($navigation);
     $this->command = $this->application->find('navigation');
     $this->questionHelper = $this->createMock('Symfony\\Component\\Console\\Helper\\QuestionHelper');
     $this->helperSet = $this->command->getHelperSet();
     $this->commandTester = new CommandTester($this->command);
     $this->filesystem = new Filesystem();
     $this->destination = DCG_SANDBOX . '/tests';
 }
 public function setUp()
 {
     $app = new Application();
     $app->add(new StartCommand());
     $this->command = $app->find('start');
     $this->configFile = __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'config.yml';
 }