Пример #1
0
 public function setUp()
 {
     $application = new Application($this->getContainer()->get('kernel'));
     $loadFixturesCommand = new LoadDataFixturesDoctrineCommand();
     $loadFixturesCommand->setApplication($application);
     $loadFixturesCommandTester = new CommandTester($loadFixturesCommand);
     $loadFixturesCommandTester->execute([], ['interactive' => false]);
     $this->command = new CreateUserCommand();
     $this->command->setApplication($application);
     $this->tester = new CommandTester($this->command);
 }
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $this->getContainer()->get('doctrine')->getManager()->getConnection()->prepare('SET FOREIGN_KEY_CHECKS = 0;')->execute();
     $result = parent::execute($input, $output);
     $this->getContainer()->get('doctrine')->getManager()->getConnection()->prepare('SET FOREIGN_KEY_CHECKS = 1;')->execute();
     return $result;
 }
 /**
  * @param \Symfony\Component\Console\Input\InputInterface $input
  * @param \Symfony\Component\Console\Output\OutputInterface $output
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $input->setOption('append', true);
     $this->fixFixturesPath($input);
     $this->fixtureOption($input);
     parent::execute($input, $output);
 }
 /**
  * Executes the current command.
  *
  * This method is not abstract because you can use this class
  * as a concrete class. In this case, instead of defining the
  * execute() method, you set the code to execute by passing
  * a Closure to the setCode() method.
  *
  * @param InputInterface  $input  An InputInterface instance
  * @param OutputInterface $output An OutputInterface instance
  *
  * @return null|int null or 0 if everything went fine, or an error code
  *
  * @throws \LogicException When this abstract method is not implemented
  *
  * @see setCode()
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     if (empty($this->databaseFilePath) || $input->getOption('no-booster')) {
         parent::execute($input, $output);
         return 0;
     }
     /**
      * Same code as parent implementation
      */
     $dirOrFile = $input->getOption('fixtures');
     $paths = [];
     if ($dirOrFile) {
         $paths = is_array($dirOrFile) ? $dirOrFile : [$dirOrFile];
     } else {
         foreach ($this->kernel->getBundles() as $bundle) {
             $paths[] = $bundle->getPath() . '/DataFixtures/ORM';
         }
     }
     /**
      * In order to take in account the kernel as well (same fixtures,
      * different kernel/different schema, make the tests crash
      */
     $paths[] = get_class($this->kernel);
     sort($paths, SORT_STRING);
     $backupFileName = sys_get_temp_dir() . '/' . sha1(serialize($paths)) . '.backup.database';
     if (file_exists($backupFileName)) {
         copy($backupFileName, $this->databaseFilePath);
         return 0;
     }
     parent::execute($input, $output);
     /**
      * If new file has been created, copy it with generated hash value. Now
      * this backup will be reusable for next iterations
      */
     if (file_exists($this->databaseFilePath)) {
         copy($this->databaseFilePath, $backupFileName);
     }
     return 0;
 }
Пример #5
0
 /**
  * @param PHPUnit_Framework_TestSuite $suite
  *
  * @throws \Doctrine\ORM\Tools\ToolsException
  */
 public function startTestSuite(PHPUnit_Framework_TestSuite $suite)
 {
     $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();
     $command->setContainer($kernel->getContainer());
     $application->add($command);
     $input = new ArrayInput(['command' => 'doctrine:database:drop', '--force' => true]);
     $command->run($input, new ConsoleOutput());
     // This stops a bug where Drop Database does not close the handle properly & causes subsequent
     // "database not found" errors.
     $connection = $kernel->getContainer()->get('doctrine')->getConnection();
     if ($connection->isConnected()) {
         $connection->close();
     }
     // add the database:create command to the application and run it
     $command = new CreateDatabaseDoctrineCommand();
     $command->setContainer($kernel->getContainer());
     $application->add($command);
     $input = new ArrayInput(['command' => 'doctrine:database:create']);
     $command->run($input, new ConsoleOutput());
     // Run the database migrations, with --quiet because they are quite
     // chatty on the console.
     $command = new MigrationsMigrateDoctrineCommand();
     $application->add($command);
     $input = new ArrayInput(['command' => 'doctrine:migrations:migrate', '--quiet' => false, '--no-interaction' => true]);
     $input->setInteractive(false);
     $command->run($input, new ConsoleOutput(ConsoleOutput::VERBOSITY_QUIET));
     // and load the fixtures
     $command = new LoadDataFixturesDoctrineCommand();
     $command->setContainer($kernel->getContainer());
     $application->add($command);
     $input = new ArrayInput(['command' => 'doctrine:fixtures:load', '--quiet']);
     $input->setInteractive(false);
     $command->run($input, new ConsoleOutput());
 }
 protected function configure()
 {
     parent::configure();
     $this->setName('koalamon:fixtures:load');
 }