Example #1
0
 /**
  * Check if the route compared has the same properties
  * @param  Route  $route route to be compared
  * @return boolean
  */
 public function equals(Route $route) : bool
 {
     if ($this->method !== $route->getMethod()) {
         return false;
     }
     if ($this->path !== $route->getPath()) {
         return false;
     }
     return true;
 }
 /**
  * @test
  * @covers Asd\Router\Route::parsePath
  * @covers Asd\Router\Route::getParams
  * @covers Asd\Router\Route::matchesRequest
  */
 public function parsePath_handlesNamedParameter()
 {
     $route = new Route('GET', 'my-path/{name}', $this->callbackStub);
     $this->requestMock->method('getMethod')->willReturn('GET');
     $this->requestMock->method('getUri')->willReturn($this->uriStub);
     $this->uriStub->method('getPath')->willReturn('my-path/JohnDoe');
     $this->assertTrue($route->matchesRequest($this->requestMock));
     $this->assertEquals(['name' => 'JohnDoe'], $route->getParams());
 }
Example #3
0
 /**
  * Dispatch the matched routes callback
  * @param  Asd\Router\Route $route
  * @return Psr\Http\Message\ResponseInterface
  */
 private function dispatch(Route $route) : ResponseInterface
 {
     $callback = $route->getCallback();
     return $callback->invoke($this->request, $this->response);
 }