public function testComplexExternalUrlMapping() { $routePatten = '/test/local/$testvar/$why/$also'; $requestUri = '/test/local/bla/whynot/hi'; $targetUri = 'https://www.google.com/search?q=$testvar&why=$why&also=$also'; $route = new Route($routePatten, function () { // ... }); $request = new Request(); $request->setRequestUri($requestUri); $this->assertTrue($route->matches($request)); $variableSet = VariableUrl::extractUrlVariables($requestUri, $routePatten); $this->assertEquals(['testvar' => 'bla', 'why' => 'whynot', 'also' => 'hi'], $variableSet); $mappedOutput = VariableUrl::applyUrlVariables($targetUri, $variableSet); $this->assertEquals('https://www.google.com/search?q=bla&why=whynot&also=hi', $mappedOutput); }
/** * Internal function to register a new route. * Will bootstrap the router if necessary. * * @param string $pattern The regex pattern to match requests against (supports dynamic variables). * @param mixed|string $target The target function or path for the route. * @param array $requestMethods A list of acceptable request methods, leave empty to disable constraint. * @return Route The generated route. */ private function registerRoute($pattern, $target, array $requestMethods = []) { $this->bootstrapRouter(); $route = new Route($pattern, $target); if (!empty($requestMethods)) { $route->setAcceptableMethods($requestMethods); } $this->router->register($route); return $route; }
public function testControllerDispatchingWithBeforeResponseSkipsPrimaryAction() { $context = new Context(); $request = new Request(); $context->registerInstance($request); $route = new Route('/', 'Enlighten\\Tests\\Routing\\Sample\\SampleControllerWithBeforeResponse'); $this->assertInstanceOf('Enlighten\\Http\\Response', $route->action($context)); $this->expectOutputString(''); // This test SHOULD result in the route's primary action NOT being called. // (if it is called, an exception is thrown - see the SampleControllerWithBeforeResponse class) }