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\Http; |
13
|
|
|
|
14
|
|
|
use Mockery as m; |
15
|
|
|
use Spiral\Boot\DirectoriesInterface; |
16
|
|
|
use Spiral\Files\FilesInterface; |
17
|
|
|
use Spiral\Http\RrDispatcher; |
18
|
|
|
use Spiral\RoadRunner\PSR7Client; |
19
|
|
|
use Spiral\Tests\Framework\ConsoleTest; |
20
|
|
|
use Zend\Diactoros\ServerRequest; |
|
|
|
|
21
|
|
|
|
22
|
|
|
class RrTest extends ConsoleTest |
23
|
|
|
{ |
24
|
|
|
public function testCanServe(): void |
25
|
|
|
{ |
26
|
|
|
$this->assertFalse($this->app->get(RrDispatcher::class)->canServe()); |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
public function testCanServe2(): void |
30
|
|
|
{ |
31
|
|
|
$this->app->getEnvironment()->set('RR_HTTP', true); |
32
|
|
|
$this->assertTrue($this->app->get(RrDispatcher::class)->canServe()); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
public function testServe(): void |
36
|
|
|
{ |
37
|
|
|
$this->app->getEnvironment()->set('RR_HTTP', true); |
38
|
|
|
|
39
|
|
|
$psr = m::mock(PSR7Client::class); |
40
|
|
|
|
41
|
|
|
$psr->shouldReceive('acceptRequest')->once()->andReturn( |
42
|
|
|
new ServerRequest([], [], '/index/dave') |
43
|
|
|
); |
44
|
|
|
|
45
|
|
|
$psr->shouldReceive('respond')->once()->with( |
46
|
|
|
\Mockery::on(function ($r) { |
47
|
|
|
$this->assertSame('Hello, dave.', (string)$r->getBody()); |
48
|
|
|
return true; |
49
|
|
|
}) |
50
|
|
|
)->andReturn(true); |
51
|
|
|
|
52
|
|
|
$psr->shouldReceive('acceptRequest')->once()->andReturn(null); |
53
|
|
|
|
54
|
|
|
$this->app->get(RrDispatcher::class)->serve($psr); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
public function testServeError(): void |
58
|
|
|
{ |
59
|
|
|
$this->app->getEnvironment()->set('RR_HTTP', true); |
60
|
|
|
|
61
|
|
|
$psr = m::mock(PSR7Client::class); |
62
|
|
|
|
63
|
|
|
$psr->shouldReceive('acceptRequest')->once()->andReturn( |
64
|
|
|
new ServerRequest([], [], '/error') |
65
|
|
|
); |
66
|
|
|
|
67
|
|
|
$psr->shouldReceive('respond')->once()->with( |
68
|
|
|
\Mockery::on(function ($r) { |
69
|
|
|
$this->assertStringContainsString('500', (string)$r->getBody()); |
70
|
|
|
return true; |
71
|
|
|
}) |
72
|
|
|
)->andReturn(true); |
73
|
|
|
|
74
|
|
|
$psr->shouldReceive('acceptRequest')->once()->andReturn(null); |
75
|
|
|
|
76
|
|
|
$files = $this->app->get(FilesInterface::class)->getFiles( |
77
|
|
|
$this->app->get(DirectoriesInterface::class)->get('runtime') . '/snapshots/' |
78
|
|
|
); |
79
|
|
|
|
80
|
|
|
$this->assertCount(0, $files); |
81
|
|
|
|
82
|
|
|
$this->app->get(RrDispatcher::class)->serve($psr); |
83
|
|
|
|
84
|
|
|
$files = $this->app->get(FilesInterface::class)->getFiles( |
85
|
|
|
$this->app->get(DirectoriesInterface::class)->get('runtime') . '/snapshots/' |
86
|
|
|
); |
87
|
|
|
|
88
|
|
|
$this->assertCount(1, $files); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
public function testServeErrorDebug(): void |
92
|
|
|
{ |
93
|
|
|
$this->app = $this->makeApp([ |
94
|
|
|
'DEBUG' => true |
95
|
|
|
]); |
96
|
|
|
|
97
|
|
|
$this->app->getEnvironment()->set('RR_HTTP', true); |
98
|
|
|
|
99
|
|
|
$psr = m::mock(PSR7Client::class); |
100
|
|
|
|
101
|
|
|
$psr->shouldReceive('acceptRequest')->once()->andReturn( |
102
|
|
|
new ServerRequest([], [], '/error') |
103
|
|
|
); |
104
|
|
|
|
105
|
|
|
$psr->shouldReceive('respond')->once()->with( |
106
|
|
|
\Mockery::on(function ($r) { |
107
|
|
|
$this->assertStringContainsString('undefined', (string)$r->getBody()); |
108
|
|
|
return true; |
109
|
|
|
}) |
110
|
|
|
)->andReturn(true); |
111
|
|
|
|
112
|
|
|
$psr->shouldReceive('acceptRequest')->once()->andReturn(null); |
113
|
|
|
|
114
|
|
|
$files = $this->app->get(FilesInterface::class)->getFiles( |
115
|
|
|
$this->app->get(DirectoriesInterface::class)->get('runtime') . '/snapshots/' |
116
|
|
|
); |
117
|
|
|
|
118
|
|
|
$this->assertCount(0, $files); |
119
|
|
|
|
120
|
|
|
$this->app->get(RrDispatcher::class)->serve($psr); |
121
|
|
|
|
122
|
|
|
$files = $this->app->get(FilesInterface::class)->getFiles( |
123
|
|
|
$this->app->get(DirectoriesInterface::class)->get('runtime') . '/snapshots/' |
124
|
|
|
); |
125
|
|
|
|
126
|
|
|
$this->assertCount(1, $files); |
127
|
|
|
} |
128
|
|
|
} |
129
|
|
|
|
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