public function testSpecifiedNamedParam() { $app = new \Exedra\Application(__DIR__); $app->map->any('/[foo|bar:name]/[baz|bad:type]')->execute(function ($exe) { return $exe->param('name') . ' ' . $exe->param('type'); }); $this->assertEquals($app->respond(ServerRequest::createFromArray(['uri' => ['path' => '/foo/baz']]))->getBody(), 'foo baz'); $this->assertEquals($app->respond(ServerRequest::createFromArray(['uri' => ['path' => '/bar/bad']]))->getBody(), 'bar bad'); $this->assertTrue($app->map->findByRequest(ServerRequest::createFromArray(['uri' => ['path' => '/foo/bad']]))->isSuccess()); $this->assertFalse($app->map->findByRequest(ServerRequest::createFromArray(['uri' => ['path' => '/bas/bad']]))->isSuccess()); $this->assertFalse($app->map->findByRequest(ServerRequest::createFromArray(['uri' => ['path' => '/foo/qux']]))->isSuccess()); }
public function testFailedDispatch() { $request = \Exedra\Http\ServerRequest::createFromArray(array('method' => 'GET', 'uri' => 'http://google.com:80/foo/bar/bat?baz=bad#fragman', 'headers' => array('referer' => array('http://foo.com')))); $app = new \Exedra\Application(__DIR__); $app->map->any('/foo/bar')->execute(function () { return 'baz'; }); $response = $app->respond($request); $this->assertEquals(404, $response->getStatusCode()); $this->assertEquals('Route does not exist', $response->getBody()); }