|
2 | 2 |
|
3 | 3 | declare(strict_types=1); |
4 | 4 |
|
5 | | -namespace Spiral\RoadRunner\Tests\Http\Unit; |
6 | | - |
7 | 5 | use Nyholm\Psr7\Factory\Psr17Factory; |
| 6 | +use PHPUnit\Framework\Attributes\CoversClass; |
8 | 7 | use PHPUnit\Framework\TestCase; |
9 | 8 | use Spiral\Goridge\Frame; |
10 | | -use Spiral\RoadRunner\Http\HttpWorker; |
| 9 | +use Spiral\RoadRunner\Http\GlobalState; |
11 | 10 | use Spiral\RoadRunner\Http\PSR7Worker; |
12 | 11 | use Spiral\RoadRunner\Tests\Http\Unit\Stub\TestRelay; |
13 | 12 | use Spiral\RoadRunner\Worker; |
14 | 13 |
|
| 14 | + |
| 15 | +#[CoversClass(PSR7Worker::class)] |
| 16 | +#[CoversClass(GlobalState::class)] |
15 | 17 | final class PSR7WorkerTest extends TestCase |
16 | 18 | { |
17 | | - /** |
| 19 | + /*** |
18 | 20 | * @param array $headers |
19 | | - * |
20 | | - * @dataProvider testStateLeakDataProvider |
21 | 21 | */ |
22 | | - public function testStateLeak(array $headers): void |
| 22 | + public function testStateServerLeak(): void |
23 | 23 | { |
24 | 24 | $psrFactory = new Psr17Factory(); |
25 | 25 | $relay = new TestRelay(); |
26 | | - |
27 | | - $body = [ |
28 | | - 'headers' => $headers, |
29 | | - 'rawQuery' => '', |
30 | | - 'remoteAddr' => '127.0.0.1', |
31 | | - 'protocol' => 'HTTP/1.1', |
32 | | - 'method' => 'GET', |
33 | | - 'uri' => 'http://localhost', |
34 | | - 'parsed' => false, |
35 | | - ]; |
36 | | - |
37 | | - $head = (string)\json_encode($body, \JSON_THROW_ON_ERROR); |
38 | | - $frame = new Frame($head .'test', [\strlen($head)]); |
39 | | - |
40 | | - $relay->addFrames($frame); |
41 | | - |
42 | | - $psrWorker = new PSR7Worker( |
| 26 | + $psrWorker = new PSR7Worker( |
43 | 27 | new Worker($relay), |
44 | 28 | $psrFactory, |
45 | 29 | $psrFactory, |
46 | 30 | $psrFactory, |
47 | 31 | ); |
48 | 32 |
|
49 | | - $psrWorker->waitRequest(); |
| 33 | + //dataProvider is always random and we need to keep the order |
| 34 | + $fixtures = [ |
| 35 | + [['Content-Type' => ['application/html'], 'Connection' => ['keep-alive']], ['REQUEST_URI' => 'http://localhost', 'REMOTE_ADDR' => '127.0.0.1', 'REQUEST_METHOD' => 'GET', 'HTTP_USER_AGENT' => '', 'CONTENT_TYPE' => 'application/html', 'HTTP_CONNECTION' => 'keep-alive',]], |
| 36 | + [['Content-Type' => ['application/json']], ['REQUEST_URI' => 'http://localhost', 'REMOTE_ADDR' => '127.0.0.1', 'REQUEST_METHOD' => 'GET', 'HTTP_USER_AGENT' => '', 'CONTENT_TYPE' => 'application/json']], |
| 37 | + ]; |
50 | 38 |
|
| 39 | + foreach ($fixtures as [$headers, $expectedServer]) { |
| 40 | + $body = [ |
| 41 | + 'headers' => $headers, |
| 42 | + 'rawQuery' => '', |
| 43 | + 'remoteAddr' => '127.0.0.1', |
| 44 | + 'protocol' => 'HTTP/1.1', |
| 45 | + 'method' => 'GET', |
| 46 | + 'uri' => 'http://localhost', |
| 47 | + 'parsed' => false, |
| 48 | + ]; |
51 | 49 |
|
52 | | - var_dump($_SERVER); |
53 | | - } |
| 50 | + $head = (string)\json_encode($body, \JSON_THROW_ON_ERROR); |
| 51 | + $frame = new Frame($head .'test', [\strlen($head)]); |
54 | 52 |
|
| 53 | + $relay->addFrames($frame); |
55 | 54 |
|
56 | | - public static function testStateLeakDataProvider(): iterable |
57 | | - { |
58 | | - yield [['Content-Type' => ['application/json'], 'Accept' => ['application/html']]]; |
59 | | - yield [['Content-Type' => ['application/json']]]; |
| 55 | + $_SERVER = []; |
| 56 | + |
| 57 | + $psrWorker->waitRequest(); |
| 58 | + |
| 59 | + unset($_SERVER['REQUEST_TIME']); |
| 60 | + unset($_SERVER['REQUEST_TIME_FLOAT']); |
| 61 | + |
| 62 | + self::assertEquals($expectedServer, $_SERVER); |
| 63 | + } |
60 | 64 | } |
61 | 65 |
|
62 | 66 |
|
|
0 commit comments