예제 #1
0
 public function command($command, $opts = [])
 {
     $opts['-e'] = 'test';
     $opts['-q'] = null;
     $opts['command'] = $command;
     return $this->app->run(new ArrayInput($opts));
 }
 /**
  * @param $command
  * @param array $options
  * @return int
  */
 protected function runConsole($command, array $options = array())
 {
     $options["-e"] = "test";
     $options["-q"] = null;
     $options = array_merge($options, array('command' => $command));
     return $this->application->run(new \Symfony\Component\Console\Input\ArrayInput($options));
 }
예제 #3
0
 /**
  * Helper to run a Symfony command.
  *
  * @param string $command
  * @param array  $options
  *
  * @return int
  * @throws \Exception
  */
 protected function runConsole($command, array $options = [])
 {
     $options["-e"] = "test";
     $options["-q"] = null;
     $options = array_merge($options, ['command' => $command]);
     return $this->application->run(new ArrayInput($options));
 }
예제 #4
0
 /**
  * @BeforeScenario @cleanDB
  * @AfterScenario @cleanDB
  */
 public function cleanDB()
 {
     $application = new Application($this->getKernel());
     $application->setAutoExit(false);
     $application->run(new StringInput("doctrine:schema:drop --force -n -q"));
     $application->run(new StringInput("doctrine:schema:create -n -q"));
 }
예제 #5
0
 /**
  * Ensure next tests will have a clean database.
  */
 public static function tearDownAfterClass()
 {
     $application = new Application(static::$kernel);
     $application->setAutoExit(false);
     $application->run(new ArrayInput(['command' => 'doctrine:schema:drop', '--no-interaction' => true, '--force' => true, '--env' => 'test']), new NullOutput());
     $application->run(new ArrayInput(['command' => 'doctrine:schema:create', '--no-interaction' => true, '--env' => 'test']), new NullOutput());
     $application->run(new ArrayInput(['command' => 'doctrine:fixtures:load', '--no-interaction' => true, '--env' => 'test']), new NullOutput());
 }
예제 #6
0
 protected function setUp()
 {
     $client = static::createClient();
     $application = new Application($client->getKernel());
     $application->setAutoExit(false);
     $application->run(new StringInput('doctrine:database:drop --force'));
     $application->run(new StringInput('doctrine:database:create'));
     $application->run(new StringInput('doctrine:schema:update --force'));
 }
 private static function runCommand($commandName, $options = array())
 {
     $options["-e"] = self::$kernel->getEnvironment();
     $options['command'] = $commandName;
     $input = new ArrayInput($options);
     $output = new NullOutput();
     static::$application->setAutoExit(false);
     self::$application->run($input, $output);
 }
 public function testExecute()
 {
     $kernel = $this->createKernel();
     $kernel->boot();
     $application = new Application($kernel);
     $application->setAutoExit(false);
     $input = new ArgvInput(['', 'doctrine:database:drop', '--no-interaction', '--force', '-q']);
     $application->run($input);
     $input = new ArgvInput(['', 'doctrine:database:create', '--no-interaction', '-q']);
     $application->run($input);
     $input = new ArgvInput(['', 'doctrine:migrations:migrate', '--no-interaction', '-q']);
     $application->run($input);
     $em = $kernel->getContainer()->get('doctrine')->getManager();
     $customer = new Customer();
     $customer->setEmail('*****@*****.**');
     $customer->setActivationCode('abc');
     $customer->setEmployeeNumber('1234567890');
     $customer->setSalesdivision(Customer::SALESDIVISION_MEDIAMARKT_SATURN);
     $customer->setIsActivated(true);
     $customer->setCouponsHaveBeenSent(false);
     $customer->setOptInAccepted(false);
     $em->persist($customer);
     $couponcode = new Couponcode();
     $couponcode->setCode('111');
     $em->persist($couponcode);
     $couponcode = new Couponcode();
     $couponcode->setCode('222');
     $em->persist($couponcode);
     $couponcode = new Couponcode();
     $couponcode->setCode('333');
     $em->persist($couponcode);
     $couponcode = new Couponcode();
     $couponcode->setCode('444');
     $em->persist($couponcode);
     $couponcode = new Couponcode();
     $couponcode->setCode('555');
     $em->persist($couponcode);
     $couponcode = new Couponcode();
     $couponcode->setCode('666');
     $em->persist($couponcode);
     $em->flush();
     $application->add(new SendCouponsCommand());
     $command = $application->find('app:sendcoupons');
     $commandTester = new CommandTester($command);
     $commandTester->execute(array('command' => $command->getName()));
     $this->assertSame("example@example.org\n", $commandTester->getDisplay());
     $this->assertTrue($customer->getCouponsHaveBeenSent());
     $repo = $em->getRepository('AppBundle\\Entity\\Couponcode');
     $codes = $repo->findBy(['customer' => 1]);
     $this->assertSame('111', $codes[0]->getCode());
     $this->assertSame('222', $codes[1]->getCode());
     $this->assertSame('333', $codes[2]->getCode());
     $this->assertSame('444', $codes[3]->getCode());
     $this->assertSame('555', $codes[4]->getCode());
     $this->assertSame('666', $codes[5]->getCode());
     $this->assertSame(6, sizeof($codes));
 }
 /**
  * Setup
  */
 public function setUp()
 {
     static::$kernel = static::createKernel();
     static::$kernel->boot();
     static::$application = new Application(static::$kernel);
     static::$application->setAutoExit(false);
     $this->client = static::createClient();
     static::$application->run(new ArrayInput(array('command' => 'doctrine:database:drop', '--no-interaction' => true, '--force' => true, '--quiet' => true)));
     static::$application->run(new ArrayInput(array('command' => 'doctrine:database:create', '--no-interaction' => true, '--quiet' => true)));
     static::$application->run(new ArrayInput(array('command' => 'doctrine:schema:create', '--no-interaction' => true, '--quiet' => true)));
 }
