Skip to content

Commit b4d3496

Browse files
committed
Fix handling non-array result from route provider
1 parent 72f0ba3 commit b4d3496

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

src/LazyRouteCollection.php

+6-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,12 @@ public function count(): int
3939
*/
4040
public function all(): array
4141
{
42-
return $this->provider->getRoutesByNames(null);
42+
$routes = $this->provider->getRoutesByNames(null);
43+
if (\is_array($routes)) {
44+
return $routes;
45+
}
46+
47+
return \iterator_to_array($routes);
4348
}
4449

4550
public function get(string $name): ?Route

tests/Unit/Routing/LazyRouteCollectionTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public function testGetIterator(): void
3636
$routeProvider->expects($this->exactly(2))
3737
->method('getRoutesByNames')
3838
->with(null)
39-
->willReturn($testRoutes);
39+
->willReturn(new \ArrayIterator($testRoutes));
4040
$lazyRouteCollection = new LazyRouteCollection($routeProvider);
4141
$this->assertEquals($testRoutes, iterator_to_array($lazyRouteCollection->getIterator()));
4242
$this->assertEquals($testRoutes, $lazyRouteCollection->all());

0 commit comments

Comments
 (0)