예제 #1
0
 /**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $em = $this->get('entity_manager');
     $helperSet = new HelperSet();
     $helperSet->set(new ConnectionHelper($em->getConnection()), 'db');
     $helperSet->set(new EntityManagerHelper($em), 'em');
     $helperSet->set($this->getHelper('dialog'), 'dialog');
     $arguments = array();
     if ($input->getArgument('version')) {
         $arguments['version'] = $input->getArgument('version');
     }
     if ($input->getOption('write-sql')) {
         $arguments['--write-sql'] = $input->getOption('write-sql');
     }
     if ($input->getOption('dry-run')) {
         $arguments['--dry-run'] = $input->getOption('dry-run');
     }
     if ($input->getOption('query-time')) {
         $arguments['--query-time'] = $input->getOption('query-time');
     }
     if ($input->getOption('allow-no-migration')) {
         $arguments['--allow-no-migration'] = $input->getOption('allow-no-migration');
     }
     $configDir = $this->get('config')->get('[directories][config_dir]');
     $arguments['--configuration'] = $configDir . '/migrations.yml';
     $command = new MigrateCommand();
     $command->setHelperSet($helperSet);
     $returnCode = $command->run(new ArrayInput($arguments), $output);
     return $returnCode;
 }
예제 #2
0
 /**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $em = $this->get('entity_manager');
     $helperSet = new HelperSet();
     $helperSet->set(new ConnectionHelper($em->getConnection()), 'db');
     $helperSet->set(new EntityManagerHelper($em), 'em');
     $arguments = array();
     if ($input->getArgument('version')) {
         $arguments['version'] = $input->getArgument('version');
     }
     if ($input->getOption('add')) {
         $arguments['--add'] = $input->getOption('add');
     }
     if ($input->getOption('delete')) {
         $arguments['--delete'] = $input->getOption('delete');
     }
     if ($input->getOption('all')) {
         $arguments['--all'] = $input->getOption('all');
     }
     if ($input->getOption('range-from')) {
         $arguments['--range-from'] = $input->getOption('range-from');
     }
     if ($input->getOption('range-to')) {
         $arguments['--range-to'] = $input->getOption('range-to');
     }
     $configDir = $this->get('config')->get('[directories][config_dir]');
     $arguments['--configuration'] = $configDir . '/migrations.yml';
     $command = new VersionCommand();
     $command->setHelperSet($helperSet);
     $returnCode = $command->run(new ArrayInput($arguments), $output);
     return $returnCode;
 }
 protected function setUp()
 {
     parent::setUp();
     $this->inputMock = static::getMock(InputInterface::class);
     $this->outputMock = static::getMock(OutputInterface::class);
     $this->packageMock = static::getMock(PackageHelper::class);
     $this->requireMock = static::getMock(RequireHelper::class);
     $this->questionMock = Mockery::mock(QuestionHelper::class)->makePartial();
     $helperSet = new HelperSet();
     $helperSet->set($this->questionMock, 'question');
     $helperSet->set($this->packageMock, 'package');
     $helperSet->set($this->requireMock, 'composer require');
     $this->sut = new CodeSnifferCommand();
     $this->sut->setHelperSet($helperSet);
 }
예제 #4
0
 /**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $em = $this->get('entity_manager');
     $helperSet = new HelperSet();
     $helperSet->set(new ConnectionHelper($em->getConnection()), 'db');
     $helperSet->set(new EntityManagerHelper($em), 'em');
     $arguments = array();
     if ($input->getOption('dump-sql')) {
         $arguments['--dump-sql'] = $input->getOption('dump-sql');
     }
     $command = new CreateCommand();
     $command->setHelperSet($helperSet);
     $returnCode = $command->run(new ArrayInput($arguments), $output);
     return $returnCode;
 }
 /**
  * Mocks question helper.
  */
 protected function mockQuestionHelper(array $answers)
 {
     foreach ($answers as $key => $answer) {
         $this->questionHelper->expects($this->at($key + 2))->method('ask')->will($this->returnValue($answer));
     }
     $this->helperSet->set($this->questionHelper, 'question');
 }
 /**
  * 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);
     }
 }
예제 #7
0
 /**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $em = $this->get('entity_manager');
     $helperSet = new HelperSet();
     $helperSet->set(new ConnectionHelper($em->getConnection()), 'db');
     $helperSet->set(new EntityManagerHelper($em), 'em');
     $arguments = array();
     if ($input->getOption('editor-cmd')) {
         $arguments['--editor-cmd'] = $input->getOption('editor-cmd');
     }
     $configDir = $this->get('config')->get('[directories][config_dir]');
     $arguments['--configuration'] = $configDir . '/migrations.yml';
     $command = new GenerateCommand();
     $command->setHelperSet($helperSet);
     $returnCode = $command->run(new ArrayInput($arguments), $output);
     return $returnCode;
 }
예제 #8
0
 protected function setUp()
 {
     parent::setUp();
     $this->inputMock = static::getMock(InputInterface::class);
     $this->outputMock = static::getMock(OutputInterface::class);
     $this->packageMock = static::getMock(PackageHelper::class);
     $this->requireMock = static::getMock(RequireHelper::class);
     $this->questionMock = Mockery::mock(QuestionHelper::class)->makePartial();
     $this->processMock = static::getMockBuilder(Process::class)->disableOriginalConstructor()->getMock();
     $this->factoryMock = static::getMockBuilder(ProcessFactory::class)->disableProxyingToOriginalMethods()->getMock();
     $this->factoryMock->expects(static::any())->method('create')->willReturn($this->processMock);
     $helperSet = new HelperSet();
     $helperSet->set($this->questionMock, 'question');
     $helperSet->set($this->packageMock, 'package');
     $helperSet->set($this->requireMock, 'composer require');
     $this->sut = new BehatCommand($this->factoryMock);
     $this->sut->setHelperSet($helperSet);
 }
 /**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $em = $this->get('entity_manager');
     $helperSet = new HelperSet();
     $helperSet->set(new ConnectionHelper($em->getConnection()), 'db');
     $helperSet->set(new EntityManagerHelper($em), 'em');
     $command = new GenerateProxiesCommand();
     $command->setHelperSet($helperSet);
     $arguments = array();
     if ($input->getOption('filter')) {
         $arguments['--filter'] = $input->getOption('filter');
     }
     if ($input->getArgument('dest-path')) {
         $arguments['dest-path'] = $input->getArgument('dest-path');
     }
     $returnCode = $command->run(new ArrayInput($arguments), $output);
     return $returnCode;
 }
예제 #10
0
 /**
  * @inheritdoc
  */
 public function register()
 {
     $container = $this->getContainer();
     $container->singleton(Services::HELPERSET, function () use($container) {
         $helperSet = new HelperSet();
         $helperSet->set($container->get(Services::HELPERSET_QUESTION), 'question');
         return $helperSet;
     })->withArgument(Services::CONFIG);
     $container->add(Services::HELPERSET_QUESTION, QuestionHelper::class);
 }
