From 0a1cfcdb5f0f75ad8c69506879eb5b8c38436d35 Mon Sep 17 00:00:00 2001 From: Tobias Schultze Date: Fri, 7 Dec 2012 13:21:35 +0100 Subject: [PATCH] adjust RouteCollectionTest for the addCollection change and refactor the tests to only skip the part that really needs the config component --- .../Routing/Tests/RouteCollectionTest.php | 54 +++++++------------ 1 file changed, 20 insertions(+), 34 deletions(-) diff --git a/src/Symfony/Component/Routing/Tests/RouteCollectionTest.php b/src/Symfony/Component/Routing/Tests/RouteCollectionTest.php index 487a537a87..09748de0f3 100644 --- a/src/Symfony/Component/Routing/Tests/RouteCollectionTest.php +++ b/src/Symfony/Component/Routing/Tests/RouteCollectionTest.php @@ -82,32 +82,31 @@ class RouteCollectionTest extends \PHPUnit_Framework_TestCase } public function testAddCollection() + { + $collection = new RouteCollection(); + $collection->add('foo', new Route('/foo')); + + $collection1 = new RouteCollection(); + $collection1->add('bar', $bar = new Route('/bar')); + $collection1->add('foo', $foo = new Route('/foo-new')); + + $collection2 = new RouteCollection(); + $collection2->add('grandchild', $grandchild = new Route('/grandchild')); + + $collection1->addCollection($collection2); + $collection->addCollection($collection1); + $collection->add('last', $last = new Route('/last')); + + $this->assertSame(array('bar' => $bar, 'foo' => $foo, 'grandchild' => $grandchild, 'last' => $last), $collection->all(), + '->addCollection() imports routes of another collection, overrides if necessary and adds them at the end'); + } + + public function testAddCollectionWithResources() { if (!class_exists('Symfony\Component\Config\Resource\FileResource')) { $this->markTestSkipped('The "Config" component is not available'); } - $collection = new RouteCollection(); - $collection->add('foo', $foo = new Route('/foo')); - $collection1 = new RouteCollection(); - $collection1->add('foo', $foo1 = new Route('/foo1')); - $collection1->add('bar', $bar1 = new Route('/bar1')); - $collection->addCollection($collection1); - $this->assertEquals(array('foo' => $foo1, 'bar' => $bar1), $collection->all(), '->addCollection() adds routes from another collection'); - - $collection = new RouteCollection(); - $collection->add('foo', $foo = new Route('/foo')); - $collection1 = new RouteCollection(); - $collection1->add('foo', $foo1 = new Route('/foo1')); - $collection->addCollection($collection1, '/{foo}', array('foo' => 'foo'), array('foo' => '\d+'), array('foo' => 'bar')); - $this->assertEquals('/{foo}/foo1', $collection->get('foo')->getPath(), '->addCollection() can add a prefix to all merged routes'); - $this->assertEquals(array('foo' => 'foo'), $collection->get('foo')->getDefaults(), '->addCollection() can add a prefix to all merged routes'); - $this->assertEquals(array('foo' => '\d+'), $collection->get('foo')->getRequirements(), '->addCollection() can add a prefix to all merged routes'); - $this->assertEquals( - array('foo' => 'bar', 'compiler_class' => 'Symfony\\Component\\Routing\\RouteCompiler'), - $collection->get('foo')->getOptions(), '->addCollection() can add an option to all merged routes' - ); - $collection = new RouteCollection(); $collection->addResource($foo = new FileResource(__DIR__.'/Fixtures/foo.xml')); $collection1 = new RouteCollection(); @@ -150,19 +149,6 @@ class RouteCollectionTest extends \PHPUnit_Framework_TestCase $this->assertEquals('https', $collection->get('bar')->getRequirement('_scheme'), '->addPrefix() overrides existing requirements'); } - public function testAddCollectionOverridesDefaultsAndRequirements() - { - $imported = new RouteCollection(); - $imported->add('foo', $foo = new Route('/foo')); - $imported->add('bar', $bar = new Route('/bar', array(), array('_scheme' => 'http'))); - - $collection = new RouteCollection(); - $collection->addCollection($imported, null, array(), array('_scheme' => 'https')); - - $this->assertEquals('https', $collection->get('foo')->getRequirement('_scheme'), '->addCollection() overrides existing requirements'); - $this->assertEquals('https', $collection->get('bar')->getRequirement('_scheme'), '->addCollection() overrides existing requirements'); - } - public function testResource() { if (!class_exists('Symfony\Component\Config\Resource\FileResource')) {