public function test_can_iterate_the_collection() { $route = new Route(['GET'], '/', function () { }); $collection = new RouteCollection(); $collection->add($route); foreach ($collection as $cRoute) { $this->assertEquals($route, $cRoute); } }
public function test_cannot_dispatch_post_route_as_get() { $request = \Mockery::mock(Request::class); $request->shouldReceive('method')->once()->andReturn('POST'); $request->shouldReceive('path')->once()->andReturn('/'); $collection = new RouteCollection(); $collection->add($givenRoute = new Route(['GET'], '/', 'HomeController@index')); $this->setExpectedException(MethodNotAllowedException::class, 'Method [GET, HEAD] is not allowed'); $this->dispatcher->dispatch($request, $collection); }
/** * Add a route to the underlying route collection. * * @param array|string $methods * @param string $uri * @param \Closure|array|string $action * * @return Route */ protected function addRoute($methods, $uri, $action) { return $this->routes->add(new Route($methods, $uri, $action)); }