/**
  * {@inheritDoc}
  */
 public function setUp()
 {
     self::bootKernel();
     $this->container = static::$kernel->getContainer();
     $this->application = new Application(static::$kernel);
     $this->application->setAutoExit(false);
     $this->application->setCatchExceptions(false);
 }
 /**
  * @before
  */
 public function setupSubject()
 {
     $this->supervisorManager = $this->getMockBuilder('YZ\\SupervisorBundle\\Manager\\SupervisorManager')->disableOriginalConstructor()->getMock();
     self::bootKernel();
     static::$kernel->getContainer()->set('supervisor.manager', $this->supervisorManager);
     $this->application = new Application(static::$kernel);
     $this->application->setAutoExit(false);
     $this->application->setCatchExceptions(false);
 }
 /**
  * {@inheritDoc}
  */
 public function setUp()
 {
     self::bootKernel();
     $this->container = static::$kernel->getContainer();
     $this->application = new Application(static::$kernel);
     $this->application->setAutoExit(false);
     $this->application->setCatchExceptions(false);
     $this->function_exists = $this->getFunctionMock('Abc\\ProcessControl', 'function_exists');
 }
 /**
  * @return Application
  */
 protected static function getApplication()
 {
     if (null === self::$application) {
         $client = static::createClient();
         self::$application = new Application($client->getKernel());
         self::$application->setAutoExit(false);
         self::$application->setCatchExceptions(false);
     }
     return self::$application;
 }
 /**
  * {@inheritDoc}
  */
 public function setUp()
 {
     self::bootKernel();
     $this->em = static::$kernel->getContainer()->get('doctrine')->getManager();
     $this->container = static::$kernel->getContainer();
     $this->application = new Application(static::$kernel);
     $this->application->setAutoExit(false);
     $this->application->setCatchExceptions(false);
     $this->runConsole("doctrine:schema:drop", array("--force" => true));
     $this->runConsole("doctrine:schema:update", array("--force" => true));
 }
 /**
  * {@inheritDoc}
  */
 public function setUp()
 {
     self::bootKernel();
     $this->container = static::$kernel->getContainer();
     $this->application = new Application(static::$kernel);
     $this->application->setAutoExit(false);
     $this->application->setCatchExceptions(false);
     $this->metadataFactory = $this->container->get('abc.job.metadata_factory');
     /** @var ClassMetadata $classMetadata */
     $this->classMetadata = $this->metadataFactory->getMetadataForClass(AnnotatedJob::class)->getRootClassMetadata();
 }
 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;
         }
     }
 }
 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');
 }
Example #9
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');
 }
 /**
  * {@inheritDoc}
  */
 public function setUp()
 {
     self::bootKernel($this->kernelOptions);
     $this->em = static::$kernel->getContainer()->get('doctrine')->getManager();
     $this->application = new Application(static::$kernel);
     $this->application->setAutoExit(false);
     $this->application->setCatchExceptions(false);
     if (count($this->entityManagerNames) > 0) {
         foreach ($this->entityManagerNames as $name) {
             $this->runConsole("doctrine:schema:drop", ['--force' => true, '--em' => $name]);
             $this->runConsole("doctrine:schema:update", ['--force' => true, '--em' => $name]);
         }
     } else {
         $this->runConsole("doctrine:schema:drop", array("--force" => true));
         $this->runConsole("doctrine:schema:update", array("--force" => true));
     }
 }