예제 #10
0
 /**
  * @BeforeScenario
  */
 public function restoreDatabase()
 {
     $this->getEntityManager()->getConnection()->executeUpdate("SET foreign_key_checks = 0;");
     $application = new Application($this->kernel);
     $application->setAutoExit(false);
     $drop = array('command' => 'doctrine:schema:drop', '--force' => true, '--no-interaction' => true, '--quiet' => true, '--env' => 'test');
     $this->getEntityManager()->getConnection()->executeUpdate("SET foreign_key_checks = 1;");
     $application->run(new ArrayInput($drop));
     $create = array('command' => 'doctrine:schema:create', '--no-interaction' => true, '--quiet' => true, '--env' => 'test');
     $application->run(new ArrayInput($create));
 }
예제 #11
0
 public function setUp()
 {
     $this->client = static::createClient();
     $this->em = $this->client->getContainer()->get('doctrine')->getManager();
     $application = new Application($this->client->getKernel());
     $application->setAutoExit(false);
     $application->run(new StringInput('doctrine:database:drop --force'));
     $application->run(new StringInput('doctrine:database:create'));
     $application->run(new StringInput('doctrine:schema:update --force'));
     $application->run(new StringInput('doctrine:fixtures:load --append'));
     $this->logIn();
 }
예제 #12
0
 /**
  * @param InputInterface $input
  * @param OutputInterface $output
  * @return int|null|void
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $this->io->title($this->getDescription());
     foreach ($this->apiViews as $apiView) {
         $bufferOutput = new BufferedOutput();
         $this->application->run(new StringInput(sprintf('api:doc:dump --view=%s', $apiView)), $bufferOutput);
         $viewDump = $bufferOutput->fetch();
         $viewDumpFile = __DIR__ . '/../Resources/doc/' . $apiView . '-api-doc.md';
         file_put_contents($viewDumpFile, $viewDump);
         $this->io->writeln(sprintf("%s -> view dumped to %s", $apiView, $viewDumpFile));
     }
 }
 public function prepareFixturesOnly()
 {
     $application = new Application($this->kernel);
     $application->setAutoExit(false);
     $options = array('command' => 'doctrine:database:drop', '--force' => true);
     $application->run(new ArrayInput($options));
     $options = array('command' => 'doctrine:database:create');
     $application->run(new ArrayInput($options));
     $options = array('command' => 'doctrine:schema:create');
     $application->run(new ArrayInput($options));
     $this->fixturesApplier->applyFixtures();
 }
예제 #14
0
 /**
  * @see Command
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $listenerManager = $this->container->get('doctrine_extensions.listener_manager');
     $listenerManager->addAllListeners($this->container->get('doctrine.orm.entity_manager'));
     $purger = new ORMPurger($this->container->get('doctrine.orm.entity_manager'));
     $purger->purge();
     $string_input = new StringInput('yrch:populate');
     $application = new Application($this->application->getKernel());
     $application->setAutoExit(false);
     $application->run($string_input, $output);
     $string_input = new StringInput('doctrine:data:load --append=true');
     $application->run($string_input, $output);
 }
 public function testIntegration()
 {
     $client = static::createClient();
     $application = new Application($client->getKernel());
     $output = new BufferedOutput();
     $application->setAutoExit(false);
     $application->run(new ArgvInput(), $output);
     $this->assertTrue(strpos($output->fetch(), 'Comment from the method') !== false, 'Description of the command is not parse from the comment of the method');
     $arguments = array('this will be ignored', 'test_service:hello', '--name=toto', '--help');
     $application->run(new ArgvInput($arguments), $output);
     $outputString = $output->fetch();
     $this->assertTrue(strpos($outputString, 'The name of the person you want to say hello to') !== false, 'Parsing of param comment is not working');
     $this->assertTrue(strpos($outputString, '--output') === false, 'Output parameter should not be there since it cannot be enter by the user');
 }
 protected function loadFixtures($kernel)
 {
     // This is the simplest way to load doctrine data fixtures from unit
     // tests. An alternative would be to load the fixtures via Doctrine's
     // DataFixture API. See: https://github.com/doctrine/data-fixtures#doctrine-data-fixtures-extension
     $app = new Application($kernel);
     $app->setAutoExit(false);
     $app->run(new ArrayInput(['command' => 'doctrine:database:drop', '--force' => true, '--quiet' => true]));
     // See http://stackoverflow.com/questions/7134469/doctrine-2-close-connection
     $kernel->getContainer()->get('doctrine')->getManager()->getConnection()->close();
     $app->run(new ArrayInput(['command' => 'doctrine:database:create', '--quiet' => true]));
     $app->run(new ArrayInput(['command' => 'doctrine:schema:create', '--quiet' => true]));
     $app->run(new ArrayInput(['command' => 'doctrine:fixtures:load', '--quiet' => true, '--no-interaction' => true]));
 }
예제 #17
0
 protected function resetDatabase()
 {
     $client = static::createClient();
     $kernel = $client->getKernel();
     $kernel->boot();
     $application = new Application($kernel);
     $application->setAutoExit(false);
     $input = new ArgvInput(['', 'doctrine:database:drop', '--no-interaction', '--force', '-q']);
     $application->run($input);
     $input = new ArgvInput(['', 'doctrine:database:create', '--no-interaction', '-q']);
     $application->run($input);
     $output = new ConsoleOutput();
     $input = new ArgvInput(['', 'doctrine:migrations:migrate', '--no-interaction', '-q']);
     $application->run($input, $output);
 }
예제 #18
0
 private static function executeCommand(Application $application, $command, array $options = array())
 {
     $options['--env'] = 'test';
     $options['--quiet'] = null;
     $options = array_merge($options, array('command' => $command));
     return $application->run(new ArrayInput($options));
 }
예제 #19
0
 /**
  * @Route("/generate", name="backups_generate")
  */
 public function generateAction()
 {
     $finder = new Finder();
     try {
         $finder->files()->in($this->get('kernel')->getRootDir() . '/../backups')->sortByModifiedTime();
     } catch (\Exception $exc) {
         $finder = null;
     }
     $fs = new Filesystem();
     $count = $finder->count();
     foreach ($finder->files() as $file) {
         if ($count >= 5) {
             try {
                 $fs->remove($file);
             } catch (IOExceptionInterface $e) {
                 echo "An error occurred while creating your directory at " . $e->getPath();
             }
             $count--;
         }
     }
     $kernel = $this->get('kernel');
     $application = new Application($kernel);
     $application->setAutoExit(false);
     $input = new ArrayInput(array('command' => 'zenstruck:backup:run', 'profile' => 'daily', '-e' => 'prod', '--clear'));
     $output = new BufferedOutput();
     $application->run($input, $output);
     $content = $output->fetch();
     $this->addFlash('success', 'Backup generated');
     return $this->redirectToRoute('backups');
 }
