Jelajahi Sumber

Merge remote branch 'pborreli/tests-fix-typos'

* pborreli/tests-fix-typos:
  Various typos
  [WebProfilerBundle] Fixed typo
  [WebProfilerBundle] Adding unit tests
Fabien Potencier 14 tahun lalu
induk
melakukan
d31c403bae
17 mengubah file dengan 249 tambahan dan 20 penghapusan
  1. 0 1
      src/Symfony/Bridge/Doctrine/Form/ChoiceList/EntityChoiceList.php
  2. 0 1
      src/Symfony/Bridge/Twig/TokenParser/TransTokenParser.php
  3. 3 3
      src/Symfony/Bundle/DoctrineBundle/DependencyInjection/Compiler/RegisterEventListenersAndSubscribersPass.php
  4. 0 1
      src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/RegisterKernelListenersPass.php
  5. 0 1
      src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php
  6. 0 2
      src/Symfony/Bundle/FrameworkBundle/Profiler/ProfilerListener.php
  7. 0 1
      src/Symfony/Bundle/FrameworkBundle/Test/WebTestCase.php
  8. 1 1
      src/Symfony/Bundle/FrameworkBundle/Tests/Templating/PhpEngineTest.php
  9. 0 1
      src/Symfony/Bundle/SecurityBundle/DependencyInjection/SecurityExtension.php
  10. 1 4
      src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/TwigExtensionTest.php
  11. 1 1
      src/Symfony/Bundle/WebProfilerBundle/Controller/ProfilerController.php
  12. 75 0
      src/Symfony/Bundle/WebProfilerBundle/Tests/Controller/ExceptionControllerTest.php
  13. 40 0
      src/Symfony/Bundle/WebProfilerBundle/Tests/DependencyInjection/ConfigurationTest.php
  14. 127 0
      src/Symfony/Bundle/WebProfilerBundle/Tests/DependencyInjection/WebProfilerExtensionTest.php
  15. 1 1
      src/Symfony/Component/DependencyInjection/Compiler/CheckDefinitionValidityPass.php
  16. 0 1
      src/Symfony/Component/HttpFoundation/SessionStorage/PdoSessionStorage.php
  17. 0 1
      src/Symfony/Component/HttpKernel/Profiler/PdoProfilerStorage.php

+ 0 - 1
src/Symfony/Bridge/Doctrine/Form/ChoiceList/EntityChoiceList.php

@@ -143,7 +143,6 @@ class EntityChoiceList extends ArrayChoiceList
             $entities = $this->em->getRepository($this->class)->findAll();
         }
 
-        $propertyPath = null;
         $this->choices = array();
         $this->entities = array();
 

+ 0 - 1
src/Symfony/Bridge/Twig/TokenParser/TransTokenParser.php

@@ -32,7 +32,6 @@ class TransTokenParser extends \Twig_TokenParser
         $lineno = $token->getLine();
         $stream = $this->parser->getStream();
 
-        $body = null;
         $vars = new \Twig_Node_Expression_Array(array(), $lineno);
         $domain = new \Twig_Node_Expression_Constant('messages', $lineno);
         if (!$stream->test(\Twig_Token::BLOCK_END_TYPE)) {

+ 3 - 3
src/Symfony/Bundle/DoctrineBundle/DependencyInjection/Compiler/RegisterEventListenersAndSubscribersPass.php

@@ -40,7 +40,7 @@ class RegisterEventListenersAndSubscribersPass implements CompilerPassInterface
         }
 
         foreach ($connections as $name) {
-            $this->getEventManager($name)->addMethodCall('addEventSubscriber', array(new Reference($subscriberId)));
+            $this->getEventManager($name, $subscriberId)->addMethodCall('addEventSubscriber', array(new Reference($subscriberId)));
         }
     }
 