Example #11
0
 public function testExecute()
 {
     self::bootKernel();
     $application = new Application(static::$kernel);
     $application->setCatchExceptions(false);
     $application->setAutoExit(false);
     $tester = new ApplicationTester($application);
     $tester->run(['command' => 'api:swagger:export']);
     $this->assertJson($tester->getDisplay());
 }
 public function testBundleCommandsHaveRightContainer()
 {
     $command = $this->getMockForAbstractClass('Symfony\\Bundle\\FrameworkBundle\\Command\\ContainerAwareCommand', array('foo'), '', true, true, true, array('setContainer'));
     $command->setCode(function () {
     });
     $command->expects($this->exactly(2))->method('setContainer');
     $application = new Application($this->getKernel(array()));
     $application->setAutoExit(false);
     $application->setCatchExceptions(false);
     $application->add($command);
     $tester = new ApplicationTester($application);
     // set container is called here
     $tester->run(array('command' => 'foo'));
     // as the container might have change between two runs, setContainer must called again
     $tester->run(array('command' => 'foo'));
 }
 /**
  * @dataProvider provideTestCommand
  *
  * @param $command
  * @param $reportFile
  */
 public function testCommand($command, $arguments, $reportFile, $inputStream = null)
 {
     $client = static::createClient();
     $application = new Application($client->getKernel());
     $application->setCatchExceptions(false);
     $output = new BufferedOutput();
     $application->setAutoExit(false);
     if ($inputStream) {
         $application->getHelperSet()->get('dialog')->setInputStream($this->getInputStream($inputStream));
     }
     //We push a empty argument that is ignore by the application and we push the command itself
     array_unshift($arguments, null, $command);
     $application->run(new ArgvInput($arguments), $output);
     if ($this->dev) {
         file_put_contents($reportFile, $this->report($application));
     }
     $this->assertStringEqualsFile($reportFile, $this->report($application));
 }
Example #14
0
 /**
  * Runs a command and returns it output
  */
 public function runCommand(Client $client, $command, $exceptionOnExitCode = true)
 {
     $application = new Application($client->getKernel());
     $application->setAutoExit(false);
     $input = new StringInput($command);
     $output = new StreamOutput($fp = tmpfile());
     $application->setCatchExceptions(false);
     $return = $application->run($input, $output);
     fseek($fp, 0);
     $output = '';
     while (!feof($fp)) {
         $output .= fread($fp, 4096);
     }
     fclose($fp);
     if ($exceptionOnExitCode && $return !== 0) {
         throw new \RuntimeException(sprintf('Return code is not 0: %s', $output));
     }
     return $output;
 }
Example #15
0
 /**
  * Execute a symfony command.
  *
  * $this->executeCommand('sulu:security:user:create', array(
  *     'firstName' => 'foo',
  *     '--option' => 'bar',
  * ));
  *
  * @param string $command Command to execute
  * @param array  $args    Arguments and options
  *
  * @return int Exit code of command
  */
 protected function execCommand($command, $args)
 {
     $kernel = $this->kernel;
     array_unshift($args, $command);
     $input = new ArrayInput($args);
     $application = new Application($kernel);
     $application->all();
     $application->setAutoExit(false);
     $application->setCatchExceptions(false);
     $command = $application->find($command);
     $output = new StreamOutput(fopen('php://memory', 'w', false));
     $exitCode = $application->run($input, $output);
     if ($exitCode !== 0) {
         rewind($output->getStream());
         $output = stream_get_contents($output->getStream());
         throw new \Exception(sprintf('Command in BaseContext exited with code "%s": "%s"', $exitCode, $output));
     }
     return $exitCode;
 }
Example #16
0
 /**
  * @dataProvider viewProvider
  *
  * @param string $view                 Command view option value
  * @param array  $expectedMethodsCount Expected resource methods count
  * @param array  $expectedMethodValues Expected resource method values
  */
 public function testDumpWithViewOption($view, array $expectedMethodsCount, array $expectedMethodValues)
 {
     $this->getContainer();
     $application = new Application(static::$kernel);
     $application->setCatchExceptions(false);
     $application->setAutoExit(false);
     $tester = new ApplicationTester($application);
     $input = array('command' => 'api:doc:dump', '--view' => $view, '--format' => 'json');
     $tester->run($input);
     $display = $tester->getDisplay();
     $this->assertJson($display);
     $json = json_decode($display);
     $accessor = PropertyAccess::createPropertyAccessor();
     foreach ($expectedMethodsCount as $propertyPath => $expectedCount) {
         $this->assertCount($expectedCount, $accessor->getValue($json, $propertyPath));
     }
     foreach ($expectedMethodValues as $propertyPath => $expectedValue) {
         $this->assertEquals($expectedValue, $accessor->getValue($json, $propertyPath));
     }
 }