/**
  * 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;
 }
Example #2
1
 /**
  * @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;
 }
 /**
  * @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());
 }
 protected function setUp()
 {
     $application = new Application();
     $application->add(new RepositoryTransferCommand($this->container));
     $command = $application->get(RepositoryTransferCommand::COMMAND_NAME);
     $this->commandTester = new CommandTester($command);
 }
 public function setUp()
 {
     $application = new Application();
     $application->add(new UserTokenGenerateCommand());
     $this->command = $application->find('user:token:generate');
     $this->commandTester = new CommandTester($this->command);
 }
Example #6
1
 /**
  * {@inheritdoc}
  */
 public function execute(ContainerInterface $app)
 {
     foreach ($this->commands as $command) {
         $this->console->add($app->create($command));
     }
     $this->console->run();
 }
 /**
  * @return Application
  */
 public function create()
 {
     $app = new Application(Message::NAME, Message::VERSION);
     $app->setDefaultCommand(Message::COMMAND);
     $app->add($this->createAnalyzeCommand());
     return $app;
 }
Example #8
1
 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;
 }
 /**
  * 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 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 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'));
 }
Example #12
0
 public function setup()
 {
     $app = new Application();
     $app->add(new UpdateCommand());
     $this->cmd = $app->find('update');
     $this->tester = new CommandTester($this->cmd);
 }
 protected function getCommandTester()
 {
     $this->application->add($this->command);
     $command = $this->application->find('phpci:create-build');
     $commandTester = new CommandTester($command);
     return $commandTester;
 }
 /**
  * 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);
     }
 }
 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));
 }
 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 #17
0
 /**
  * @param Command $command
  * @param $index
  */
 private function registerCommandWithConsole(Command $command, $index)
 {
     $this->console->add($command);
     $command->registerAction(function () use($index) {
         $this->actions->handle($index);
     });
 }
 public function setUp()
 {
     $application = new Application();
     $application->add(new CreateTenantCommand());
     $this->command = $application->get('swp:tenant:create');
     $this->question = $this->command->getHelper('question');
 }
Example #19
0
 public function setUp()
 {
     $application = new Application();
     $application->add(new ConvertCommand());
     $this->command = $application->find('convert');
     $this->commandTester = new CommandTester($this->command);
 }
 /**
  * @param ContainerInterface $container
  * @param string $requestedName
  * @param array $options, optional
  *
  * @return Application
  */
 public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
 {
     $cliApplication = new Application('AsseticBundle', '1.7.0');
     $cliApplication->add(new BuildCommand($container->get('AsseticService')));
     $cliApplication->add(new SetupCommand($container->get('AsseticService')));
     return $cliApplication;
 }
 /**
  * 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 #22
0
 /**
  * @return CommandTester
  */
 protected function createCommandTester()
 {
     $application = new Application();
     $application->add(new LintCommand());
     $command = $application->find('lint:yaml');
     return new CommandTester($command);
 }
 /**
  * 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);
 }
Example #24
0
 /**
  * command应用主入口
  * @throws \Exception
  */
 static function main()
 {
     $application = new Application();
     $application->addCommands(self::createCommands());
     $application->setDefaultCommand(ThumbnailCommand::COMMAND_NAME);
     $application->run();
 }
 /**
  * {@inheritdoc}
  */
 public function createApplication($kernel, $commandName = null, $commandDescription = null)
 {
     $command = $this->createCommand($kernel, $commandName, $commandDescription);
     $application = new Application();
     $application->add($command);
     return $application;
 }
 public function testExecuteWithExectedUnavailableVersionAndInteraction()
 {
     // Mocks
     $configuration = $this->buildMock('AntiMattr\\MongoDB\\Migrations\\Configuration\\Configuration');
     $executedVersion = $this->buildMock('AntiMattr\\MongoDB\\Migrations\\Version');
     $migration = $this->buildMock('AntiMattr\\MongoDB\\Migrations\\Migration');
     $dialog = $this->buildMock('Symfony\\Component\\Console\\Helper\\DialogHelper');
     // Variables and Objects
     $numVersion = '000123456789';
     $input = new ArgvInput(array('application-name', MigrateCommand::NAME, $numVersion));
     $interactive = true;
     $executedVersions = array($executedVersion);
     $availableVersions = array();
     $application = new Application();
     $helperSet = new HelperSet(array('dialog' => $dialog));
     // Set properties on objects
     $application->setHelperSet($helperSet);
     $this->command->setApplication($application);
     $input->setInteractive($interactive);
     $this->command->setMigration($migration);
     $this->command->setMigrationConfiguration($configuration);
     // Expectations
     $configuration->expects($this->once())->method('getMigratedVersions')->will($this->returnValue($executedVersions));
     $configuration->expects($this->once())->method('getAvailableVersions')->will($this->returnValue($availableVersions));
     $dialog->expects($this->exactly(2))->method('askConfirmation')->will($this->returnValue(true));
     $migration->expects($this->once())->method('migrate')->with($numVersion);
     // Run command, run.
     $this->command->run($input, $this->output);
 }
 /**
  * Instantiate and adds the console commands to 
  * the console application
  * 
  * @return $this
  */
 protected function setupConsoleCommands()
 {
     foreach ($this->commandClasses() as $class) {
         $this->consoleApplication->add(new $class());
     }
     return $this;
 }
 /**
  * @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);
 }
Example #29
0
 /**
  * Constructor.
  *
  * If there is no readline support for the current PHP executable
  * a \RuntimeException exception is thrown.
  *
  * @param Application $application An application instance
  */
 public function __construct(Application $application)
 {
     $this->hasReadline = function_exists('readline');
     $this->application = $application;
     $this->history = getenv('HOME') . '/.history_' . $application->getName();
     $this->output = new ConsoleOutput();
 }
Example #30
0
 public function setup()
 {
     $app = new Application();
     $app->add(new CheckCommand());
     $this->cmd = $app->find('check');
     $this->tester = new CommandTester($this->cmd);
 }