Gets the Kernel associated with this Console.
public getKernel ( ) : Symfony\Component\HttpKernel\KernelInterface | ||
return | Symfony\Component\HttpKernel\KernelInterface | A KernelInterface instance |
/** * create test db. */ public function initDB() { static::bootKernel(); $this->application = new Application(static::$kernel); $this->em = $this->getEntityManager(); // drop the database $command = new DropDatabaseDoctrineCommand(); $this->application->add($command); $input = new ArrayInput(array('command' => 'doctrine:database:drop', '--force' => true)); $command->run($input, new NullOutput()); // we have to close the connection after dropping the database so we don't get "No database selected" error $connection = $this->application->getKernel()->getContainer()->get('doctrine')->getConnection(); if ($connection->isConnected()) { $connection->close(); } // create the database $command = new CreateDatabaseDoctrineCommand(); $this->application->add($command); $input = new ArrayInput(array('command' => 'doctrine:database:create')); $command->run($input, new NullOutput()); // create schema $command = new CreateSchemaDoctrineCommand(); $this->application->add($command); $input = new ArrayInput(array('command' => 'doctrine:schema:create')); $command->run($input, new NullOutput()); }
protected function setUp() { self::bootKernel(); $this->application = new Application(self::$kernel); // Register doctrine bundles $this->application->add(new LoadDataFixturesCommand($this->application->getKernel()->getContainer()->get('doctrine'), $this->application->getKernel()->getContainer()->get('hautelook_alice.fixtures.loader'), $this->application->getKernel()->getContainer()->get('hautelook_alice.doctrine.finder'))); $this->doctrineManager = $this->application->getKernel()->getContainer()->get('doctrine')->getManager(); $this->application->setAutoExit(false); $this->runConsole("doctrine:schema:drop", ["--force" => true]); $this->runConsole("doctrine:schema:create"); }
private function addConsoleHelpers(FrameworkApplication $app) { if (!Util::hasQuestionHelper()) { $helper = $app->getKernel()->getContainer()->get('rj_frontend.console.helper.question_legacy'); $app->getHelperSet()->set($helper, 'question'); } }
/** * Wrapper function to get whole contents of a particular log file as a string * * @param $name * * @return string * @throws Exception is the logfile does not exist */ protected function getLogfileContents($name) { if (!$this->doesLogfileExist($name)) { throw new \Exception('Could not file logfile with name \'' . $name . '\' to read contents from for test'); } return file_get_contents($this->application->getKernel()->getLogDir() . DIRECTORY_SEPARATOR . $name); }
/** * @param Symfony\Bundle\FrameworkBundle\Console\Application * @param string $dmName */ public static function setApplicationDocumentManager(Application $application, $dmName) { /** @var $dm \Doctrine\ODM\DocumentManager */ $alias = sprintf("doctrine_mongodb.odm.%s", $dmName); $dm = $application->getKernel()->getContainer()->get($alias); $helperSet = $application->getHelperSet(); $helperSet->set(new DocumentManagerHelper($dm), 'dm'); }
/** * Set the document manager on the application. * * @param Application $application * @param string $dmName */ public static function setApplicationDocumentManager(Application $application, $dmName) { /** @var $registry ManagerRegistry */ $registry = $application->getKernel()->getContainer()->get('doctrine_phpcr'); $documentManager = $registry->getManager($dmName); $helperSet = $application->getHelperSet(); $helperSet->set(new DocumentManagerHelper(null, $documentManager)); }
public static function setApplicationHelper(Application $application, InputInterface $input) { $doctrine = $application->getKernel()->getContainer()->get('doctrine'); if ($doctrine->getManagerNames()) { self::setApplicationConnection($application, $input->getOption('db')); } else { self::setApplicationEntityManager($application, $input->getOption('em')); } }
public static function configureMigrationsForBundle(Application $application, $bundle, Configuration $configuration) { $bundle = $application->getKernel()->getBundle($bundle); $dir = $bundle->getPath() . '/DoctrineMigrations'; $configuration->setMigrationsNamespace($bundle->getNamespace() . '\\DoctrineMigrations'); $configuration->setMigrationsDirectory($dir); $configuration->registerMigrationsFromDirectory($dir); $configuration->setName($bundle->getName() . ' Migrations'); $configuration->setMigrationsTableName(Inflector::tableize($bundle->getName()) . '_migration_versions'); }
public function testRunImportCommand() { $application = new Application($this->getClient()->getKernel()); $application->add(new ImportCommand()); $command = $application->find('wallabag:import'); $tester = new CommandTester($command); $tester->execute(['command' => $command->getName(), 'userId' => 1, 'filepath' => $application->getKernel()->getContainer()->getParameter('kernel.root_dir') . '/../tests/Wallabag/ImportBundle/fixtures/wallabag-v2-read.json', '--importer' => 'v2']); $this->assertContains('imported', $tester->getDisplay()); $this->assertContains('already saved', $tester->getDisplay()); }
/** * Looks at all the bundles registered in the application to return the bundles requested. An exception is thrown * if a bundle has not been found. * * @param Application $application Application in which bundles will be looked in. * @param string[] $names Bundle names. * * @return BundleInterface[] Bundles requested. * @throws \RuntimeException A bundle could not be resolved. */ public function resolveBundles(Application $application, array $names) { $bundles = $application->getKernel()->getBundles(); $result = []; foreach ($names as $name) { if (false === isset($bundles[$name])) { throw new \RuntimeException(sprintf('The bundle "%s" was not found. Bundles availables are: %s.', $name, implode('", "', array_keys($bundles)))); } $result[$name] = $bundles[$name]; } return $result; }
public static function setApplicationDocumentManager(Application $application, $dmName) { $container = $application->getKernel()->getContainer(); $dmName = $dmName ? $dmName : 'default'; $dmServiceName = sprintf('doctrine.odm.mongodb.%s_document_manager', $dmName); if (!$container->has($dmServiceName)) { throw new \InvalidArgumentException(sprintf('Could not find Doctrine ODM DocumentManager named "%s"', $dmName)); } $dm = $container->get($dmServiceName); $helperSet = $application->getHelperSet(); $helperSet->set(new DocumentManagerHelper($dm), 'dm'); }
public static function setApplicationXmlEntityManager(Application $application, $xemName) { $container = $application->getKernel()->getContainer(); $xemName = $xemName ? $xemName : 'default'; $xemServiceName = sprintf('doctrine.oxm.%s_xml_entity_manager', $xemName); if (!$container->has($xemServiceName)) { throw new \InvalidArgumentException(sprintf('Could not find Doctrine OXM XmlEntityManager named "%s"', $xemName)); } $xem = $container->get($xemServiceName); $helperSet = $application->getHelperSet(); $helperSet->set(new XmlEntityManagerHelper($xem), 'xem'); }
public static function setApplicationConnection(Application $application, $connName) { $container = $application->getKernel()->getContainer(); $connName = $connName ? $connName : $container->getParameter('doctrine.dbal.default_connection'); $connServiceName = sprintf('doctrine.dbal.%s_connection', $connName); if (!$container->has($connServiceName)) { throw new \InvalidArgumentException(sprintf('Could not find Doctrine Connection named "%s"', $connName)); } $connection = $container->get($connServiceName); $helperSet = $application->getHelperSet(); $helperSet->set(new ConnectionHelper($connection), 'db'); }
public static function configureMigrationsForBundle(Application $application, $bundle, Configuration $configuration) { $configuration->setMigrationsNamespace($bundle . '\\DoctrineMigrations'); $dirs = $application->getKernel()->getBundleDirs(); $tmp = str_replace('\\', '/', $bundle); $namespace = str_replace('/', '\\', dirname($tmp)); $bundle = basename($tmp); $dir = $dirs[$namespace] . '/' . $bundle . '/DoctrineMigrations'; $configuration->setMigrationsDirectory($dir); $configuration->registerMigrationsFromDirectory($dir); $configuration->setName($bundle . ' Migrations'); $configuration->setMigrationsTableName(Inflector::tableize($bundle) . '_migration_versions'); }
public function testRunRedisWorkerCommand() { $application = new Application($this->getClient()->getKernel()); $application->add(new RedisWorkerCommand()); $factory = new RedisMockFactory(); $redisMock = $factory->getAdapter('Predis\\Client', true); $application->getKernel()->getContainer()->set('wallabag_core.redis.client', $redisMock); // put a fake message in the queue so the worker will stop after reading that message // instead of waiting for others $redisMock->lpush('wallabag.import.readability', '{}'); $command = $application->find('wallabag:import:redis-worker'); $tester = new CommandTester($command); $tester->execute(['command' => $command->getName(), 'serviceName' => 'readability', '--maxIterations' => 1]); $this->assertContains('Worker started at', $tester->getDisplay()); $this->assertContains('Waiting for message', $tester->getDisplay()); }
public static function setApplicationHelper(Application $application, InputInterface $input) { $container = $application->getKernel()->getContainer(); $doctrine = $container->get('doctrine'); $managerNames = $doctrine->getManagerNames(); if (empty($managerNames)) { self::setApplicationConnection($application, $input->getOption('db')); } else { self::setApplicationEntityManager($application, $input->getOption('em')); } if ($input->getOption('shard')) { $connection = $application->getHelperSet()->get('db')->getConnection(); if (!$connection instanceof PoolingShardConnection) { if (empty($managerNames)) { throw new \LogicException(sprintf("Connection '%s' must implement shards configuration.", $input->getOption('db'))); } else { throw new \LogicException(sprintf("Connection of EntityManager '%s' must implement shards configuration.", $input->getOption('em'))); } } $connection->connect($input->getOption('shard')); } }
/** * Convenience method to push the helper sets of a given connection into the application. * * @param Application $application * @param string $connName */ public static function setApplicationConnection(Application $application, $connName) { $connection = $application->getKernel()->getContainer()->get('doctrine')->getConnection($connName); $helperSet = $application->getHelperSet(); $helperSet->set(new ConnectionHelper($connection), 'db'); }
/** * @return mixed */ public function getContainer() { return $this->application->getKernel()->getContainer(); }
$kernel = new AppKernel('test', true); // create a "test" kernel $kernel->boot(); $application = new Application($kernel); // add the database:drop command to the application and run it $command = new DropDatabaseDoctrineCommand(); $application->add($command); $input = new ArrayInput(array('command' => 'doctrine:database:drop', '--force' => true)); $command->run($input, new ConsoleOutput()); // add the database:create command to the application and run it $command = new CreateDatabaseDoctrineCommand(); $application->add($command); $input = new ArrayInput(array('command' => 'doctrine:database:create')); $command->run($input, new ConsoleOutput()); // Hack $connection = $application->getKernel()->getContainer()->get('doctrine')->getConnection(); if ($connection->isConnected()) { $connection->close(); } // let Doctrine create the database schema (i.e. the tables) $command = new CreateSchemaDoctrineCommand(); $application->add($command); $input = new ArrayInput(array('command' => 'doctrine:schema:create')); $command->run($input, new ConsoleOutput()); /* //load fixtures $command = new LoadDataFixturesDoctrineCommand(); $application->add($command); $input = new ArrayInput(array( 'command' => 'doctrine:fixtures:load', '--fixtures' => 'src/Neblion/ScrumBundle/DataFixtures/Tests',
public static function setApplicationDocumentManager(Application $application, $dmName) { $dm = $application->getKernel()->getContainer()->get('doctrine_mongodb')->getManager($dmName); $helperSet = $application->getHelperSet(); $helperSet->set(new DocumentManagerHelper($dm), 'dm'); }
protected function setUp() { self::bootKernel(); $this->application = new Application(self::$kernel); $this->faker = $this->application->getKernel()->getContainer()->get('hautelook_alice.faker'); }
protected function setUp() { self::bootKernel(); $this->application = new Application(self::$kernel); $this->processorChain = $this->application->getKernel()->getContainer()->get('hautelook_alice.alice.processor_chain'); }
/** * @return \Doctrine\Bundle\DoctrineBundle\Registry */ private function getDoctrine() { return $this->application->getKernel()->getContainer()->get('doctrine'); }
/** * Execute a command * * @param string $command Command * @param array $parameters Parameters * * @return $this Self object */ protected function executeCommand($command, array $parameters = []) { $environment = $this->application->getKernel()->getEnvironment(); $this->application->run(new ArrayInput(array_merge(['command' => $command, '--no-interaction' => true, '--env' => $environment, '--quiet' => true], $parameters))); return $this; }