Преглед на файлове

[Routing] Added YamlFileLoader test verifying if pattern is required by parseRoute.

Jakub Zalas преди 14 години
родител
ревизия
6235f42cd5
променени са 1 файла, в които са добавени 29 реда и са изтрити 0 реда
  1. 29 0
      tests/Symfony/Tests/Component/Routing/Loader/YamlFileLoaderTest.php

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

@@ -89,4 +89,33 @@ class YamlFileLoaderTest extends \PHPUnit_Framework_TestCase
         $this->assertEquals(1, count($routes), 'One route is loaded');
         $this->assertContainsOnly('Symfony\Component\Routing\Route', $routes);
     }
+
+    /**
+     * @expectedException \InvalidArgumentException
+     */
+    public function testParseRouteThrowsExceptionWithMissingPattern()
+    {
+        $loader = new CustomYamlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures')));
+        $loader->load('incomplete.yml');
+    }
 }
+
+class CustomYamlFileLoader extends YamlFileLoader
+{
+    public function load($file, $type = null)
+    {
+        $path = $this->locator->locate($file);
+
+        $config = $this->loadFile($path);
+
+        $collection = new RouteCollection();
+        $collection->addResource(new FileResource($path));
+
+        foreach ($config as $name => $config) {
+            $this->parseRoute($collection, $name, $config, $path);
+        }
+
+        return $collection;
+    }
+}
+