|
@@ -0,0 +1,127 @@
|
|
|
+<?php
|
|
|
+
|
|
|
+/*
|
|
|
+ * This file is part of the Symfony package.
|
|
|
+ *
|
|
|
+ * (c) Fabien Potencier <fabien@symfony.com>
|
|
|
+ *
|
|
|
+ * For the full copyright and license information, please view the LICENSE
|
|
|
+ * file that was distributed with this source code.
|
|
|
+ */
|
|
|
+
|
|
|
+namespace Symfony\Bundle\WebProfilerBundle\Tests\DependencyInjection;
|
|
|
+
|
|
|
+use Symfony\Bundle\WebProfilerBundle\DependencyInjection\WebProfilerExtension;
|
|
|
+use Symfony\Component\Config\FileLocator;
|
|
|
+use Symfony\Component\DependencyInjection\Container;
|
|
|
+use Symfony\Component\DependencyInjection\ContainerBuilder;
|
|
|
+use Symfony\Component\DependencyInjection\Definition;
|
|
|
+use Symfony\Component\DependencyInjection\Parameter;
|
|
|
+use Symfony\Component\DependencyInjection\Reference;
|
|
|
+use Symfony\Component\DependencyInjection\Loader\PhpFileLoader;
|
|
|
+use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
|
|
|
+use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
|
|
|
+use Symfony\Component\DependencyInjection\Dumper\PhpDumper;
|
|
|
+use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
|
|
|
+use Symfony\Component\DependencyInjection\Scope;
|
|
|
+
|
|
|
+class WebProfilerExtensionTest extends \PHPUnit_Framework_TestCase
|
|
|
+{
|
|
|
+ private $kernel;
|
|
|
+ /**
|
|
|
+ * @var Symfony\Component\DependencyInjection\Container $container
|
|
|
+ */
|
|
|
+ private $container;
|
|
|
+
|
|
|
+ static public function assertSaneContainer(Container $container, $message = '')
|
|
|
+ {
|
|
|
+ $errors = array();
|
|
|
+ foreach ($container->getServiceIds() as $id) {
|
|
|
+ try {
|
|
|
+ $container->get($id);
|
|
|
+ } catch (\Exception $e) {
|
|
|
+ $errors[$id] = $e->getMessage();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ self::assertEquals(array(), $errors, $message);
|
|
|
+ }
|
|
|
+
|
|
|
+ protected function setUp()
|
|
|
+ {
|
|
|
+
|
|
|
+ $this->kernel = $this->getMock('Symfony\\Component\\HttpKernel\\KernelInterface');
|
|
|
+
|
|
|
+ $this->container = new ContainerBuilder();
|
|
|
+ $this->container->addScope(new Scope('request'));
|
|
|
+ $this->container->register('request', 'Symfony\\Component\\HttpFoundation\\Request')->setScope('request');
|
|
|
+ $this->container->register('templating.helper.assets', $this->getMockClass('Symfony\\Component\\Templating\\Helper\\AssetsHelper'));
|
|
|
+ $this->container->register('templating.helper.router', $this->getMockClass('Symfony\\Bundle\\FrameworkBundle\\Templating\\Helper\\RouterHelper'))
|
|
|
+ ->addArgument(new Definition($this->getMockClass('Symfony\\Component\\Routing\\RouterInterface')));
|
|
|
+ $this->container->register('twig', 'Twig_Environment');
|
|
|
+ $this->container->register('templating.engine.twig', $this->getMockClass('Symfony\\Bundle\\TwigBundle\\TwigEngine'))
|
|
|
+ ->addArgument(new Definition($this->getMockClass('Twig_Environment')))
|
|
|
+ ->addArgument(new Definition($this->getMockClass('Symfony\\Component\\Templating\\TemplateNameParserInterface')))
|
|
|
+ ->addArgument(new Definition($this->getMockClass('Symfony\\Bundle\\FrameworkBundle\\Templating\\GlobalVariables'), array(new Definition($this->getMockClass('Symfony\\Component\\DependencyInjection\\Container')))));
|
|
|
+ $this->container->setParameter('kernel.bundles', array());
|
|
|
+ $this->container->setParameter('kernel.cache_dir', __DIR__);
|
|
|
+ $this->container->setParameter('kernel.debug', false);
|
|
|
+ $this->container->setParameter('kernel.root_dir', __DIR__);
|
|
|
+ $this->container->set('kernel', $this->kernel);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @dataProvider getDebugModes
|
|
|
+ */
|
|
|
+ public function testDefaultConfig($debug)
|
|
|
+ {
|
|
|
+ $this->container->setParameter('kernel.debug', $debug);
|
|
|
+
|
|
|
+ $extension = new WebProfilerExtension();
|
|
|
+ $extension->load(array(array()), $this->container);
|
|
|
+
|
|
|
+ $this->assertFalse($this->container->has('web_profiler.debug.toolbar'));
|
|
|
+
|
|
|
+ $this->assertSaneContainer($this->getDumpedContainer());
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @dataProvider getDebugModes
|
|
|
+ */
|
|
|
+ public function testToolbarConfig($debug)
|
|
|
+ {
|
|
|
+ $this->container->setParameter('kernel.debug', $debug);
|
|
|
+
|
|
|
+ $extension = new WebProfilerExtension();
|
|
|
+ $extension->load(array(array('toolbar' => $debug)), $this->container);
|
|
|
+
|
|
|
+ $this->assertTrue($debug === $this->container->has('web_profiler.debug.toolbar'), '->load() registers web_profiler.debug.toolbar only when toolbar is true');
|
|
|
+
|
|
|
+ $this->assertSaneContainer($this->getDumpedContainer());
|
|
|
+ }
|
|
|
+
|
|
|
+ public function getDebugModes()
|
|
|
+ {
|
|
|
+ return array(
|
|
|
+ array(true),
|
|
|
+ array(false),
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
+ private function getDumpedContainer()
|
|
|
+ {
|
|
|
+ static $i = 0;
|
|
|
+ $class = 'WebProfilerExtensionTestContainer'.$i++;
|
|
|
+
|
|
|
+ $this->container->compile();
|
|
|
+
|
|
|
+ $dumper = new PhpDumper($this->container);
|
|
|
+ eval('?>'.$dumper->dump(array('class' => $class)));
|
|
|
+
|
|
|
+ $container = new $class();
|
|
|
+ $container->enterScope('request');
|
|
|
+ $container->set('kernel', $this->kernel);
|
|
|
+
|
|
|
+ return $container;
|
|
|
+ }
|
|
|
+}
|