Bladeren bron

[Routing] Added YamlFileLoader tests.

Jakub Zalas 14 jaren geleden
bovenliggende
commit
4244ae7794

+ 2 - 0
tests/Symfony/Tests/Component/Routing/Fixtures/incomplete.yml

@@ -0,0 +1,2 @@
+blog_show:
+    defaults:  { _controller: MyBlogBundle:Blog:show }

+ 4 - 0
tests/Symfony/Tests/Component/Routing/Fixtures/validpattern.yml

@@ -0,0 +1,4 @@
+blog_show:
+    pattern:   /blog/{slug}
+    defaults:  { _controller: MyBlogBundle:Blog:show }
+

+ 2 - 0
tests/Symfony/Tests/Component/Routing/Fixtures/validresource.yml

@@ -0,0 +1,2 @@
+blog_show:
+    resource: validpattern.yml

+ 29 - 0
tests/Symfony/Tests/Component/Routing/Loader/YamlFileLoaderTest.php

@@ -60,4 +60,33 @@ class YamlFileLoaderTest extends \PHPUnit_Framework_TestCase
         $loader = new YamlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures')));
         $loader->load('nonvalidkeys.yml');
     }
+
+    /**
+     * @expectedException \InvalidArgumentException
+     */
+    public function testLoadThrowsExceptionWhenIncomplete()
+    {
+        $loader = new YamlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures')));
+        $loader->load('incomplete.yml');
+    }
+
+    public function testLoadWithPattern()
+    {
+        $loader = new YamlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures')));
+        $routeCollection = $loader->load('validpattern.yml');
+        $routes = $routeCollection->all();
+
+        $this->assertEquals(1, count($routes), 'One route is loaded');
+        $this->assertContainsOnly('Symfony\Component\Routing\Route', $routes);
+    }
+
+    public function testLoadWithResource()
+    {
+        $loader = new YamlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures')));
+        $routeCollection = $loader->load('validresource.yml');
+        $routes = $routeCollection->all();
+
+        $this->assertEquals(1, count($routes), 'One route is loaded');
+        $this->assertContainsOnly('Symfony\Component\Routing\Route', $routes);
+    }
 }