/** * @param $job * @param $collection * @return callable */ private function getClosure($job, RouteCollection $collection) { $collection->addRoutes(['/' => ['use' => $job['controller'], 'ajax' => isset($job['ajax']) && $job['ajax'] ? true : false]], ['path' => ROOT . '/Views', 'namespace' => '']); $router = new Router($collection); $router->setUrl('/'); $router->match(); return function () use($router) { $router->callTarget(); $router->response->sendContent(); }; }
public function testPostResponseMethod() { $collection = new RouteCollection(); $collection->addRoutes(ROOT . '/Config/routes.php', ['view_dir' => ROOT . '/Views', 'ctrl_namespace' => 'JetFire\\Routing\\App\\Controllers']); $_SERVER['REQUEST_METHOD'] = 'POST'; $router = new Router($collection); $router->addMatcher(new ArrayMatcher($router)); $router->setUrl('/search'); $this->assertTrue($router->match()); $router->callTarget(); $router->response->sendContent(); $this->assertEquals('POST', $router->route->getMethod()); }