예제 #11
0
 public function testIteration()
 {
     $helperset = new HelperSet();
     $helperset->set($this->getGenericMockHelper('fake_helper_01', $helperset));
     $helperset->set($this->getGenericMockHelper('fake_helper_02', $helperset));
     $helpers = array('fake_helper_01', 'fake_helper_02');
     $i = 0;
     foreach ($helperset as $helper) {
         $this->assertEquals($helpers[$i++], $helper->getName());
     }
 }
예제 #12
0
 protected function setUp()
 {
     parent::setUp();
     $this->inputMock = static::getMock(InputInterface::class);
     $this->outputMock = static::getMock(OutputInterface::class);
     $this->packageMock = static::getMock(PackageHelper::class);
     $this->requireMock = static::getMock(RequireHelper::class);
     $this->pathMock = static::getMock(PathHelper::class);
     $this->questionMock = Mockery::mock(QuestionHelper::class)->makePartial();
     $root = vfsStream::setup('projectDir');
     $this->configPath = $root->url() . '/phpunit.xml.dist';
     $this->pathMock->expects(static::any())->method('getPath')->with('phpunit.xml.dist')->willReturn($this->configPath);
     $this->factoryMock = static::getMockBuilder(ConfigurationFactory::class)->disableProxyingToOriginalMethods()->getMock();
     $helperSet = new HelperSet();
     $helperSet->set($this->questionMock, 'question');
     $helperSet->set($this->packageMock, 'package');
     $helperSet->set($this->requireMock, 'composer require');
     $helperSet->set($this->pathMock, 'path');
     $this->sut = new PhpUnitCommand($this->factoryMock);
     $this->sut->setHelperSet($helperSet);
 }
