diff --git a/flight/Engine.php b/flight/Engine.php index e2c1dc3..a26c1ff 100644 --- a/flight/Engine.php +++ b/flight/Engine.php @@ -490,6 +490,7 @@ class Engine $this->unregister('response'); $this->register('request', Request::class); $this->register('response', Response::class); + $this->router()->reset(); } $request = $this->request(); $response = $this->response(); @@ -513,7 +514,6 @@ class Engine // Route the request $failedMiddlewareCheck = false; - while ($route = $router->route($request)) { $params = array_values($route->params); diff --git a/tests/FlightAsyncTest.php b/tests/FlightAsyncTest.php new file mode 100644 index 0000000..1a53f44 --- /dev/null +++ b/tests/FlightAsyncTest.php @@ -0,0 +1,83 @@ +expectOutputString('hello world'); + Flight::start(); + } + + public function testMultipleRoutes() + { + Flight::route('GET /', function () { + echo 'hello world'; + }); + + Flight::route('GET /test', function () { + echo 'test'; + }); + + $this->expectOutputString('test'); + $_SERVER['REQUEST_URI'] = '/test'; + Flight::start(); + } + + public function testMultipleStartsSingleRoute() + { + Flight::route('GET /', function () { + echo 'hello world'; + }); + + $this->expectOutputString('hello worldhello world'); + Flight::start(); + Flight::start(); + } + + public function testMultipleStartsMultipleRoutes() + { + Flight::route('GET /', function () { + echo 'hello world'; + }); + + Flight::route('GET /test', function () { + echo 'test'; + }); + + $this->expectOutputString('testhello world'); + $_SERVER['REQUEST_URI'] = '/test'; + Flight::start(); + $_SERVER['REQUEST_URI'] = '/'; + Flight::start(); + } +}