本文整理汇总了PHP中Symfony\Component\Console\Application类的典型用法代码示例。如果您正苦于以下问题:PHP Application类的具体用法?PHP Application怎么用?PHP Application使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Application类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setConsole
/**
* Config doctrine console
*
* @param Application $console
* @param EntityManager $entityManager
* @return Application
*/
static function setConsole(Application $console, EntityManager $entityManager)
{
$helperSet = new \Symfony\Component\Console\Helper\HelperSet(array('db' => new \Doctrine\DBAL\Tools\Console\Helper\ConnectionHelper($entityManager->getConnection()), 'em' => new \Doctrine\ORM\Tools\Console\Helper\EntityManagerHelper($entityManager)));
$console->setHelperSet($helperSet);
$console->addCommands(array(new \Doctrine\DBAL\Tools\Console\Command\RunSqlCommand(), new \Doctrine\DBAL\Tools\Console\Command\ImportCommand(), new \Doctrine\ORM\Tools\Console\Command\ClearCache\MetadataCommand(), new \Doctrine\ORM\Tools\Console\Command\ClearCache\ResultCommand(), new \Doctrine\ORM\Tools\Console\Command\ClearCache\QueryCommand(), new \Doctrine\ORM\Tools\Console\Command\SchemaTool\CreateCommand(), new \Doctrine\ORM\Tools\Console\Command\SchemaTool\UpdateCommand(), new \Doctrine\ORM\Tools\Console\Command\SchemaTool\DropCommand(), new \Doctrine\ORM\Tools\Console\Command\EnsureProductionSettingsCommand(), new \Doctrine\ORM\Tools\Console\Command\ConvertDoctrine1SchemaCommand(), new \Doctrine\ORM\Tools\Console\Command\GenerateRepositoriesCommand(), new \Doctrine\ORM\Tools\Console\Command\GenerateEntitiesCommand(), new \Doctrine\ORM\Tools\Console\Command\GenerateProxiesCommand(), new \Doctrine\ORM\Tools\Console\Command\ConvertMappingCommand(), new \Doctrine\ORM\Tools\Console\Command\RunDqlCommand(), new \Doctrine\ORM\Tools\Console\Command\ValidateSchemaCommand()));
return $console;
}
示例2: create
/**
* @return Application
*/
public function create()
{
$app = new Application(Message::NAME, Message::VERSION);
$app->setDefaultCommand(Message::COMMAND);
$app->add($this->createAnalyzeCommand());
return $app;
}
示例3: 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());
}
示例4: getApplicationDocument
/**
* @param Application $application
* @param string|null $namespace
*
* @return \DOMDocument
*/
public function getApplicationDocument(Application $application, $namespace = null)
{
$dom = new \DOMDocument('1.0', 'UTF-8');
$dom->appendChild($rootXml = $dom->createElement('symfony'));
if ($application->getName() !== 'UNKNOWN') {
$rootXml->setAttribute('name', $application->getName());
if ($application->getVersion() !== 'UNKNOWN') {
$rootXml->setAttribute('version', $application->getVersion());
}
}
$rootXml->appendChild($commandsXML = $dom->createElement('commands'));
$description = new ApplicationDescription($application, $namespace);
if ($namespace) {
$commandsXML->setAttribute('namespace', $namespace);
}
foreach ($description->getCommands() as $command) {
$this->appendDocument($commandsXML, $this->getCommandDocument($command));
}
if (!$namespace) {
$rootXml->appendChild($namespacesXML = $dom->createElement('namespaces'));
foreach ($description->getNamespaces() as $namespaceDescription) {
$namespacesXML->appendChild($namespaceArrayXML = $dom->createElement('namespace'));
$namespaceArrayXML->setAttribute('id', $namespaceDescription['id']);
foreach ($namespaceDescription['commands'] as $name) {
$namespaceArrayXML->appendChild($commandXML = $dom->createElement('command'));
$commandXML->appendChild($dom->createTextNode($name));
}
}
}
return $dom;
}
示例5: setUp
public function setUp()
{
$application = new Application();
$application->add(new UserTokenGenerateCommand());
$this->command = $application->find('user:token:generate');
$this->commandTester = new CommandTester($this->command);
}
示例6: setUp
protected function setUp()
{
$application = new Application();
$application->add(new RepositoryTransferCommand($this->container));
$command = $application->get(RepositoryTransferCommand::COMMAND_NAME);
$this->commandTester = new CommandTester($command);
}
示例7: createApplication
public function createApplication($className)
{
$app = new Application('Robo', self::VERSION);
$roboTasks = new $className();
$commandNames = array_filter(get_class_methods($className), function ($m) {
return !in_array($m, ['__construct']);
});
$passThrough = $this->passThroughArgs;
foreach ($commandNames as $commandName) {
$command = $this->createCommand(new TaskInfo($className, $commandName));
$command->setCode(function (InputInterface $input) use($roboTasks, $commandName, $passThrough) {
// get passthru args
$args = $input->getArguments();
array_shift($args);
if ($passThrough) {
$args[key(array_slice($args, -1, 1, TRUE))] = $passThrough;
}
$args[] = $input->getOptions();
$res = call_user_func_array([$roboTasks, $commandName], $args);
if (is_int($res)) {
exit($res);
}
if (is_bool($res)) {
exit($res ? 0 : 1);
}
if ($res instanceof Result) {
exit($res->getExitCode());
}
});
$app->add($command);
}
return $app;
}
示例8: setUp
/**
* 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);
}
示例9: 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());
}
示例10: setApplicationDocumentManager
public static function setApplicationDocumentManager(Application $application, $dmName)
{
$service = null === $dmName ? 'doctrine_phpcr.odm.document_manager' : 'doctrine_phpcr.odm.' . $dmName . '_document_manager';
$documentManager = $application->getKernel()->getContainer()->get($service);
$helperSet = $application->getHelperSet();
$helperSet->set(new DocumentManagerHelper(null, $documentManager));
}
示例11: testCommand
public function testCommand()
{
$app = new Application('Propel', Propel::VERSION);
$command = new DatabaseReverseCommand();
$app->add($command);
$currentDir = getcwd();
$outputDir = __DIR__ . '/../../../../reversecommand';
chdir(__DIR__ . '/../../../../Fixtures/bookstore');
$input = new \Symfony\Component\Console\Input\ArrayInput(array('command' => 'database:reverse', '--database-name' => 'reverse-test', '--output-dir' => $outputDir, '--verbose' => true, '--platform' => ucfirst($this->getDriver()) . 'Platform', 'connection' => $this->getConnectionDsn('bookstore-schemas', true)));
$output = new \Symfony\Component\Console\Output\StreamOutput(fopen("php://temp", 'r+'));
$app->setAutoExit(false);
$result = $app->run($input, $output);
chdir($currentDir);
if (0 !== $result) {
rewind($output->getStream());
echo stream_get_contents($output->getStream());
}
$this->assertEquals(0, $result, 'database:reverse tests exited successfully');
$databaseXml = simplexml_load_file($outputDir . '/schema.xml');
$this->assertEquals('reverse-test', $databaseXml['name']);
$this->assertGreaterThan(20, $databaseXml->xpath("table"));
$table = $databaseXml->xpath("table[@name='acct_access_role']");
$this->assertCount(1, $table);
$table = $table[0];
$this->assertEquals('acct_access_role', $table['name']);
$this->assertEquals('AcctAccessRole', $table['phpName']);
$this->assertCount(2, $table->xpath('column'));
}
示例12: setup
public function setup()
{
$app = new Application();
$app->add(new UpdateCommand());
$this->cmd = $app->find('update');
$this->tester = new CommandTester($this->cmd);
}
示例13: boot
/**
* Bootstraps the application.
*
* This method is called after all services are registered
* and should be used for "dynamic" configuration (whenever
* a service must be requested).
*
* @param Application $app
*/
public function boot(Application $app)
{
$helperSet = new HelperSet(array('connection' => new ConnectionHelper($app['db']), 'dialog' => new DialogHelper()));
if (isset($app['orm.em'])) {
$helperSet->set(new EntityManagerHelper($app['orm.em']), 'em');
}
$this->console->setHelperSet($helperSet);
$commands = array('Doctrine\\DBAL\\Migrations\\Tools\\Console\\Command\\ExecuteCommand', 'Doctrine\\DBAL\\Migrations\\Tools\\Console\\Command\\GenerateCommand', 'Doctrine\\DBAL\\Migrations\\Tools\\Console\\Command\\MigrateCommand', 'Doctrine\\DBAL\\Migrations\\Tools\\Console\\Command\\StatusCommand', 'Doctrine\\DBAL\\Migrations\\Tools\\Console\\Command\\VersionCommand');
// @codeCoverageIgnoreStart
if (true === $this->console->getHelperSet()->has('em')) {
$commands[] = 'Doctrine\\DBAL\\Migrations\\Tools\\Console\\Command\\DiffCommand';
}
// @codeCoverageIgnoreEnd
$configuration = new Configuration($app['db'], $app['migrations.output_writer']);
$configuration->setMigrationsDirectory($app['migrations.directory']);
$configuration->setName($app['migrations.name']);
$configuration->setMigrationsNamespace($app['migrations.namespace']);
$configuration->setMigrationsTableName($app['migrations.table_name']);
$configuration->registerMigrationsFromDirectory($app['migrations.directory']);
foreach ($commands as $name) {
/** @var AbstractCommand $command */
$command = new $name();
$command->setMigrationConfiguration($configuration);
$this->console->add($command);
}
}
示例14: testExecute
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'));
}
示例15: setUp
public function setUp()
{
$application = new Application();
$application->add(new CreateTenantCommand());
$this->command = $application->get('swp:tenant:create');
$this->question = $this->command->getHelper('question');
}