Reset router to beginning

pull/622/head
n0nag0n 3 days ago
parent 25250bf44e
commit 7dd52c9ee6

@ -490,6 +490,7 @@ class Engine
$this->unregister('response'); $this->unregister('response');
$this->register('request', Request::class); $this->register('request', Request::class);
$this->register('response', Response::class); $this->register('response', Response::class);
$this->router()->reset();
} }
$request = $this->request(); $request = $this->request();
$response = $this->response(); $response = $this->response();
@ -513,7 +514,6 @@ class Engine
// Route the request // Route the request
$failedMiddlewareCheck = false; $failedMiddlewareCheck = false;
while ($route = $router->route($request)) { while ($route = $router->route($request)) {
$params = array_values($route->params); $params = array_values($route->params);

@ -0,0 +1,83 @@
<?php
declare(strict_types=1);
namespace tests;
use Flight;
use flight\Engine;
use PHPUnit\Framework\TestCase;
class FlightAsyncTest extends TestCase
{
public static function setUpBeforeClass(): void
{
Flight::setEngine(new Engine());
}
protected function setUp(): void
{
$_SERVER = [];
$_REQUEST = [];
}
protected function tearDown(): void
{
unset($_REQUEST);
unset($_SERVER);
}
// Checks that default components are loaded
public function testSingleRoute()
{
Flight::route('GET /', function () {
echo 'hello world';
});
$this->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();
}
}
Loading…
Cancel
Save