/** * Asserts that global strategy is used when set * * @return void */ public function testGlobalStrategyIsUsedWhenSet() { $router = new RouteCollection(); $router->setStrategy(RouteCollection::URI_STRATEGY); $router->get('/route/{wildcard}', 'handler_get', RouteCollection::RESTFUL_STRATEGY); $router->post('/route/{wildcard}', 'handler_post', RouteCollection::URI_STRATEGY); $router->put('/route/{wildcard}', 'handler_put', RouteCollection::REQUEST_RESPONSE_STRATEGY); $router->patch('/route/{wildcard}', 'handler_patch'); $router->delete('/route/{wildcard}', 'handler_delete'); $router->head('/route/{wildcard}', 'handler_head'); $router->options('/route/{wildcard}', 'handler_options'); $routes = (new \ReflectionClass($router))->getProperty('routes'); $routes->setAccessible(true); $routes = $routes->getValue($router); $this->assertCount(7, $routes); $this->assertSame($routes['handler_get'], ['strategy' => 2]); $this->assertSame($routes['handler_post'], ['strategy' => 2]); $this->assertSame($routes['handler_put'], ['strategy' => 2]); $this->assertSame($routes['handler_patch'], ['strategy' => 2]); $this->assertSame($routes['handler_delete'], ['strategy' => 2]); $this->assertSame($routes['handler_head'], ['strategy' => 2]); $this->assertSame($routes['handler_options'], ['strategy' => 2]); }
/** * Asserts that a custom strategy is dispatched correctly and the return of that * method bubbles out to the dispatcher * * @return void */ public function testCustomStrategyIsDispatchedCorrectly() { $mockStrategy = $this->getMock('Orno\\Route\\CustomStrategyInterface'); $mockStrategy->expects($this->once())->method('dispatch')->with($this->equalTo(['Controller', 'method']), $this->equalTo(['id' => 2, 'name' => 'phil']))->will($this->returnValue(['id' => 2, 'name' => 'phil'])); $collection = new Route\RouteCollection(); $collection->get('/route/{id}/{name}', 'Controller::method', $mockStrategy); $dispatcher = $collection->getDispatcher(); $response = $dispatcher->dispatch('GET', '/route/2/phil'); $this->assertSame(['id' => 2, 'name' => 'phil'], $response); }