|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* Spiral Framework. |
|
5
|
|
|
* |
|
6
|
|
|
* @license MIT |
|
7
|
|
|
* @author Anton Titov (Wolfy-J) |
|
8
|
|
|
*/ |
|
9
|
|
|
|
|
10
|
|
|
declare(strict_types=1); |
|
11
|
|
|
|
|
12
|
|
|
namespace Spiral\Tests\Framework; |
|
13
|
|
|
|
|
14
|
|
|
use Psr\Http\Message\ResponseInterface; |
|
15
|
|
|
use Spiral\Http\Http; |
|
16
|
|
|
use Spiral\App\TestApp; |
|
17
|
|
|
use Zend\Diactoros\ServerRequest; |
|
|
|
|
|
|
18
|
|
|
|
|
19
|
|
|
abstract class HttpTest extends BaseTest |
|
20
|
|
|
{ |
|
21
|
|
|
/** @var TestApp */ |
|
22
|
|
|
protected $app; |
|
23
|
|
|
|
|
24
|
|
|
/** @var Http */ |
|
25
|
|
|
protected $http; |
|
26
|
|
|
|
|
27
|
|
|
public function setUp(): void |
|
28
|
|
|
{ |
|
29
|
|
|
$this->app = $this->makeApp(); |
|
30
|
|
|
$this->http = $this->app->get(Http::class); |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
protected function get( |
|
34
|
|
|
$uri, |
|
35
|
|
|
array $query = [], |
|
36
|
|
|
array $headers = [], |
|
37
|
|
|
array $cookies = [] |
|
38
|
|
|
): ResponseInterface { |
|
39
|
|
|
return $this->http->handle($this->request($uri, 'GET', $query, $headers, $cookies)); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
protected function getWithAttributes( |
|
43
|
|
|
$uri, |
|
44
|
|
|
array $attributes, |
|
45
|
|
|
array $headers = [] |
|
46
|
|
|
): ResponseInterface { |
|
47
|
|
|
$r = $this->request($uri, 'GET', [], $headers, []); |
|
48
|
|
|
foreach ($attributes as $k => $v) { |
|
49
|
|
|
$r = $r->withAttribute($k, $v); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
return $this->http->handle($r); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
|
|
56
|
|
|
protected function post( |
|
57
|
|
|
$uri, |
|
58
|
|
|
array $data = [], |
|
59
|
|
|
array $headers = [], |
|
60
|
|
|
array $cookies = [] |
|
61
|
|
|
): ResponseInterface { |
|
62
|
|
|
return $this->http->handle( |
|
63
|
|
|
$this->request($uri, 'POST', [], $headers, $cookies)->withParsedBody($data) |
|
64
|
|
|
); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
protected function request( |
|
68
|
|
|
$uri, |
|
69
|
|
|
string $method, |
|
70
|
|
|
array $query = [], |
|
71
|
|
|
array $headers = [], |
|
72
|
|
|
array $cookies = [] |
|
73
|
|
|
): ServerRequest { |
|
74
|
|
|
return new ServerRequest( |
|
75
|
|
|
[], |
|
76
|
|
|
[], |
|
77
|
|
|
$uri, |
|
78
|
|
|
$method, |
|
79
|
|
|
'php://input', |
|
80
|
|
|
$headers, |
|
81
|
|
|
$cookies, |
|
82
|
|
|
$query |
|
83
|
|
|
); |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
protected function fetchCookies(array $header) |
|
87
|
|
|
{ |
|
88
|
|
|
$result = []; |
|
89
|
|
|
foreach ($header as $line) { |
|
90
|
|
|
$cookie = explode('=', $line); |
|
91
|
|
|
$result[$cookie[0]] = rawurldecode(substr($cookie[1], 0, strpos($cookie[1], ';'))); |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
return $result; |
|
95
|
|
|
} |
|
96
|
|
|
} |
|
97
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths