Author: Fabien Potencier (fabien.potencier@symfony-project.com)
Inheritance: extends Symfony\Components\Console\Application
 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();
 }
 public static function setUpBeforeClass()
 {
     @unlink(__DIR__ . '/../Fixtures/Test/TestBundle/Resources/config/routing.rest.yml');
     @unlink(__DIR__ . '/../Fixtures/Test/TestBundle/Controller/CarController.php');
     @unlink(__DIR__ . '/../Fixtures/Test/TestBundle/Controller/OrderController.php');
     $kernel = new \AppKernel('test', true);
     $app = new Application($kernel);
     $app->addCommands(array(new GenerateRestControllerCommand()));
     $kernel->boot();
     $command = $app->find('generate:rest:controller');
     $commandTester = new CommandTester($command);
     $commandTester->execute(array('command' => $command->getName(), '--controller' => 'TestTestBundle:Order', '--entity' => 'TestTestBundle:Order', '--mongo' => true), array('interactive' => false));
     $kernel->shutdown();
     $kernel = new \AppKernel('test', true);
     $app = new Application($kernel);
     $app->addCommands(array(new GenerateRestControllerCommand()));
     $kernel->boot();
     $command = $app->find('generate:rest:controller');
     $commandTester = new CommandTester($command);
     $commandTester->execute(array('command' => $command->getName(), '--controller' => 'TestTestBundle:Car', '--entity' => 'TestTestBundle:Car'), array('interactive' => false));
     $kernel->shutdown();
     @unlink(__DIR__ . '/../app/cache/test/appTestUrlGenerator.php.meta');
     @unlink(__DIR__ . '/../app/cache/test/appTestUrlGenerator.php');
     @unlink(__DIR__ . '/../app/cache/test/appTestUrlMatcher.php.meta');
     @unlink(__DIR__ . '/../app/cache/test/appTestUrlMatcher.php');
 }
 /**
  * @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));
 }
Example #4
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);
 }
 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;
         }
     }
 }
Example #6
0
 public function command($command, $opts = [])
 {
     $opts['-e'] = 'test';
     $opts['-q'] = null;
     $opts['command'] = $command;
     return $this->app->run(new ArrayInput($opts));
 }
Example #7
0
 /**
  * @Given I run Sylius Install Load Sample Data command
  */
 public function iRunSyliusInstallSampleDataCommand()
 {
     $this->application = new Application($this->kernel);
     $this->application->add(new InstallSampleDataCommand());
     $this->command = $this->application->find('sylius:install:sample-data');
     $this->tester = new CommandTester($this->command);
 }
 /**
  * Executor which runs a command.
  *
  * @param string $name
  * @param array  $args
  *
  * @return CommandTester
  */
 protected function executeCommand(string $name, array $args = []) : CommandTester
 {
     $application = new Application($this->getKernel());
     $tester = new CommandTester($application->get($name));
     $tester->execute($args, ['interactive' => false]);
     return $tester;
 }
 /**
  * Set up test
  */
 public function setUp()
 {
     static::$kernel = static::createKernel();
     static::$kernel->boot();
     static::$application = new Application(static::$kernel);
     static::$application->setAutoExit(false);
 }
Example #10
0
function executeCommand(Application $app, $cmd, array $options = [])
{
    $options['--env'] = 'test';
    $options['--quiet'] = true;
    $options['command'] = $cmd;
    $app->run(new ArrayInput($options));
}
Example #11
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"));
 }
Example #12
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();
     }
 }
 public function runCommand($commandServiceId, array $input = array())
 {
     $this->errorCode = null;
     $this->commandTester = null;
     $command = $this->grabServiceFromContainer($commandServiceId);
     $application = new Application($this->kernel);
     $application->add($command);
     $commandTester = new CommandTester($command);
     try {
         $commandTester->execute(array('command' => $command->getName()) + $input, array('interactive' => false));
     } catch (\Exception $e) {
         $exitCode = $e->getCode();
         if (is_numeric($exitCode)) {
             $exitCode = (int) $exitCode;
             if (0 === $exitCode) {
                 $exitCode = 1;
             }
         } else {
             $exitCode = 1;
         }
         $this->errorCode = $exitCode;
         $this->debug((string) $e);
         return;
     }
     $this->debug($commandTester->getDisplay());
     $this->commandTester = $commandTester;
 }
 public function testExecute()
 {
     $expected = '/^.+ [a-z0-9]+@local.+api-key: [a-f0-9]+ secret: [a-f0-9]+$/';
     $commandTester = new CommandTester($this->instance->find('hayapi:create-user'));
     $commandTester->execute(array('username' => $this->userIdentifier, 'email' => $this->userIdentifier, 'password' => $this->userIdentifier), array('interactive'));
     $this->assertRegExp($expected, $commandTester->getDisplay());
 }
Example #15
0
 public function testCacheIsFreshAfterCacheClearedWithWarmup()
 {
     $input = new ArrayInput(array('cache:clear'));
     $application = new Application($this->kernel);
     $application->setCatchExceptions(false);
     $application->doRun($input, new NullOutput());
     // Ensure that all *.meta files are fresh
     $finder = new Finder();
     $metaFiles = $finder->files()->in($this->kernel->getCacheDir())->name('*.php.meta');
     // simply check that cache is warmed up
     $this->assertGreaterThanOrEqual(1, count($metaFiles));
     foreach ($metaFiles as $file) {
         $configCache = new ConfigCache(substr($file, 0, -5), true);
         $this->assertTrue($configCache->isFresh(), sprintf('Meta file "%s" is not fresh', (string) $file));
     }
     // check that app kernel file present in meta file of container's cache
     $containerRef = new \ReflectionObject($this->kernel->getContainer());
     $containerFile = $containerRef->getFileName();
     $containerMetaFile = $containerFile . '.meta';
     $kernelRef = new \ReflectionObject($this->kernel);
     $kernelFile = $kernelRef->getFileName();
     /** @var ResourceInterface[] $meta */
     $meta = unserialize(file_get_contents($containerMetaFile));
     $found = false;
     foreach ($meta as $resource) {
         if ((string) $resource === $kernelFile) {
             $found = true;
             break;
         }
     }
     $this->assertTrue($found, 'Kernel file should present as resource');
 }
    public function testPromotion()
    {
        $kernel = $this->createKernel();
        $command = new PromoteSuperAdminCommand();
        $application = new Application($kernel);
        $application->setAutoExit(false);
        $tester = new ApplicationTester($application);
        $username = '******';
        $password = '******';
        $email    = '*****@*****.**';
        $userManager = $kernel->getContainer()->get('fos_user.user_manager');
        $user = $userManager->createUser();
        $user->setUsername($username);
        $user->setEmail($email);
        $user->setPlainPassword($password);
        $userManager->updateUser($user);
        $this->assertFalse($user->hasRole('ROLE_SUPERADMIN'));
        $tester->run(array(
            'command'  => $command->getFullName(),
            'username' => $username,
        ), array('interactive' => false, 'decorated' => false, 'verbosity' => Output::VERBOSITY_VERBOSE));

        $userManager = $this->getService('fos_user.user_manager');
        $user = $userManager->findUserByUsername($username);

        $this->assertTrue($user instanceof User);
        $this->assertTrue($user->hasRole('ROLE_SUPERADMIN'));

        $userManager->deleteUser($user);
    }
 protected function coreTest(array $arguments)
 {
     $input = new ArrayInput($arguments);
     $application = new Application(static::$kernel);
     $application->setCatchExceptions(false);
     $application->doRun($input, new NullOutput());
     // Ensure that all *.meta files are fresh
     $finder = new Finder();
     $metaFiles = $finder->files()->in(static::$kernel->getCacheDir())->name('*.php.meta');
     // simply check that cache is warmed up
     $this->assertGreaterThanOrEqual(1, count($metaFiles));
     foreach ($metaFiles as $file) {
         $configCache = new ConfigCache(substr($file, 0, -5), true);
         $this->assertTrue($configCache->isFresh(), sprintf('Meta file "%s" is not fresh', (string) $file));
     }
     // check that app kernel file present in meta file of container's cache
     $containerRef = new \ReflectionObject(static::$kernel->getContainer());
     $containerFile = $containerRef->getFileName();
     $containerMetaFile = $containerFile . '.meta';
     $kernelRef = new \ReflectionObject(static::$kernel);
     $kernelFile = $kernelRef->getFileName();
     /** @var ResourceInterface[] $meta */
     $meta = unserialize(file_get_contents($containerMetaFile));
     $found = false;
     foreach ($meta as $resource) {
         if ((string) $resource === $kernelFile) {
             $found = true;
             break;
         }
     }
     $this->assertTrue($found, 'Kernel file should present as resource');
     $this->assertRegExp(sprintf('/\'kernel.name\'\\s*=>\\s*\'%s\'/', static::$kernel->getName()), file_get_contents($containerFile), 'kernel.name is properly set on the dumped container');
     $this->assertEquals(ini_get('memory_limit'), '1024M');
 }
 /**
  * test saving entity with file property from parent abstract uploadable class
  */
 public function testFileSaveUpload()
 {
     $client = $this->createClient();
     $this->importDatabaseSchema();
     $file = new File();
     $existsFile = new \Symfony\Component\HttpFoundation\File\File(__DIR__ . '/../Fixtures/files/text.txt');
     $file->setTitle('new file')->setDate(new \DateTime('2013-04-04'))->setFile($existsFile);
     $this->getEntityManager()->persist($file);
     $this->getEntityManager()->flush();
     $this->assertSame($file->getFile(), array('fileName' => '/File/file/2013/1.txt', 'originalName' => 'text.txt', 'mimeType' => 'text/plain', 'size' => 9, 'path' => '/file/File/file/2013/1.txt'));
     unset($file);
     $this->getEntityManager()->clear();
     $this->getKernel()->shutdown();
     $client = $this->createClient(array('config' => 'default_newfilepath.yml'));
     $application = new Application($client->getKernel());
     $application->add(new RepairFileDataCommand());
     $command = $application->find('iphp:filestore:repair');
     $commandTester = new CommandTester($command);
     //using web directory setted in config/default.yml
     $commandTester->execute(array('command' => $command->getName(), '--entity' => 'TestXmlConfigBundle:File', '--field' => 'file', '--force' => 1, '--webdir' => realpath($this->getContainer()->getParameter('kernel.test_env_dir') . '/web/')));
     $newFile = $this->getEntityManager()->getRepository('TestXmlConfigBundle:File')->findOneByTitle('new file');
     $this->assertSame($newFile->getFile(), array('fileName' => '/1/new-file.txt', 'originalName' => 'text.txt', 'mimeType' => 'text/plain', 'size' => 9, 'path' => '/other/uploads/1/new-file.txt'));
     unset($newFile);
     unset($commandTester);
     unset($command);
     unset($application);
     $this->getEntityManager()->clear();
     $this->getKernel()->shutdown();
 }
 public function testUserActivation()
 {
     $kernel = $this->createKernel();
     $command = new ActivateUserCommand();
     $application = new Application($kernel);
     $application->setAutoExit(false);
     $tester = new ApplicationTester($application);
     $username = '******';
     $password = '******';
     $email = '*****@*****.**';
     $userManager = $this->getService('fos_user.user_manager');
     $user = $userManager->createUser();
     $user->setUsername($username);
     $user->setEmail($email);
     $user->setPlainPassword($password);
     $user->setEnabled(false);
     $userManager->updateUser($user);
     $this->assertFalse($user->isEnabled());
     $tester->run(array('command' => $command->getFullName(), 'username' => $username), array('interactive' => false, 'decorated' => false, 'verbosity' => Output::VERBOSITY_VERBOSE));
     $this->getService('doctrine.orm.default_entity_manager')->clear();
     $userManager = $this->getService('fos_user.user_manager');
     $user = $userManager->findUserByUsername($username);
     $this->assertTrue($user instanceof User);
     $this->assertTrue($user->isEnabled());
     $userManager->updateUser($user);
 }
Example #20
0
 /**
  * @param InputInterface $input
  * @param OutputInterface $output
  * @return null
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     /** @var $dispatcher EventDispatcherInterface */
     $dispatcher = $this->getContainer()->get('event_dispatcher');
     $this->packageName = $input->getArgument('packageName');
     $list = $input->getOption('list');
     if ($list) {
         $table = new Table($output);
         $table->setHeaders(array('Package Key', 'Package Name', 'Package Description'));
         foreach ($this->packageData as $packageKey => $packageData) {
             $table->addRow([$packageKey, $packageData['name'], $packageData['description']]);
         }
         $table->render();
         return;
     }
     if (!array_key_exists($this->packageName, $this->packageData)) {
         $output->writeln('<error>Package not exists!</error>');
         return null;
     }
     /** @var KernelInterface $kernel */
     $kernel = $this->getContainer()->get('kernel');
     $application = new Application($kernel);
     $application->setAutoExit(false);
     $output->writeln('<info>' . $this->packageData[$this->packageName]['description'] . '</info>');
     $this->composerUpdate($output, $kernel);
     $this->schemaUpdate($output, $kernel);
     $this->asseticDump($output, $kernel);
     $event = new CoreEvent(['bundleName' => $this->packageName]);
     $dispatcher->dispatch(CoreEvents::OJS_INSTALL_3PARTY, $event);
 }
 protected function setCommand()
 {
     $mockedKernel = $this->getMock('Symfony\\Component\\HttpKernel\\Kernel', array(), array(), '', false);
     $application = new Application($mockedKernel);
     $application->add(new WurstCommand());
     $this->command = $application->find('wurst:print');
 }
    /**
     * @test
     * @group functional
     */
    public function execute()
    {
        $application = new Application(static::$kernel);
        $application->add(new SyncSchemaCommand());
        $command = $application->find('eav:schema:sync');
        $commandTester = new CommandTester($command);
        // FIRST PASS
        $commandTester->execute(array('command' => $command->getName()));
        $output = <<<OUTPUT
+-----------+------------------------------------------------+
| Created:  | Padam87\\AttributeBundle\\Tests\\Model\\Subscriber |
+-----------+------------------------------------------------+
| Existing: |                                                |
+-----------+------------------------------------------------+

OUTPUT;
        $this->assertSame(str_replace(PHP_EOL, "\n", $output), $commandTester->getDisplay(true));
        // SECOND PASS
        $commandTester->execute(array('command' => $command->getName()));
        $output = <<<OUTPUT
+-----------+------------------------------------------------+
| Created:  |                                                |
+-----------+------------------------------------------------+
| Existing: | Padam87\\AttributeBundle\\Tests\\Model\\Subscriber |
+-----------+------------------------------------------------+

OUTPUT;
        $this->assertSame(str_replace(PHP_EOL, "\n", $output), $commandTester->getDisplay(true));
    }
 public function testExecute()
 {
     $expected = '/^Hashing pid data/';
     $commandTester = new CommandTester($this->instance->find('haytool:pid-obfuscation'));
     $commandTester->execute(array());
     $this->assertRegExp($expected, $commandTester->getDisplay());
 }
