ソースを参照

[FrameworkBundle] added some unit tests

Fabien Potencier 14 年 前
コミット
e84c867336

+ 6 - 3
src/Symfony/Bundle/FrameworkBundle/Tests/Controller/ControllerNameConverterTest.php

@@ -27,7 +27,8 @@ class ControllerNameConverterTest extends TestCase
         $kernel->boot();
         $converter = new ControllerNameConverter($kernel);
 
-        $this->assertEquals('FooBundle:Foo:index', $converter->toShortNotation('Symfony\Bundle\FooBundle\Controller\FooController::indexAction'), '->toShortNotation() converts a class::method string to the short a:b:c notation');
+        $this->assertEquals('FooBundle:Default:index', $converter->toShortNotation('TestBundle\FooBundle\Controller\DefaultController::indexAction'), '->toShortNotation() converts a class::method string to the short a:b:c notation');
+        $this->assertEquals('Sensio\\FooBundle:Default:index', $converter->toShortNotation('TestBundle\Sensio\FooBundle\Controller\DefaultController::indexAction'), '->toShortNotation() converts a class::method string to the short a:b:c notation');
 
         try {
             $converter->toShortNotation('foo');
@@ -65,7 +66,9 @@ class ControllerNameConverterTest extends TestCase
         $logger = new Logger();
         $converter = new ControllerNameConverter($kernel, $logger);
 
-        $this->assertEquals('Symfony\Bundle\FrameworkBundle\Controller\DefaultController::indexAction', $converter->fromShortNotation('FrameworkBundle:Default:index'), '->fromShortNotation() converts a short a:b:c notation string to a class::method string');
+        $this->assertEquals('TestBundle\FooBundle\Controller\DefaultController::indexAction', $converter->fromShortNotation('FooBundle:Default:index'), '->fromShortNotation() converts a short a:b:c notation string to a class::method string');
+        $this->assertEquals('TestBundle\Sensio\FooBundle\Controller\DefaultController::indexAction', $converter->fromShortNotation('Sensio/FooBundle:Default:index'), '->fromShortNotation() converts a short a:b:c notation string to a class::method string');
+        $this->assertEquals('TestBundle\Sensio\FooBundle\Controller\DefaultController::indexAction', $converter->fromShortNotation('Sensio\\FooBundle:Default:index'), '->fromShortNotation() converts a short a:b:c notation string to a class::method string');
 
         try {
             $converter->fromShortNotation('foo:');
@@ -75,7 +78,7 @@ class ControllerNameConverterTest extends TestCase
         }
 
         try {
-            $converter->fromShortNotation('FooBundle:Default:index');
+            $converter->fromShortNotation('BarBundle:Default:index');
             $this->fail('->fromShortNotation() throws a \InvalidArgumentException if the class is found but does not exist');
         } catch (\Exception $e) {
             $this->assertInstanceOf('\InvalidArgumentException', $e, '->fromShortNotation() throws a \LogicException if the class is found but does not exist');

+ 21 - 0
src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/TestBundle/FooBundle/Controller/DefaultController.php

@@ -0,0 +1,21 @@
+<?php
+
+namespace TestBundle\FooBundle\Controller;
+
+/*
+ * This file is part of the Symfony framework.
+ *
+ * (c) Fabien Potencier <fabien.potencier@symfony-project.com>
+ *
+ * This source file is subject to the MIT license that is bundled
+ * with this source code in the file LICENSE.
+ */
+
+/**
+ * DefaultController.
+ *
+ * @author Fabien Potencier <fabien.potencier@symfony-project.com>
+ */
+class DefaultController
+{
+}

+ 23 - 0
src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/TestBundle/FooBundle/FooBundle.php

@@ -0,0 +1,23 @@
+<?php
+
+namespace TestBundle\FooBundle;
+
+use Symfony\Component\HttpKernel\Bundle\Bundle;
+
+/*
+ * This file is part of the Symfony framework.
+ *
+ * (c) Fabien Potencier <fabien.potencier@symfony-project.com>
+ *
+ * This source file is subject to the MIT license that is bundled
+ * with this source code in the file LICENSE.
+ */
+
+/**
+ * Bundle.
+ *
+ * @author Fabien Potencier <fabien.potencier@symfony-project.com>
+ */
+class FooBundle extends Bundle
+{
+}

+ 21 - 0
src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/TestBundle/Sensio/FooBundle/Controller/DefaultController.php

@@ -0,0 +1,21 @@
+<?php
+
+namespace TestBundle\Sensio\FooBundle\Controller;
+
+/*
+ * This file is part of the Symfony framework.
+ *
+ * (c) Fabien Potencier <fabien.potencier@symfony-project.com>
+ *
+ * This source file is subject to the MIT license that is bundled
+ * with this source code in the file LICENSE.
+ */
+
+/**
+ * DefaultController.
+ *
+ * @author Fabien Potencier <fabien.potencier@symfony-project.com>
+ */
+class DefaultController
+{
+}

+ 23 - 0
src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/TestBundle/Sensio/FooBundle/SensioFooBundle.php

@@ -0,0 +1,23 @@
+<?php
+
+namespace TestBundle\Sensio\FooBundle;
+
+use Symfony\Component\HttpKernel\Bundle\Bundle;
+
+/*
+ * This file is part of the Symfony framework.
+ *
+ * (c) Fabien Potencier <fabien.potencier@symfony-project.com>
+ *
+ * This source file is subject to the MIT license that is bundled
+ * with this source code in the file LICENSE.
+ */
+
+/**
+ * Bundle.
+ *
+ * @author Fabien Potencier <fabien.potencier@symfony-project.com>
+ */
+class SensioFooBundle extends Bundle
+{
+}

+ 10 - 0
src/Symfony/Bundle/FrameworkBundle/Tests/Kernel.php

@@ -14,6 +14,7 @@ namespace Symfony\Bundle\FrameworkBundle\Tests;
 use Symfony\Component\HttpKernel\Kernel as BaseKernel;
 use Symfony\Component\DependencyInjection\Loader\LoaderInterface;
 use Symfony\Bundle\FrameworkBundle\Util\Filesystem;
+use Symfony\Component\HttpFoundation\UniversalClassLoader;
 
 class Kernel extends BaseKernel
 {
@@ -29,6 +30,12 @@ class Kernel extends BaseKernel
         }
 
         parent::__construct('env', true);
+
+        $loader = new UniversalClassLoader();
+        $loader->registerNamespaces(array(
+            'TestBundle' => __DIR__.'/Fixtures/',
+        ));
+        $loader->register();
     }
 
     public function __destruct()
@@ -46,6 +53,8 @@ class Kernel extends BaseKernel
     {
         return array(
             new \Symfony\Bundle\FrameworkBundle\FrameworkBundle(),
+            new \TestBundle\FooBundle\FooBundle(),
+            new \TestBundle\Sensio\FooBundle\SensioFooBundle(),
         );
     }
 
@@ -54,6 +63,7 @@ class Kernel extends BaseKernel
         return array(
             'Application'     => __DIR__.'/../src/Application',
             'Bundle'          => __DIR__.'/../src/Bundle',
+            'TestBundle'      => __DIR__.'/Fixtures/TestBundle',
             'Symfony\\Bundle' => __DIR__.'/../src/vendor/symfony/src/Symfony/Bundle',
         );
     }

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

@@ -32,6 +32,7 @@ class TemplateNameParserTest extends TestCase
             array('BlogBundle:Post:index.php.html', array('index', array('bundle' => 'BlogBundle', 'controller' => 'Post', 'renderer' => 'php', 'format' => 'html'))),
             array('BlogBundle:Post:index.twig.html', array('index', array('bundle' => 'BlogBundle', 'controller' => 'Post', 'renderer' => 'twig', 'format' => 'html'))),
             array('BlogBundle:Post:index.php.xml', array('index', array('bundle' => 'BlogBundle', 'controller' => 'Post', 'renderer' => 'php', 'format' => 'xml'))),
+            array('Sensio\\BlogBundle:Post:index.php.html', array('index', array('bundle' => 'Sensio/BlogBundle', 'controller' => 'Post', 'renderer' => 'php', 'format' => 'html'))),
         );
     }