예제 #13
0
 /**
  * Sets the dojo theme to use.
  *
  * @param \Zend\ServiceManager\ServiceLocatorInterface $serviceLocator
  * @return \Symfony\Component\Console\Application
  */
 public function createService(ServiceLocatorInterface $serviceLocator)
 {
     $config = $serviceLocator->get('Config')['sds']['dojo'];
     $configHelper = new \Sds\DojoModule\Tools\Console\Helper\ConfigHelper($config);
     $helperSet = new HelperSet();
     $helperSet->set($configHelper, 'config');
     $cli = new Application();
     $cli->setName('DojoModule Command Line Interface');
     $cli->setHelperSet($helperSet);
     $cli->addCommands(array(new \Sds\DojoModule\Tools\Console\Command\GenerateProfile()));
     return $cli;
 }
예제 #14
0
 public function testExecute()
 {
     $profiler = $this->getMockBuilder('Symfony\\Component\\HttpKernel\\Profiler\\Profiler')->disableOriginalConstructor()->getMock();
     $profiler->expects($this->once())->method('import')->will($this->returnValue(new Profile('TOKEN')));
     $helperSet = new HelperSet();
     $helper = $this->getMock('Symfony\\Component\\Console\\Helper\\FormatterHelper');
     $helper->expects($this->any())->method('formatSection');
     $helperSet->set($helper, 'formatter');
     $command = new ImportCommand($profiler);
     $command->setHelperSet($helperSet);
     $commandTester = new CommandTester($command);
     $commandTester->execute(array('filename' => __DIR__ . '/../Fixtures/profile.data'));
     $this->assertRegExp('/Profile "TOKEN" has been successfully imported\\./', $commandTester->getDisplay());
 }
예제 #15
0
 public function testExecuteWithToken()
 {
     $profiler = $this->getMockBuilder('Symfony\\Component\\HttpKernel\\Profiler\\Profiler')->disableOriginalConstructor()->getMock();
     $profile = new Profile('TOKEN');
     $profiler->expects($this->once())->method('loadProfile')->with('TOKEN')->will($this->returnValue($profile));
     $helperSet = new HelperSet();
     $helper = $this->getMock('Symfony\\Component\\Console\\Helper\\FormatterHelper');
     $helper->expects($this->any())->method('formatSection');
     $helperSet->set($helper, 'formatter');
     $command = new ExportCommand($profiler);
     $command->setHelperSet($helperSet);
     $commandTester = new CommandTester($command);
     $commandTester->execute(array('token' => 'TOKEN'));
     $this->assertEquals($profiler->export($profile), $commandTester->getDisplay());
 }
