Skip to content

Commit

Permalink
refactor interator test that was still assuming a tree
Browse files Browse the repository at this point in the history
  • Loading branch information
Tobion committed Mar 5, 2013
1 parent 2760844 commit bc21687
Showing 1 changed file with 7 additions and 17 deletions.
24 changes: 7 additions & 17 deletions Tests/RouteCollectionTest.php
Expand Up @@ -54,16 +54,19 @@ public function testDeepOverriddenRoute()
$this->assertEquals('/foo2', $collection->get('foo')->getPath()); $this->assertEquals('/foo2', $collection->get('foo')->getPath());
} }


public function testIteratorWithOverriddenRoutes() public function testIterator()
{ {
$collection = new RouteCollection(); $collection = new RouteCollection();
$collection->add('foo', new Route('/foo')); $collection->add('foo', new Route('/foo'));


$collection1 = new RouteCollection(); $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->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() public function testCount()
Expand All @@ -72,25 +75,12 @@ public function testCount()
$collection->add('foo', new Route('/foo')); $collection->add('foo', new Route('/foo'));


$collection1 = new RouteCollection(); $collection1 = new RouteCollection();
$collection1->add('foo1', new Route('/foo1')); $collection1->add('bar', new Route('/bar'));
$collection->addCollection($collection1); $collection->addCollection($collection1);


$this->assertCount(2, $collection); $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() public function testAddCollection()
{ {
if (!class_exists('Symfony\Component\Config\Resource\FileResource')) { if (!class_exists('Symfony\Component\Config\Resource\FileResource')) {
Expand Down

0 comments on commit bc21687

Please sign in to comment.