/** * Verifies that we can create and reload a cached container. * * @covers \Box\Component\Console\ApplicationCache * * @runInSeparateProcess */ public function testCache() { // create the test configuration file $file = $this->dir . '/test.yml'; file_put_contents($file, Yaml::dump(array('parameters' => array('box.console.name' => 'test name', 'box.console.version' => 'test version')))); $cache = $this->dir . '/new/cache.php'; // bootstrap the application $app = ApplicationCache::bootstrap($cache, function (ContainerBuilder $container) use($file) { $loader = new YamlFileLoader($container, new FileLocator()); $loader->load($file); }); // make sure a new container was created self::assertInstanceOf('Symfony\\Component\\DependencyInjection\\ContainerBuilder', $app->getContainer()); // make sure the configuration file was loaded $console = $app->getContainer()->get(ApplicationCache::getId()); self::assertEquals('test name', $console->getName()); self::assertEquals('test version', $console->getVersion()); // make sure the cache files were created self::assertFileExists($this->dir . '/new/cache.php'); self::assertFileExists($this->dir . '/new/cache.php.meta'); // change the cache file times so it isn't immediately treated as stale touch($this->dir . '/new/cache.php', filemtime($this->dir . '/new/cache.php') + 1); touch($this->dir . '/new/cache.php.meta', filemtime($this->dir . '/new/cache.php.meta') + 1); // bootstrap the application again $app = ApplicationCache::bootstrap($cache, function (ContainerBuilder $container) use($file) { $loader = new YamlFileLoader($container, new FileLocator()); $loader->load($file); }); // make sure that the cached container is used self::assertFalse($app->getContainer() instanceof ContainerBuilder); }
/** * 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); }