Exemple #1
0
 /**
  * Returns a http route fixture.
  * @param array $rules
  * @param array $defaultValues
  * @return \Brickoo\Component\Routing\Route\HttpRoute
  */
 private function getHttpRouteFixture(array $rules = [], array $defaultValues = [])
 {
     $route = new HttpRoute("test.route", "/article/{name}/{page}", "NewspaperController", "getArticle");
     $route->setRules($rules);
     $route->setDefaultValues($defaultValues);
     return $route;
 }
 /**
  * @covers Brickoo\Component\Routing\Route\Matcher\HttpRouteMatcher::getRouteParameters
  * @covers Brickoo\Component\Routing\Route\Matcher\CommonRouteMatcherStructure::collectRouteParameters
  * @covers Brickoo\Component\Routing\Route\Matcher\CommonRouteMatcherStructure::getRuleCorrespondingRouteParameter
  */
 public function testGetRouteParametersWithPageAsDefaultValue()
 {
     $expectedParameters = ["name" => "doing-unit-tests", "page" => 1];
     $routeHttpMatcher = new HttpRouteMatcher($this->getRequestFixture("/doing-unit-tests"), new RoutePathRegexGenerator());
     $route = new HttpRoute("test.route", "/{name}/{page}", "ControllerPath");
     $route->setRules(["name" => "[\\w\\-]+", "page" => "[0-9]+"]);
     $route->setDefaultValues(["page" => 1]);
     $this->assertTrue($routeHttpMatcher->matchesRoute($route));
     $this->assertEquals($expectedParameters, $routeHttpMatcher->getRouteParameters());
 }
 /**
  * Checks if the Route is allowed to be executed.
  * @param \Brickoo\Component\Routing\Route\HttpRoute $route
  * @return boolean check result
  */
 private function isAllowedRoute(HttpRoute $route)
 {
     return $this->doesPropertyMatch($route->getMethod(), $this->request->getMethod()->toString()) && $this->doesPropertyMatch($route->getHostname(), $this->request->getUri()->getHostname()) && $this->doesPropertyMatch($route->getScheme(), $this->request->getUri()->getScheme());
 }