From bc216872551b04e7b06764b19da027c622151e04 Mon Sep 17 00:00:00 2001 From: Tobias Schultze Date: Fri, 7 Dec 2012 11:44:47 +0100 Subject: [PATCH] refactor interator test that was still assuming a tree --- Tests/RouteCollectionTest.php | 24 +++++++----------------- 1 file changed, 7 insertions(+), 17 deletions(-) diff --git a/Tests/RouteCollectionTest.php b/Tests/RouteCollectionTest.php index 62d58ca0..9cccd4c3 100644 --- a/Tests/RouteCollectionTest.php +++ b/Tests/RouteCollectionTest.php @@ -54,16 +54,19 @@ public function testDeepOverriddenRoute() $this->assertEquals('/foo2', $collection->get('foo')->getPath()); } - public function testIteratorWithOverriddenRoutes() + public function testIterator() { $collection = new RouteCollection(); $collection->add('foo', new Route('/foo')); $collection1 = new RouteCollection(); - $collection1->add('foo', new Route('/foo1')); + $collection1->add('bar', $bar = new Route('/bar')); + $collection1->add('foo', $foo = new Route('/foo-new')); $collection->addCollection($collection1); + $collection->add('last', $last = new Route('/last')); - $this->assertEquals('/foo1', $this->getFirstNamedRoute($collection, 'foo')->getPath()); + $this->assertInstanceOf('\ArrayIterator', $collection->getIterator()); + $this->assertSame(array('bar' => $bar, 'foo' => $foo, 'last' => $last), $collection->getIterator()->getArrayCopy()); } public function testCount() @@ -72,25 +75,12 @@ public function testCount() $collection->add('foo', new Route('/foo')); $collection1 = new RouteCollection(); - $collection1->add('foo1', new Route('/foo1')); + $collection1->add('bar', new Route('/bar')); $collection->addCollection($collection1); $this->assertCount(2, $collection); } - protected function getFirstNamedRoute(RouteCollection $routeCollection, $name) - { - foreach ($routeCollection as $key => $route) { - if ($route instanceof RouteCollection) { - return $this->getFirstNamedRoute($route, $name); - } - - if ($name === $key) { - return $route; - } - } - } - public function testAddCollection() { if (!class_exists('Symfony\Component\Config\Resource\FileResource')) {