@@ -67,14 +67,14 @@ class RegisterEventListenersAndSubscribersPass implements CompilerPassInterface
         }
 
         foreach ($connections as $name => $events) {
-            $this->getEventManager($name)->addMethodCall('addEventListener', array(
+            $this->getEventManager($name, $listenerId)->addMethodCall('addEventListener', array(
                 array_unique($events),
                 new Reference($listenerId),
             ));
         }
     }
 
-    private function getEventManager($name)
+    private function getEventManager($name, $listenerId = null)
     {
         if (null === $this->eventManagers) {
             $this->eventManagers = array();

+ 0 - 1
src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/RegisterKernelListenersPass.php

@@ -23,7 +23,6 @@ class RegisterKernelListenersPass implements CompilerPassInterface
             return;
         }
 
-        $listeners = array();
         $definition = $container->getDefinition('event_dispatcher');
 
         foreach ($container->findTaggedServiceIds('kernel.listener') as $id => $events) {

+ 0 - 1
src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php

@@ -445,7 +445,6 @@ class FrameworkExtension extends Extension
             }
 
             // Register translation resources
-            $resources = array();
             if ($dirs) {
                 $finder = new Finder();
                 $finder->files()->filter(function (\SplFileInfo $file) { return 2 === substr_count($file->getBasename(), '.'); })->in($dirs);

+ 0 - 2
src/Symfony/Bundle/FrameworkBundle/Profiler/ProfilerListener.php

@@ -82,8 +82,6 @@ class ProfilerListener
      */
     public function onCoreResponse(FilterResponseEvent $event)
     {
-        $response = $event->getResponse();
-
         if ($this->onlyMasterRequests && HttpKernelInterface::MASTER_REQUEST !== $event->getRequestType()) {
             return;
         }

+ 0 - 1
src/Symfony/Bundle/FrameworkBundle/Test/WebTestCase.php

@@ -55,7 +55,6 @@ abstract class WebTestCase extends BaseWebTestCase
      */
     protected function getPhpUnitXmlDir()
     {
-        $dir = null;
         if (!isset($_SERVER['argv']) || false === strpos($_SERVER['argv'][0], 'phpunit')) {
             throw new \RuntimeException('You must override the WebTestCase::createKernel() method.');
         }

+ 1 - 1
src/Symfony/Bundle/FrameworkBundle/Tests/Templating/PhpEngineTest.php

@@ -35,7 +35,7 @@ class PhpEngineTest extends TestCase
     {
         $container = new Container();
         $loader = $this->getMockForAbstractClass('Symfony\Component\Templating\Loader\Loader');
-        $engine = new PhpEngine(new TemplateNameParser(), $container, $loader, $app = new GlobalVariables($container));
+        $engine = new PhpEngine(new TemplateNameParser(), $container, $loader, new GlobalVariables($container));
 
         $container->set('request', null);
 

+ 0 - 1
src/Symfony/Bundle/SecurityBundle/DependencyInjection/SecurityExtension.php

@@ -244,7 +244,6 @@ class SecurityExtension extends Extension
 
         // Register listeners
         $listeners = array();
-        $providers = array();
 
         // Channel listener
         $listeners[] = new Reference('security.channel_listener');

+ 1 - 4
src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/TwigExtensionTest.php

@@ -23,10 +23,7 @@ use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
 
 class TwigExtensionTest extends TestCase
 {
-    /**
-     * @dataProvider getFormats
-     */
-    public function testLoadEmptyConfiguration($format)
+    public function testLoadEmptyConfiguration()
     {
         $container = $this->createContainer();
         $container->registerExtension(new TwigExtension());

+ 1 - 1
src/Symfony/Bundle/WebProfilerBundle/Controller/ProfilerController.php

@@ -208,7 +208,7 @@ class ProfilerController extends ContainerAware
         $profiler = $this->container->get('profiler');
         $profiler->disable();
 
-        $pofiler = $profiler->loadFromToken($token);
+        $profiler = $profiler->loadFromToken($token);
 
         $ip    = $this->container->get('request')->query->get('ip');
         $url   = $this->container->get('request')->query->get('url');

+ 75 - 0
src/Symfony/Bundle/WebProfilerBundle/Tests/Controller/ExceptionControllerTest.php

@@ -0,0 +1,75 @@
+<?php
+
+/*
+ * This file is part of the Symfony framework.
+ *
+ * (c) Fabien Potencier <fabien@symfony.com>
+ *
+ * This source file is subject to the MIT license that is bundled
+ * with this source code in the file LICENSE.
+ */
+
+namespace Symfony\Bundle\WebProfilerBundle\Tests\Controller;
+
+use Symfony\Bundle\WebProfilerBundle\Controller\ExceptionController;
+use Symfony\Component\DependencyInjection\ContainerBuilder;
+use Symfony\Component\DependencyInjection\Reference;
+use Symfony\Component\DependencyInjection\Scope;
+use Symfony\Component\DependencyInjection\Definition;
+
+class ExceptionControllerTest extends \PHPUnit_Framework_TestCase
+{
+    protected $controller;
+    protected $container;
+    protected $flatten;
+    protected $kernel;
+
+    protected function setUp()
+    {
+        $this->flatten = $this->getMock('Symfony\Component\HttpKernel\Exception\FlattenException');
+        $this->flatten->expects($this->once())->method('getStatusCode')->will($this->returnValue(404));
+        $this->controller = new ExceptionController();
+        $this->kernel = $this->getMock('Symfony\\Component\\HttpKernel\\KernelInterface');
+        $this->container = $this->getContainer();
+    }
+
+    /**
+     * @dataProvider getDebugModes
+     */
+    public function testShowActionDependingOnDebug($debug)
+    {
+        $this->container->setParameter('kernel.debug', $debug);
+        $this->controller->setContainer($this->container);
+        $this->controller->showAction($this->flatten);
+    }
+
+    public function getDebugModes()
+    {
+        return array(
+            array(true),
+            array(false),
+        );
+    }
+
+    private function getContainer()
+    {
+        $container = new ContainerBuilder();
+        $container->addScope(new Scope('request'));
+        $container->register('request', 'Symfony\\Component\\HttpFoundation\\Request')->setScope('request');
+        $container->register('templating.helper.assets', $this->getMockClass('Symfony\\Component\\Templating\\Helper\\AssetsHelper'));
+        $container->register('templating.helper.router', $this->getMockClass('Symfony\\Bundle\\FrameworkBundle\\Templating\\Helper\\RouterHelper'))
+            ->addArgument(new Definition($this->getMockClass('Symfony\\Component\\Routing\\RouterInterface')));
+        $container->register('twig', 'Twig_Environment');
+        $container->register('templating.engine.twig',$this->getMockClass('Symfony\\Bundle\\TwigBundle\\TwigEngine'))
+            ->addArgument($this->getMock('Twig_Environment'))
+            ->addArgument($this->getMock('Symfony\\Component\\Templating\\TemplateNameParserInterface'))
+            ->addArgument($this->getMock('Symfony\\Bundle\\FrameworkBundle\\Templating\\GlobalVariables', array(), array($this->getMock('Symfony\\Component\\DependencyInjection\\Container'))));
+        $container->setAlias('templating', 'templating.engine.twig');
+        $container->setParameter('kernel.bundles', array());
+        $container->setParameter('kernel.cache_dir', __DIR__);
+        $container->setParameter('kernel.root_dir', __DIR__);
+        $container->set('kernel', $this->kernel);
+
+        return $container;
+    }
+}

+ 40 - 0
src/Symfony/Bundle/WebProfilerBundle/Tests/DependencyInjection/ConfigurationTest.php

@@ -0,0 +1,40 @@
+<?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\Configuration;
+use Symfony\Component\Config\Definition\Processor;
+
+class ConfigurationTest extends \PHPUnit_Framework_TestCase
+{
+    /**
+     * @dataProvider getDebugModes
+     */
+    public function testConfigTree($options, $results)
+    {
+        $processor = new Processor();
+        $configuration = new Configuration(array());
+        $config = $processor->processConfiguration($configuration, array($options));
+
+        $this->assertEquals($results, $config);
+    }
+    public function getDebugModes()
+    {
+        return array(
+            array(array(), array('intercept_redirects' => false, 'toolbar' => false, 'verbose' => true)),
+            array(array('intercept_redirects' => true), array('intercept_redirects' => true, 'toolbar' => false, 'verbose' => true)),
+            array(array('intercept_redirects' => false), array('intercept_redirects' => false, 'toolbar' => false, 'verbose' => true)),
+            array(array('toolbar' => true), array('intercept_redirects' => false, 'toolbar' => true, 'verbose' => true)),
+            array(array('verbose' => false), array('intercept_redirects' => false, 'toolbar' => false, 'verbose' => false)),
+        );
+    }
+}

+ 127 - 0
src/Symfony/Bundle/WebProfilerBundle/Tests/DependencyInjection/WebProfilerExtensionTest.php

@@ -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;
+    }
+}

+ 1 - 1
src/Symfony/Component/DependencyInjection/Compiler/CheckDefinitionValidityPass.php

@@ -10,7 +10,7 @@ use Symfony\Component\DependencyInjection\ContainerBuilder;
  * into account which is contained in the definition itself.
  *
  * Later passes can rely on the following, and specifically do not need to
- * perform these checks themself:
+ * perform these checks themselves:
  *
  * - non synthetic, non abstract services always have a class set
  * - synthetic services are always public

+ 0 - 1
src/Symfony/Component/HttpFoundation/SessionStorage/PdoSessionStorage.php

@@ -166,7 +166,6 @@ class PdoSessionStorage extends NativeSessionStorage
         $dbTable    = $this->dbOptions['db_table'];
         $dbDataCol = $this->dbOptions['db_data_col'];
         $dbIdCol   = $this->dbOptions['db_id_col'];
-        $dbTimeCol = $this->dbOptions['db_time_col'];
 
         try {
             $sql = 'SELECT '.$dbDataCol.' FROM '.$dbTable.' WHERE '.$dbIdCol.'=?';

+ 0 - 1
src/Symfony/Component/HttpKernel/Profiler/PdoProfilerStorage.php

@@ -180,7 +180,6 @@ abstract class PdoProfilerStorage implements ProfilerStorageInterface
 
     protected function fetch($db, $query, array $args = array())
     {
-        $return = array();
         $stmt = $this->prepareStatement($db, $query);
 
         foreach ($args as $arg => $val) {