예제 #16
0
 public function testSet()
 {
     $helperset = new HelperSet();
     $helperset->set($this->getGenericMockHelper('fake_helper', $helperset));
     $this->assertTrue($helperset->has('fake_helper'), '->set() adds helper to helpers');
     $helperset = new HelperSet();
     $helperset->set($this->getGenericMockHelper('fake_helper_01', $helperset));
     $helperset->set($this->getGenericMockHelper('fake_helper_02', $helperset));
     $this->assertTrue($helperset->has('fake_helper_01'), '->set() will set multiple helpers on consecutive calls');
     $this->assertTrue($helperset->has('fake_helper_02'), '->set() will set multiple helpers on consecutive calls');
     $helperset = new HelperSet();
     $helperset->set($this->getGenericMockHelper('fake_helper', $helperset), 'fake_helper_alias');
     $this->assertTrue($helperset->has('fake_helper'), '->set() adds helper alias when set');
     $this->assertTrue($helperset->has('fake_helper_alias'), '->set() adds helper alias when set');
 }
 /**
  * @param Container
  * @return Application
  */
 public static function createConsole(Container $container, $config)
 {
     $console = new Application($config['name'], $config['version']);
     $helperSet = new HelperSet();
     foreach (array_keys($container->findByTag(self::HELPER_TAG)) as $name) {
         $helperSet->set($container->getService($name), $name);
     }
     $console->setHelperSet($helperSet);
     $console->setCatchExceptions($config['catchExceptions']);
     $commands = [];
     foreach (array_keys($container->findByTag(self::COMMAND_TAG)) as $name) {
         $commands[] = $container->getService($name);
     }
     foreach (array_keys($container->findByTag(self::KDYBY_COMMAND_TAG)) as $name) {
         $commands[] = $container->getService($name);
     }
     $console->addCommands($commands);
     return $console;
 }
예제 #18
0
<?php

/**
 * PHP version 5.6
 *
 * This source file is subject to the license that is bundled with this package in the file LICENSE.
 */
require __DIR__ . '/../vendor/autoload.php';
use Symfony\Component\Console\Application;
use Symfony\Component\Console\Helper\HelperSet;
use Doctrine\DBAL\Tools\Console\Helper\ConnectionHelper;
use Doctrine\DBAL\DriverManager;
use ComPHPPuebla\Console\Command\LoadFixtureCommand;
$cli = new Application('DBAL Fixtures CLI', '2.0.0');
$cli->setCatchExceptions(true);
$connection = DriverManager::getConnection(require 'config/connection.config.php');
$helperSet = new HelperSet();
$helperSet->set(new ConnectionHelper($connection), 'db');
$cli->setHelperSet($helperSet);
$cli->addCommands([new LoadFixtureCommand()]);
$cli->run();
예제 #19
0
<?php

use Doctrine\DBAL\Tools\Console\Helper\ConnectionHelper;
use Symfony\Component\Console\Application;
use Symfony\Component\Console\Helper\DialogHelper;
use Symfony\Component\Console\Helper\HelperSet;
use Symfony\Component\Console\Input\InputOption;
$console = new Application('My Silex Application', 'n/a');
$console->getDefinition()->addOption(new InputOption('--env', '-e', InputOption::VALUE_REQUIRED, 'The Environment name.', 'dev'));
// Instantiate console application
$console->setCatchExceptions(true);
$helperSet = new HelperSet();
$helperSet->set(new ConnectionHelper($app['db']), 'connection');
$helperSet->set(new DialogHelper(), 'dialog');
$console->setHelperSet($helperSet);
$console->addCommands(array(new \Doctrine\DBAL\Migrations\Tools\Console\Command\DiffCommand(), new \Doctrine\DBAL\Migrations\Tools\Console\Command\ExecuteCommand(), new \Doctrine\DBAL\Migrations\Tools\Console\Command\GenerateCommand(), new \Doctrine\DBAL\Migrations\Tools\Console\Command\MigrateCommand(), new \Doctrine\DBAL\Migrations\Tools\Console\Command\StatusCommand(), new \Doctrine\DBAL\Migrations\Tools\Console\Command\VersionCommand()));
return $console;
 /**
  * @param HelperSet $helperSet
  */
 public function addTo(HelperSet $helperSet)
 {
     foreach ($this->helpers as $helper) {
         $helperSet->set($helper);
     }
 }