예제 #20
0
 protected function runCommand($command)
 {
     $command = sprintf('%s --quiet', $command);
     $application = new Application($this->client->getKernel());
     $application->setAutoExit(false);
     return $application->run(new StringInput($command));
 }
 private static function initDatabase()
 {
     $console = new Application(static::$kernel);
     $console->setAutoExit(false);
     /**
      * SQLite is not supported yet
      *
      * @link https://github.com/doctrine/dbal/pull/2402
      */
     $commands = ['doctrine:database:create' => ['--if-not-exists' => true], 'doctrine:schema:drop' => ['--full-database' => true, '--force' => true], 'doctrine:migrations:migrate' => [], 'doctrine:fixtures:load' => []];
     foreach ($commands as $command => $args) {
         /** apply common commands options */
         $args['--env'] = 'test';
         $args['--quiet'] = true;
         $args['--no-interaction'] = true;
         $args['command'] = $command;
         try {
             $console->setCatchExceptions(false);
             $console->run(new ArrayInput($args));
         } catch (\Exception $e) {
             echo PHP_EOL . $e->getMessage() . PHP_EOL;
             echo PHP_EOL . $e->getTraceAsString() . PHP_EOL;
             throw $e;
         }
     }
 }
예제 #22
0
function executeCommand(Application $app, $cmd, array $options = [])
{
    $options['--env'] = 'test';
    $options['--quiet'] = true;
    $options['command'] = $cmd;
    $app->run(new ArrayInput($options));
}
예제 #23
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $this->io = new SymfonyStyle($input, $output);
     $locator = $this->getContainer()->get('campaignchain.core.module.locator');
     $bundles = $locator->getAvailableBundles();
     $selectedBundle = $this->selectBundle($bundles);
     $generateOutput = new BufferedOutput();
     $application = new Application($this->getContainer()->get('kernel'));
     $application->setAutoExit(false);
     $application->run(new ArrayInput(['command' => $this->getDoctrineMigrationsCommand(), '--no-interaction' => true]), $generateOutput);
     preg_match('/Generated new migration class to "(.*)"/', $generateOutput->fetch(), $matches);
     if (count($matches) < 2) {
         //error
         return;
     }
     $pathForMigrationFile = $matches[1];
     preg_match('/Version.*.php/', $pathForMigrationFile, $fileNames);
     if (!count($fileNames)) {
         return;
     }
     $schemaFile = $this->getContainer()->getParameter('kernel.root_dir') . DIRECTORY_SEPARATOR . '..';
     $schemaFile .= DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR . $selectedBundle->getName();
     $schemaFile .= str_replace('/', DIRECTORY_SEPARATOR, $this->getContainer()->getParameter('campaignchain_update.bundle.schema_dir'));
     $schemaFile .= DIRECTORY_SEPARATOR . $fileNames[0];
     $fs = new Filesystem();
     $fs->copy($pathForMigrationFile, $schemaFile);
     $fs->remove($pathForMigrationFile);
     $this->io->success('Generation finished. You can find the file here:');
     $this->io->text($schemaFile);
 }
