|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the doyo/code-coverage project. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) Anthonius Munthi <[email protected]> |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
declare(strict_types=1); |
|
13
|
|
|
|
|
14
|
|
|
namespace Spec\Doyo\Bridge\CodeCoverage\Controller; |
|
15
|
|
|
|
|
16
|
|
|
use Doyo\Bridge\CodeCoverage\Controller\RemoteController; |
|
17
|
|
|
use Doyo\Bridge\CodeCoverage\Driver\Dummy; |
|
18
|
|
|
use Doyo\Bridge\CodeCoverage\ProcessorInterface; |
|
19
|
|
|
use Doyo\Bridge\CodeCoverage\Session\SessionInterface; |
|
20
|
|
|
use PhpSpec\ObjectBehavior; |
|
|
|
|
|
|
21
|
|
|
use SebastianBergmann\CodeCoverage\CodeCoverage; |
|
|
|
|
|
|
22
|
|
|
use Spec\Doyo\Bridge\CodeCoverage\ResponseTrait; |
|
23
|
|
|
use Symfony\Component\HttpFoundation\HeaderBag; |
|
|
|
|
|
|
24
|
|
|
use Symfony\Component\HttpFoundation\Request; |
|
|
|
|
|
|
25
|
|
|
use Symfony\Component\HttpFoundation\Response; |
|
|
|
|
|
|
26
|
|
|
|
|
27
|
|
|
class RemoteControllerSpec extends ObjectBehavior |
|
28
|
|
|
{ |
|
29
|
|
|
use ResponseTrait; |
|
30
|
|
|
|
|
31
|
|
|
public function it_is_initializable() |
|
32
|
|
|
{ |
|
33
|
|
|
$this->shouldHaveType(RemoteController::class); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
public function its_create_should_create_a_new_instance() |
|
37
|
|
|
{ |
|
38
|
|
|
$this->create()->shouldHaveType(RemoteController::class); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
public function its_should_return_404_when_action_not_exist( |
|
42
|
|
|
Request $request |
|
43
|
|
|
) { |
|
44
|
|
|
$request->get('action')->willReturn('foo'); |
|
45
|
|
|
|
|
46
|
|
|
$response = $this->getResponse(); |
|
47
|
|
|
$response->shouldBeInJson(); |
|
48
|
|
|
$response->shouldContainJsonKey('message'); |
|
49
|
|
|
$response->shouldContainJsonKeyWithValue('message', 'The page you requested'); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
public function its_notFoundAction_should_handle_404_response( |
|
53
|
|
|
Request $request |
|
54
|
|
|
) { |
|
55
|
|
|
$response = $this->notFoundAction(); |
|
56
|
|
|
$response->shouldBeInJson(); |
|
57
|
|
|
$response->shouldHaveStatusCode(404); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
public function its_methodUnsupported_should_handle_unsupported_method( |
|
61
|
|
|
Request $request |
|
62
|
|
|
) { |
|
63
|
|
|
$request->get('action')->willReturn('action'); |
|
64
|
|
|
$request->getMethod()->willReturn('GET'); |
|
65
|
|
|
$response = $this->unsupportedMethodAction($request, Request::METHOD_POST); |
|
66
|
|
|
$response->shouldBeInJson(); |
|
67
|
|
|
$response->shouldHaveStatusCode(Response::HTTP_METHOD_NOT_ALLOWED); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
public function its_initAction_only_accept_post_method( |
|
71
|
|
|
Request $request |
|
72
|
|
|
) { |
|
73
|
|
|
$request->isMethod('POST')->willReturn(false); |
|
74
|
|
|
$request->getMethod()->willReturn('GET'); |
|
75
|
|
|
$request->get('action')->willReturn('init'); |
|
76
|
|
|
|
|
77
|
|
|
$response = $this->initAction($request); |
|
78
|
|
|
$response->shouldBeInJson(); |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
public function its_initAction_should_init_new_coverage_session( |
|
82
|
|
|
Request $request |
|
83
|
|
|
) { |
|
84
|
|
|
$config = [ |
|
85
|
|
|
'filterOptions' => [ |
|
86
|
|
|
'whitelistedFiles' => [ |
|
87
|
|
|
__FILE__, |
|
88
|
|
|
], |
|
89
|
|
|
], |
|
90
|
|
|
'codeCoverageOptions' => [ |
|
91
|
|
|
'addUncoveredFilesFromWhitelist' => true, |
|
92
|
|
|
], |
|
93
|
|
|
]; |
|
94
|
|
|
|
|
95
|
|
|
$data = json_encode($config); |
|
96
|
|
|
|
|
97
|
|
|
$request->get('session')->shouldBeCalled()->willReturn('spec-remote'); |
|
98
|
|
|
$request->getContent()->willReturn($data); |
|
99
|
|
|
$request->isMethod('POST')->shouldBeCalled()->willReturn(true); |
|
100
|
|
|
$request->headers = new HeaderBag(); |
|
101
|
|
|
|
|
102
|
|
|
$response = $this->initAction($request); |
|
103
|
|
|
$response->shouldBeInJson(); |
|
104
|
|
|
$response->shouldContainJsonKey('message'); |
|
105
|
|
|
$response->shouldContainJsonKeyWithValue('message', 'coverage session: spec-remote initialized.'); |
|
106
|
|
|
$response->shouldHaveStatusCode(Response::HTTP_ACCEPTED); |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
|
|
public function its_readAction_only_accept_get_method( |
|
110
|
|
|
Request $request |
|
111
|
|
|
) { |
|
112
|
|
|
$request->get('action')->willReturn('read'); |
|
113
|
|
|
$request->getMethod()->willReturn('POST'); |
|
114
|
|
|
$request->isMethod('GET')->willReturn(false); |
|
115
|
|
|
|
|
116
|
|
|
$response = $this->readAction($request); |
|
117
|
|
|
$response->shouldBeInJson(); |
|
118
|
|
|
$response->shouldHaveStatusCode(Response::HTTP_METHOD_NOT_ALLOWED); |
|
119
|
|
|
} |
|
120
|
|
|
|
|
121
|
|
|
public function its_readAction_will_not_process_undefined_session( |
|
122
|
|
|
Request $request |
|
123
|
|
|
) { |
|
124
|
|
|
$request->isMethod('GET')->willReturn(true); |
|
125
|
|
|
$request->get('session')->willReturn(null); |
|
126
|
|
|
|
|
127
|
|
|
$response = $this->readAction($request); |
|
128
|
|
|
$response->shouldBeInJson(); |
|
129
|
|
|
$response->shouldHaveStatusCode(404); |
|
130
|
|
|
} |
|
131
|
|
|
|
|
132
|
|
|
public function its_readAction_will_not_process_uninitialized_session( |
|
133
|
|
|
Request $request |
|
134
|
|
|
) { |
|
135
|
|
|
$request->isMethod('GET')->willReturn(true); |
|
136
|
|
|
$request->get('session')->willReturn('uninitialized'); |
|
137
|
|
|
|
|
138
|
|
|
$response = $this->readAction($request); |
|
139
|
|
|
$response->shouldBeInJson(); |
|
140
|
|
|
$response->shouldHaveStatusCode(404); |
|
141
|
|
|
} |
|
142
|
|
|
|
|
143
|
|
|
public function its_readAction_returns_code_coverage_data( |
|
144
|
|
|
Request $request, |
|
145
|
|
|
ProcessorInterface $processor, |
|
146
|
|
|
SessionInterface $session |
|
147
|
|
|
) { |
|
148
|
|
|
$codeCoverage = new CodeCoverage(new Dummy()); |
|
149
|
|
|
$processor->getCodeCoverage()->willReturn($codeCoverage); |
|
150
|
|
|
$session->getProcessor()->willReturn($processor); |
|
|
|
|
|
|
151
|
|
|
$processor->getCodeCoverage()->willReturn($codeCoverage); |
|
152
|
|
|
|
|
153
|
|
|
$request->isMethod('GET')->willReturn(true); |
|
154
|
|
|
$request |
|
155
|
|
|
->get('session') |
|
156
|
|
|
->willReturn('spec-remote') |
|
157
|
|
|
->shouldBeCalled(); |
|
158
|
|
|
|
|
159
|
|
|
$response = $this->readAction($request); |
|
160
|
|
|
$response->shouldBeAHttpResponse(); |
|
161
|
|
|
$response->shouldBeASerializedObject(SessionInterface::class); |
|
162
|
|
|
} |
|
163
|
|
|
} |
|
164
|
|
|
|
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