public function testUriBuilder() { $routeCollection = new RouteCollection(); $routeCollection->addRoute(new PlaceholderRoute('/profile/:username'))->setName('profileUsername')->constraints(['username' => '[a-zA-Z]+']); $routeCollection->addRoute(new PlaceholderRoute('/profile/:id'))->setName('profileUserId')->constraints(['id' => '[0-9]+']); $uriBuilder = new UriBuilder($routeCollection); $url = $uriBuilder->buildUri(new RouteData('profileUserId', ['id' => 42])); $this->assertSame('/profile/42', $url); }
public function testRequestMatcher() { $routeCollection = new RouteCollection(); $routeCollection->get(new PlaceholderRoute('/profile/:username'))->setName('profileUsername')->constraints(['username' => '[a-zA-Z]+']); $routeCollection->addRoute(new PlaceholderRoute('/profile/:id'))->setName('profileUserId')->constraints(['id' => '[0-9]+'])->allows(['GET', 'POST']); $requestMatcher = new RequestMatcher($routeCollection); $routeData = $requestMatcher->match(new ServerRequest([], [], 'http://example.com/profile/42', 'POST')); $this->assertInstanceOf('Gobline\\Router\\RouteData', $routeData); $this->assertSame('profileUserId', $routeData->getName()); $routeData = $requestMatcher->match(new ServerRequest([], [], 'http://example.com/profile/foobar', 'GET')); $this->assertInstanceOf('Gobline\\Router\\RouteData', $routeData); $this->assertSame('profileUsername', $routeData->getName()); }