예제 #24
0
 /**
  * Clear the application cache and run the warmup routine for the current environment
  *
  * @param bool $noWarmup Skips the warmup routine
  * @param bool $configSave True if clearing the cache after saving the configuration
  * @return void
  */
 public function clearCache($noWarmup = false, $configSave = false)
 {
     $this->clearSessionItems();
     $memoryLimit = ini_get('memory_limit');
     if ((int) substr($memoryLimit, 0, -1) < 128) {
         ini_set('memory_limit', '128M');
     }
     $this->clearOpcaches($configSave);
     //attempt to squash command output
     ob_start();
     $env = $this->factory->getEnvironment();
     $args = array('console', 'cache:clear', '--env=' . $env);
     if ($env == 'prod') {
         $args[] = '--no-debug';
     }
     if ($noWarmup) {
         $args[] = '--no-warmup';
     }
     $input = new ArgvInput($args);
     $application = new Application($this->factory->getKernel());
     $application->setAutoExit(false);
     $output = new NullOutput();
     $application->run($input, $output);
     if (ob_get_length() > 0) {
         ob_end_clean();
     }
 }
예제 #25
0
 /**
  * Clear the application cache and run the warmup routine for the current environment
  *
  * @param bool $noWarmup Skips the warmup routine
  *
  * @return void
  */
 public function clearCache($noWarmup = false)
 {
     $this->clearSessionItems();
     // Force a refresh of enabled addon bundles so they are picked up by the events
     $addonHelper = $this->factory->getHelper('addon');
     $addonHelper->buildAddonCache();
     ini_set('memory_limit', '128M');
     //attempt to squash command output
     ob_start();
     $env = $this->factory->getEnvironment();
     $args = array('console', 'cache:clear', '--env=' . $env);
     if ($env == 'prod') {
         $args[] = '--no-debug';
     }
     if ($noWarmup) {
         $args[] = '--no-warmup';
     }
     $input = new ArgvInput($args);
     $application = new Application($this->factory->getKernel());
     $application->setAutoExit(false);
     $output = new NullOutput();
     $application->run($input, $output);
     if (ob_get_length() > 0) {
         ob_end_clean();
     }
 }
 private function report(Application $application)
 {
     $output = new BufferedOutput();
     $arguments = array('this will be ignored', 'nucleus_migration:report');
     $application->run(new ArgvInput($arguments), $output);
     return $output->fetch();
 }
