/** * Creates a new container and application. */ protected function setUp() { $this->container = new ContainerBuilder(); $this->application = new Application($this->container); $this->container->setParameter(Application::getId('auto_exist'), false); $this->configDir = tempnam(sys_get_temp_dir(), 'box-'); unlink($this->configDir); mkdir($this->configDir); }
/** * Returns the container builder. * * @return ContainerBuilder The container builder. * * @throws CacheException If the cached configuration file does not exist. */ public function getContainerBuilder() { if (null === $this->file) { throw CacheException::fileNotExist($this->file); // @codeCoverageIgnore } $container = new ContainerBuilder(); $loader = new XmlFileLoader($container, new FileLocator()); $loader->load($this->file); $extensions = $container->findTaggedServiceIds(Application::getId('extension')); foreach ($extensions as $id => $tag) { $container->registerExtension($container->get($id)); } return $container; }
/** * Verifies that we can debug the service container. * * @covers \Box\Component\Console\Command\Debug\ContainerCommand * @covers \Box\Component\Console\Helper\ContainerHelper * * @runInSeparateProcess */ public function testCommand() { // create a new application $this->application = ApplicationCache::bootstrap($this->configDir . '/test.php'); // run the container debugger $this->runCommand(new ArrayInput(array('command' => 'debug:container')), $output); // verify that our service is listed $output = $this->readOutput($output); self::assertContains(Application::getId(), $output); // reload the application from the cache $this->application = ApplicationCache::bootstrap($this->configDir . '/test.php'); // reset the output variable $output = null; // run the container debugger again $this->runCommand(new ArrayInput(array('command' => 'debug:container')), $output); // verify that our service is still listed $output = $this->readOutput($output); self::assertContains(Application::getId(), $output); }
/** * {@inheritdoc} */ protected function register(ContainerBuilder $container, Definition $definition, $id, array $tag) { $container->getDefinition(Application::getId('helper_set'))->addMethodCall('set', array(new Reference($id))); }
/** * Verifies that we can run the application. */ public function testRun() { // registers a simple event listener $definition = new Definition(__CLASS__); $definition->addTag(Application::getId('event.subscriber')); $this->container->setDefinition('test_event', $definition); // register our own IO $input = new ArrayInput(array()); $output = new StreamOutput(fopen('php://memory', 'r+')); $this->container->set(Application::getId('input'), $input); $this->container->set(Application::getId('output'), $output); // compile the container ourselves $this->container->compile(); // make sure the exit status is returned self::assertEquals(0, $this->application->run()); // make sure it uses our output $output = $this->readOutput($output); self::assertContains('help', $output); // make sure that the event dispatcher is used self::assertContains('Event listened.', $output); // make sure the helper set is registered self::assertSame($this->container->get(Application::getId('helper_set')), $this->container->get(Application::getId())->getHelperSet()); // make sure the default helpers are registered self::assertNotNull($this->container->has(Application::getId('helper.formatter'))); // make sure the helpers are registered with the helper set $helperSet = $this->container->get(Application::getId('helper_set')); self::assertSame($this->container->get(Application::getId('helper.formatter')), $helperSet->get('formatter')); // make sure that the container helper is registered self::assertSame($this->container, $helperSet->get('container')->getContainer()); // make sure the default commands are registered self::assertNotNull($this->container->has(Application::getId('command.help'))); // make sure the commands are registered with the application. $command = $this->container->get(Application::getId('command.help')); self::assertSame($command, $this->container->get(Application::getId())->find($command->getName())); // make sure the commands use the helper set service self::assertSame($helperSet, $command->getHelperSet()); }