예제 #21
0
 */
require 'vendor/autoload.php';
use Symfony\Component\Console\Application;
use Symfony\Component\Console\Helper\HelperSet;
use Symfony\Component\Console\Helper\DialogHelper;
use Doctrine\DBAL\Tools\Console\Helper\ConnectionHelper;
use Doctrine\DBAL\Tools\Console\Command\RunSqlCommand;
use Doctrine\DBAL\Tools\Console\Command\ImportCommand;
use Doctrine\DBAL\Migrations\Tools\Console\Command\ExecuteCommand;
use Doctrine\DBAL\Migrations\Tools\Console\Command\GenerateCommand;
use Doctrine\DBAL\Migrations\Tools\Console\Command\MigrateCommand;
use Doctrine\DBAL\Migrations\Tools\Console\Command\StatusCommand;
use Doctrine\DBAL\Migrations\Tools\Console\Command\VersionCommand;
use Doctrine\DBAL\DriverManager;
use ComPHPPuebla\Doctrine\Command\CreateDatabaseCommand;
use ComPHPPuebla\Doctrine\Command\DropDatabaseCommand;
use ComPHPPuebla\Doctrine\Console\Command\LoadFixtureCommand;
/**
 * Application's CLI
 *
 * @author     LMV <*****@*****.**>
 */
$cli = new Application('Échale Ganas Command Line Interface');
$cli->setCatchExceptions(true);
$connection = DriverManager::getConnection(require 'config/connection.config.php');
$helperSet = new HelperSet();
$helperSet->set(new DialogHelper(), 'dialog');
$helperSet->set(new ConnectionHelper($connection), 'db');
$cli->setHelperSet($helperSet);
$cli->addCommands([new RunSqlCommand(), new ImportCommand(), new CreateDatabaseCommand(), new DropDatabaseCommand(), new ExecuteCommand(), new GenerateCommand(), new MigrateCommand(), new StatusCommand(), new VersionCommand(), new LoadFixtureCommand()]);
$cli->run();
예제 #22
0
 /**
  * Set Doctrine settings
  */
 protected function setDoctrineSettings(HelperSet $helperSet)
 {
     $config = new \Doctrine\ORM\Configuration();
     $config->setMetadataCacheImpl(new \Doctrine\Common\Cache\ArrayCache());
     $reader = new AnnotationReader();
     $driverImpl = new \Doctrine\ORM\Mapping\Driver\AnnotationDriver($reader, array());
     $config->setMetadataDriverImpl($driverImpl);
     $config->setProxyDir(__DIR__ . '/Proxies');
     $config->setProxyNamespace('Proxies');
     $settings = $this->getDatabaseSettings();
     $dbName = $settings['dbname'];
     unset($settings['dbname']);
     $em = \Doctrine\ORM\EntityManager::create($settings, $config);
     try {
         $connection = $em->getConnection();
         $dbList = $connection->getSchemaManager()->listDatabases();
         // Check in db exists in list.
         if (in_array($dbName, $dbList)) {
             $settings['dbname'] = $dbName;
             $em = \Doctrine\ORM\EntityManager::create($settings, $config);
         }
     } catch (ConnectionException $e) {
         echo $e->getMessage();
     }
     $platform = $em->getConnection()->getDatabasePlatform();
     $platform->registerDoctrineTypeMapping('enum', 'string');
     $platform->registerDoctrineTypeMapping('set', 'string');
     $helpers = array('db' => new \Doctrine\DBAL\Tools\Console\Helper\ConnectionHelper($em->getConnection()), 'em' => new \Doctrine\ORM\Tools\Console\Helper\EntityManagerHelper($em));
     foreach ($helpers as $name => $helper) {
         $helperSet->set($helper, $name);
     }
     return $em;
 }