예제 #27
0
 /**
  * @Route("/tokens/clear}", name="admin_clear_stale_tokens")
  */
 public function clearStaleTokens()
 {
     $application = new Application($this->get('kernel'));
     $application->setAutoExit(false);
     $application->run(new ArrayInput(array('command' => 'fos:oauth-server:clean')));
     $this->addFlash('success', 'Stale tokens cleaned');
     return $this->redirectToRoute('admin_setting_list');
 }
예제 #28
0
파일: BaseTestSetup.php 프로젝트: ojs/ojs
 /**
  * @param $command
  * @param array $options
  * @return integer
  */
 protected function runConsole($command, array $options = array())
 {
     $options["--env"] = "test";
     $options["--quiet"] = null;
     $options["--no-interaction"] = null;
     $options = array_merge($options, array('command' => $command));
     return $this->app->run(new ArrayInput($options));
 }
예제 #29
0
 /**
  * @When I run the command :commandName
  */
 public function iRunTheCommand($commandName)
 {
     $application = new Application($this->kernel);
     $application->setAutoExit(false);
     $input = new ArrayInput(['command' => $commandName]);
     $output = new NullOutput();
     $this->lastRun = $application->run($input, $output);
 }
예제 #30
0
 /**
  * @When /^se envía un correo de aviso de renovación con (\d+) días de antelación$/
  */
 public function seEnvíaUnCorreoDeAvisoDeRenovaciónConDíasDeAntelación($dias)
 {
     $application = new Application($this->kernel);
     $application->setAutoExit(false);
     $input = new ArrayInput(['command' => 'seta:cron:run']);
     $output = new NullOutput();
     $application->run($input, $output);
 }