Ejemplo n.º 1
0
 public function testShouldDispatchRequestToControllerResourceActionWithParameter()
 {
     // Simulates request trigger
     $_SERVER["REQUEST_URI"] = "http://localhost/app/mock-test/do-another-thing/amazing";
     $requestFactory = new RequestFactory();
     $controllerFinder = FinderFactory::getControllerFinder($requestFactory);
     $actionFinder = FinderFactory::getActionFinder($requestFactory, true);
     $parameterFinder = FinderFactory::getParameterFinder($requestFactory);
     $builder = new RouteBuilder($controllerFinder, $actionFinder, $parameterFinder);
     $dispatcher = new Dispatcher($builder);
     $result = $dispatcher->dispatch($requestFactory);
     $this->assertThat($result, $this->equalTo('Mock\\Controller\\MockTestController::doAnotherThingGetAction(amazing)'));
 }
 public function testShouldBuildRouteToRequest()
 {
     // Simulates a GET request
     $_SERVER["SCRIPT_NAME"] = "http://localhost/app/index.php";
     $_SERVER["REQUEST_URI"] = "http://localhost/app/pt-br/test/test/attribute1/attribute2";
     $_SERVER["REQUEST_METHOD"] = "GET";
     $requestFactory = new RequestFactory();
     $dispatcherHelper = DispatcherHelper::getHelper($requestFactory->get()->toArray(), true);
     $localeFinder = FinderFactory::getLocaleFinder($requestFactory);
     $controllerFinder = FinderFactory::getControllerFinder($requestFactory);
     $actionFinder = FinderFactory::getActionFinder($requestFactory);
     $parameterFinder = FinderFactory::getParameterFinder($requestFactory);
     $routeBuilder = new I18nRouteBuilder($localeFinder, $controllerFinder, $actionFinder, $parameterFinder);
     $route = $routeBuilder->locale($dispatcherHelper->getLocale())->controller($dispatcherHelper->getController())->action($dispatcherHelper->getAction())->parameters($dispatcherHelper->getParameters())->build();
     $this->assertThat($route->locale, $this->equalTo("pt_br"), "Locale is not translated correctly!");
     $this->assertThat($route->controller, $this->equalTo("TestController"), "Controller is not translated correctly!");
     $this->assertThat($route->action, $this->equalTo("testAction"), "Action is not translated correctly!");
     $this->assertThat($route->parameters[0], $this->logicalNot($this->isNull()), "Parameter 1 is not translated correctly!");
     $this->assertThat($route->parameters[1], $this->logicalNot($this->isNull()), "Parameter 2 is not translated correctly!");
 }