-
-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathRequestMock.php
121 lines (111 loc) · 3.57 KB
/
RequestMock.php
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
<?php
/*
* This file is part of Aplus Framework HTTP Library.
*
* (c) Natan Felles <natanfelles@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Tests\HTTP;
use Framework\HTTP\UserAgent;
class RequestMock extends \Framework\HTTP\Request
{
/**
* @var array<string,mixed>|null
*/
public ?array $parsedBody = null;
public UserAgent | false $userAgent;
/**
* @var array<int,array<string,mixed>>
*/
public static array $input = [
\INPUT_SERVER => [
'HTTP_ACCEPT' => 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
'HTTP_ACCEPT_ENCODING' => 'gzip, deflate',
'HTTP_ACCEPT_LANGUAGE' => 'pt-BR,es;q=0.8,en;q=0.5,en-US;q=0.3',
'HTTP_ACCEPT_CHARSET' => 'utf-8, iso-8859-1;q=0.5, *;q=0.1',
'HTTP_CONTENT_TYPE' => 'text/html; charset=UTF-8',
'HTTP_HOST' => 'domain.tld',
'HTTP_REFERER' => 'http://domain.tld/contact.html',
'HTTP_USER_AGENT' => 'Mozilla/5.0 (X11; Linux x86_64; rv:61.0) Gecko/20100101 Firefox/61.0',
'HTTP_X_REQUEST_ID' => 'abc123',
'HTTP_X_REQUESTED_WITH' => 'XMLHTTPREQUEST',
'REMOTE_ADDR' => '192.168.1.100',
'REQUEST_METHOD' => 'GET',
'REQUEST_SCHEME' => 'http',
'REQUEST_URI' => '/blog/posts?order_by=title&order=asc',
'SERVER_PORT' => 80,
'SERVER_PROTOCOL' => 'HTTP/1.1',
'SERVER_NAME' => 'domain.tld',
],
\INPUT_POST => [
'username' => 'phpdev',
'password' => 'Aw3S0me',
'user' => [
'name' => 'foo',
'email' => 'foo@bar.com',
'city' => 'bar',
],
'csrf_token' => 'foo',
],
\INPUT_GET => [
'order_by' => 'title',
'order' => 'asc',
],
\INPUT_COOKIE => [
'session_id' => 'abc',
'cart' => 'cart-123',
'status-bar' => 'open',
'X-CSRF-Token' => 'token',
],
\INPUT_ENV => [],
];
public function __construct(array $allowedHosts = [])
{
$this->prepareInput();
parent::__construct($allowedHosts);
}
protected function prepareInput() : void
{
$_SERVER = static::$input[\INPUT_SERVER];
$_POST = static::$input[\INPUT_POST];
$_GET = static::$input[\INPUT_GET];
$_COOKIE = static::$input[\INPUT_COOKIE];
$_ENV = static::$input[\INPUT_ENV];
}
public function filterInput(
int $type,
?string $name = null,
?int $filter = null,
array | int $options = []
) : mixed {
return parent::filterInput($type, $name, $filter, $options);
}
public function setHeader(string $name, string $value) : static
{
return parent::setHeader($name, $value);
}
public function removeHeader(string $name) : static
{
return parent::removeHeader($name);
}
public function setMethod(string $method) : static
{
return parent::setMethod($method);
}
public function setHost(string $host) : static
{
return parent::setHost($host);
}
/**
* @param int $type One of the INPUT_* constants
* @param array<string,mixed> $variables
*/
public static function setInput(int $type, array $variables) : void
{
foreach ($variables as $key => $value) {
static::$input[$type][$key] = $value;
}
}
}