public function testGetBasic() { $route = Route\get($this->basicPattern, $this->basicHandler); $pattern = trim($this->basicPattern, '/'); $this->assertNotNull($route); $this->assertEquals($route['pattern'], $pattern); $this->assertEquals($route['callback'], $this->basicHandler); $this->assertEquals($route['options'], ['method' => 'GET']); }
protected function setup() { $text = 'basicHandler'; $response = Response\create(); $response['body'] = $text; $this->basicResult = $response; $this->basicPattern = '/test'; $this->basicHandler = function ($conn) use($text) { $conn['response']['body'] = $text; return $conn; }; $this->basicRoutes = [Route\get($this->basicPattern, $this->basicHandler)]; $_SERVER['REQUEST_URI'] = $this->basicPattern; $_SERVER['REQUEST_METHOD'] = 'GET'; }
<?php require '../vendor/autoload.php'; use FPWeb\App; use FPWeb\Route; // index handler $index = function ($conn) { // TODO: make this process nicer $conn['response']['body'] = 'index'; return $conn; }; // create routes $routes = [Route\get('/index', $index)]; // match request and run match $response = App\run($routes, ['param_set' => [$_GET, $_POST], 'on_error' => function ($conn) { $conn['response']['body'] = 'Not Found'; return $conn; }]); printf('<pre><code>%s</code></pre>', print_r($response, true));