Skip to content

Commit 7dd52c9

Browse files
committed
Reset router to beginning
1 parent 25250bf commit 7dd52c9

File tree

2 files changed

+84
-1
lines changed

2 files changed

+84
-1
lines changed

flight/Engine.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -490,6 +490,7 @@ public function _start(): void
490490
$this->unregister('response');
491491
$this->register('request', Request::class);
492492
$this->register('response', Response::class);
493+
$this->router()->reset();
493494
}
494495
$request = $this->request();
495496
$response = $this->response();
@@ -513,7 +514,6 @@ public function _start(): void
513514

514515
// Route the request
515516
$failedMiddlewareCheck = false;
516-
517517
while ($route = $router->route($request)) {
518518
$params = array_values($route->params);
519519

tests/FlightAsyncTest.php

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace tests;
6+
7+
use Flight;
8+
use flight\Engine;
9+
use PHPUnit\Framework\TestCase;
10+
11+
class FlightAsyncTest extends TestCase
12+
{
13+
public static function setUpBeforeClass(): void
14+
{
15+
Flight::setEngine(new Engine());
16+
}
17+
18+
protected function setUp(): void
19+
{
20+
$_SERVER = [];
21+
$_REQUEST = [];
22+
}
23+
24+
protected function tearDown(): void
25+
{
26+
unset($_REQUEST);
27+
unset($_SERVER);
28+
}
29+
30+
// Checks that default components are loaded
31+
public function testSingleRoute()
32+
{
33+
Flight::route('GET /', function () {
34+
echo 'hello world';
35+
});
36+
37+
$this->expectOutputString('hello world');
38+
Flight::start();
39+
}
40+
41+
public function testMultipleRoutes()
42+
{
43+
Flight::route('GET /', function () {
44+
echo 'hello world';
45+
});
46+
47+
Flight::route('GET /test', function () {
48+
echo 'test';
49+
});
50+
51+
$this->expectOutputString('test');
52+
$_SERVER['REQUEST_URI'] = '/test';
53+
Flight::start();
54+
}
55+
56+
public function testMultipleStartsSingleRoute()
57+
{
58+
Flight::route('GET /', function () {
59+
echo 'hello world';
60+
});
61+
62+
$this->expectOutputString('hello worldhello world');
63+
Flight::start();
64+
Flight::start();
65+
}
66+
67+
public function testMultipleStartsMultipleRoutes()
68+
{
69+
Flight::route('GET /', function () {
70+
echo 'hello world';
71+
});
72+
73+
Flight::route('GET /test', function () {
74+
echo 'test';
75+
});
76+
77+
$this->expectOutputString('testhello world');
78+
$_SERVER['REQUEST_URI'] = '/test';
79+
Flight::start();
80+
$_SERVER['REQUEST_URI'] = '/';
81+
Flight::start();
82+
}
83+
}

0 commit comments

Comments
 (0)