forked from roadrunner-php/http
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGlobalStateTest.php
More file actions
71 lines (60 loc) · 2.07 KB
/
GlobalStateTest.php
File metadata and controls
71 lines (60 loc) · 2.07 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
<?php
declare(strict_types=1);
namespace Spiral\RoadRunner\Tests\Http\Unit;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
use Spiral\RoadRunner\Http\GlobalState;
use Spiral\RoadRunner\Http\Request;
final class GlobalStateTest extends TestCase
{
/**
* @return iterable<array{0: Request, 1: array<array-key, mixed>}>
*/
public static function enrichServerVarsDataProvider(): iterable
{
yield [
new Request(),
[
'REQUEST_URI' => 'http://localhost',
'REMOTE_ADDR' => '127.0.0.1',
'REQUEST_METHOD' => 'GET',
'HTTP_USER_AGENT' => '',
'HTTP_HOST' => 'localhost',
],
];
yield [
new Request(uri: 'https://roadrunner.dev'),
[
'REQUEST_URI' => 'https://roadrunner.dev',
'REMOTE_ADDR' => '127.0.0.1',
'REQUEST_METHOD' => 'GET',
'HTTP_USER_AGENT' => '',
'HTTP_HOST' => 'roadrunner.dev',
],
];
yield [
new Request(uri: 'https://roadrunner.dev:8080'),
[
'REQUEST_URI' => 'https://roadrunner.dev:8080',
'REMOTE_ADDR' => '127.0.0.1',
'REQUEST_METHOD' => 'GET',
'HTTP_USER_AGENT' => '',
'HTTP_HOST' => 'roadrunner.dev:8080',
],
];
}
/**
* @param array<array-key, mixed> $expected
*/
#[DataProvider('enrichServerVarsDataProvider')]
public function testEnrichServerVars(Request $request, array $expected): void
{
$_SERVER = [];
$server = GlobalState::enrichServerVars($request);
$this->assertArrayHasKey('REQUEST_TIME', $server);
$this->assertArrayHasKey('REQUEST_TIME_FLOAT', $server);
unset($server['REQUEST_TIME']);
unset($server['REQUEST_TIME_FLOAT']);
$this->assertEquals($server, $expected);
}
}