forked from roadrunner-php/http
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPSR7WorkerTest.php
More file actions
99 lines (85 loc) · 2.85 KB
/
PSR7WorkerTest.php
File metadata and controls
99 lines (85 loc) · 2.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
<?php
declare(strict_types=1);
namespace Spiral\RoadRunner\Tests\Http\Unit;
use Nyholm\Psr7\Factory\Psr17Factory;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\RunClassInSeparateProcess;
use PHPUnit\Framework\TestCase;
use Spiral\Goridge\Frame;
use Spiral\RoadRunner\Http\GlobalState;
use Spiral\RoadRunner\Http\PSR7Worker;
use Spiral\RoadRunner\Tests\Http\Unit\Stub\TestRelay;
use Spiral\RoadRunner\Worker;
#[CoversClass(PSR7Worker::class)]
#[CoversClass(GlobalState::class)]
#[RunClassInSeparateProcess]
final class PSR7WorkerTest extends TestCase
{
public function testStateServerLeak(): void
{
$psrFactory = new Psr17Factory();
$relay = new TestRelay();
$psrWorker = new PSR7Worker(
new Worker($relay),
$psrFactory,
$psrFactory,
$psrFactory,
);
//dataProvider is always random and we need to keep the order
$fixtures = [
[
[
'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',
],
],
[
[
'Content-Type' => ['application/json']
],
[
'REQUEST_URI' => 'http://localhost',
'REMOTE_ADDR' => '127.0.0.1',
'REQUEST_METHOD' => 'GET',
'HTTP_USER_AGENT' => '',
'CONTENT_TYPE' => 'application/json'
],
],
];
$_SERVER = [];
foreach ($fixtures as [$headers, $expectedServer]) {
$body = [
'headers' => $headers,
'rawQuery' => '',
'remoteAddr' => '127.0.0.1',
'protocol' => 'HTTP/1.1',
'method' => 'GET',
'uri' => 'http://localhost',
'parsed' => false,
];
$head = (string)\json_encode($body, \JSON_THROW_ON_ERROR);
$frame = new Frame($head .'test', [\strlen($head)]);
$relay->addFrames($frame);
$psrWorker->waitRequest();
unset($_SERVER['REQUEST_TIME']);
unset($_SERVER['REQUEST_TIME_FLOAT']);
self::assertEquals($expectedServer, $_SERVER);
}
}
protected function tearDown(): void
{
// Clean all extra output buffers
$level = \ob_get_level();
while (--$level > 0) {
\ob_end_clean();
}
}
}