예제 #23
0
파일: cli.php 프로젝트: janmarek/Neuron
<?php

use Nette\Environment;
use Symfony\Component\Console;
use Doctrine\DBAL\Tools\Console\Helper\ConnectionHelper;
use Doctrine\ORM\Tools\Console\Helper\EntityManagerHelper;
use Doctrine\ORM\Tools\Console\Command as DoctrineCommand;
use Doctrine\DBAL\Tools\Console\Command as DoctrineDBALCommand;
use Neuron\Console\Command as NeuronCommand;
require __DIR__ . '/../../../index.php';
$em = Environment::getService('Doctrine\\ORM\\EntityManager');
$helperSet = new Console\Helper\HelperSet();
$helperSet->set(new ConnectionHelper($em->getConnection()), 'db');
$helperSet->set(new EntityManagerHelper($em), 'em');
$cli = new Console\Application('Doctrine & Neuron Command Line Interface', Doctrine\ORM\Version::VERSION);
$cli->setCatchExceptions(true);
$cli->setHelperSet($helperSet);
$cli->addCommands(array(new DoctrineDBALCommand\RunSqlCommand(), new DoctrineDBALCommand\ImportCommand(), new DoctrineCommand\ClearCache\MetadataCommand(), new DoctrineCommand\ClearCache\ResultCommand(), new DoctrineCommand\ClearCache\QueryCommand(), new DoctrineCommand\SchemaTool\CreateCommand(), new DoctrineCommand\SchemaTool\UpdateCommand(), new DoctrineCommand\SchemaTool\DropCommand(), new DoctrineCommand\EnsureProductionSettingsCommand(), new DoctrineCommand\ConvertDoctrine1SchemaCommand(), new DoctrineCommand\GenerateRepositoriesCommand(), new DoctrineCommand\GenerateEntitiesCommand(), new DoctrineCommand\GenerateProxiesCommand(), new DoctrineCommand\ConvertMappingCommand(), new DoctrineCommand\RunDqlCommand(), new DoctrineCommand\ValidateSchemaCommand(), new NeuronCommand\GenerateForm(), new NeuronCommand\GenerateModel(), new NeuronCommand\GenerateCrud(), new NeuronCommand\GenerateFrontPresenter()));
$cli->run();
예제 #24
0
require 'vendor/autoload.php';
// Create the database connection and set up bit for boolean mapping
if (file_exists('migrations-db.php')) {
    $params = (include 'migrations-db.php');
    if (!is_array($params)) {
        throw new \InvalidArgumentException('The connection file has to return an array with database configuration parameters.');
    }
    $connection = \Doctrine\DBAL\DriverManager::getConnection($params);
} else {
    throw new \InvalidArgumentException('You have to specify a --db-configuration file or pass a Database Connection as a dependency to the Migrations.');
}
// Instantiate console application
$cli = new Console\Application('Doctrine Migrations', MigrationsVersion::VERSION());
$cli->setCatchExceptions(true);
$helperSet = new Console\Helper\HelperSet();
$helperSet->set(new Console\Helper\DialogHelper(), 'dialog');
$helperSet->set(new ConnectionHelper($connection), 'connection');
$cli->setHelperSet($helperSet);
// Add Migrations commands
$commands = array();
$commands[] = new MigrationsCommand\ExecuteCommand();
$commands[] = new MigrationsCommand\GenerateCommand();
$commands[] = new MigrationsCommand\LatestCommand();
$commands[] = new MigrationsCommand\MigrateCommand();
$commands[] = new MigrationsCommand\StatusCommand();
$commands[] = new MigrationsCommand\VersionCommand();
// remove the "migrations:" prefix on each command name
foreach ($commands as $command) {
    $command->setName(str_replace('migrations:', '', $command->getName()));
}
$cli->addCommands($commands);