示例#1
0
 function testRouteNotFoundException()
 {
     $routes = new RouteCollection();
     $route = new Route('/foo/{id}/bar/{name}', '');
     $route->setHost('{main}.foo.com');
     $route->setRequirements(['id' => '\\d+', 'name' => '\\w+', 'main' => 'm']);
     $routes->add($route);
     $matcher = new Matcher();
     $context = RequestContext::create();
     $context->setHost('www.foo.com');
     $matcher->setContext($context);
     $this->setExpectedExceptionRegExp('Slince\\Routing\\Exception\\RouteNotFoundException');
     $matcher->match('/foo/100/bar/steven', $routes);
 }
示例#2
0
 function testCompile()
 {
     $route = new Route('/users/{id}/{action}', '');
     $this->assertFalse($route->isCompiled());
     $route->compile();
     $this->assertTrue($route->isCompiled());
     $this->assertEquals('#^/users/(?P<id>.+)/(?P<action>.+)$#i', $route->getPathRegex());
     $this->assertEquals(['id', 'action'], $route->getVariables());
     $route->setHost('{mainDomain}.domain.com');
     $route->compile(true);
     $this->assertTrue($route->isCompiled());
     $this->assertEquals('#^/users/(?P<id>.+)/(?P<action>.+)$#i', $route->getPathRegex());
     $this->assertEquals('#^(?P<mainDomain>.+).domain.com$#i', $route->getHostRegex());
 }