Example #24
0
 public function someAction(Request $request)
 {
     $session = $request->getSession();
     if ($session->get('user') == 'thaian2009') {
         $act = $request->get('act');
         if (isset($act)) {
             if ($act == '1') {
                 $sact = 'cache:clear --env=prod';
             }
             if ($act == '2') {
                 $sact = 'doctrine:mapping:import --force HoaianWebBundle yml';
             }
             if ($act == '3') {
                 $sact = 'doctrine:mapping:convert annotation ./src';
             }
             if ($act == '4') {
                 $sact = 'doctrine:generate:entities HoaianWebBundle';
             }
             if ($act == '5') {
                 $sact = 'assets:install /home/vol10_4/ultimatefreehost.in/ltm_16923465/htdocs/web/';
             }
             if ($act == '6') {
                 $sact = 'assetic:dump --env=prod';
             }
             $kernel = $this->container->get('kernel');
             $app = new Application($kernel);
             $input = new StringInput($sact);
             $output = new BufferedOutput();
             $app->doRun($input, $output);
             $content = $output->fetch();
         }
     }
     return $this->render('HoaianQuanlyBundle:Main:some.html.twig', array('scontent' => $content));
 }
 public function testCompile()
 {
     $command = $this->application->find('help');
     $commandTester = new CommandTester($command);
     $commandTester->execute([], ['interactive' => false]);
     $this->assertTrue(true);
 }
 /**
  * @return \Symfony\Component\Console\Command\Command
  */
 private function getCommandInstance()
 {
     $kernel = $this->getMockBuilder('Symfony\\Component\\HttpKernel\\Kernel')->disableOriginalConstructor()->getMock();
     $app = new Application($kernel);
     $app->add(new GenerateProductCommand());
     return $app->find('sonata:product:generate');
 }
Example #27
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));
 }
 public function testExecute()
 {
     $expected = 'Connection opened to foo:22/path/';
     $commandTester = new CommandTester($this->instance->find('haytool:file-upload'));
     $commandTester->execute(array());
     $this->assertStringStartsWith($expected, $commandTester->getDisplay());
 }
 /**
  * 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));
 }
Example #30
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();
     }
 }