|
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\Session; |
|
15
|
|
|
|
|
16
|
|
|
use Doyo\Bridge\CodeCoverage\Driver\Dummy; |
|
17
|
|
|
use Doyo\Bridge\CodeCoverage\Exception\SessionException; |
|
18
|
|
|
use Doyo\Bridge\CodeCoverage\ProcessorInterface; |
|
19
|
|
|
use Doyo\Bridge\CodeCoverage\Session\Session; |
|
20
|
|
|
use Doyo\Bridge\CodeCoverage\TestCase; |
|
21
|
|
|
use PhpSpec\ObjectBehavior; |
|
|
|
|
|
|
22
|
|
|
use Prophecy\Argument; |
|
|
|
|
|
|
23
|
|
|
use SebastianBergmann\CodeCoverage\CodeCoverage; |
|
|
|
|
|
|
24
|
|
|
use SebastianBergmann\CodeCoverage\Filter; |
|
|
|
|
|
|
25
|
|
|
use Symfony\Component\Cache\Adapter\FilesystemAdapter; |
|
|
|
|
|
|
26
|
|
|
|
|
27
|
|
|
class SessionSpec extends ObjectBehavior |
|
28
|
|
|
{ |
|
29
|
|
|
public function let( |
|
30
|
|
|
ProcessorInterface $processor |
|
31
|
|
|
) { |
|
32
|
|
|
$filter = new Filter(); |
|
33
|
|
|
$this->beAnInstanceOf(TestSession::class); |
|
34
|
|
|
$this->beConstructedWith('spec-test'); |
|
35
|
|
|
$processor->getCodeCoverageFilter()->willReturn($filter); |
|
36
|
|
|
$processor->getCodeCoverageOptions()->willReturn([]); |
|
37
|
|
|
$this->setProcessor($processor); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
public function it_is_initializable() |
|
41
|
|
|
{ |
|
42
|
|
|
$this->shouldHaveType(Session::class); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
public function it_should_be_serializable() |
|
46
|
|
|
{ |
|
47
|
|
|
$this->shouldImplement(\Serializable::class); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
public function its_test_case_should_be_mutable( |
|
51
|
|
|
TestCase $testCase |
|
52
|
|
|
) { |
|
53
|
|
|
$this->setTestCase($testCase)->shouldReturn($this); |
|
54
|
|
|
$this->getTestCase()->shouldReturn($testCase); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
public function its_cache_adapter_should_be_mutable( |
|
58
|
|
|
FilesystemAdapter $adapter |
|
59
|
|
|
) { |
|
60
|
|
|
$this->getAdapter()->shouldHaveType(FilesystemAdapter::class); |
|
61
|
|
|
$this->setAdapter($adapter); |
|
62
|
|
|
$this->getAdapter()->shouldReturn($adapter); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
public function its_name_should_be_mutable() |
|
66
|
|
|
{ |
|
67
|
|
|
$this->getName()->shouldReturn('spec-test'); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
public function its_exceptions_should_be_mutable() |
|
71
|
|
|
{ |
|
72
|
|
|
$exception = new \Exception('some-error'); |
|
73
|
|
|
$this->hasExceptions()->shouldBe(false); |
|
74
|
|
|
$this->addException($exception); |
|
75
|
|
|
$this->hasExceptions()->shouldBe(true); |
|
76
|
|
|
$this->getExceptions()->shouldContain($exception); |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
public function its_xdebugPatch_should_be_mutable() |
|
80
|
|
|
{ |
|
81
|
|
|
$this->getPatchXdebug()->shouldReturn(true); |
|
82
|
|
|
$this->setPatchXdebug(false); |
|
83
|
|
|
$this->getPatchXdebug()->shouldReturn(false); |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
public function it_should_create_and_reset_session( |
|
87
|
|
|
TestCase $testCase, |
|
88
|
|
|
ProcessorInterface $processor |
|
89
|
|
|
) { |
|
90
|
|
|
$processor->clear()->shouldBeCalledOnce(); |
|
91
|
|
|
$this->setProcessor($processor); |
|
92
|
|
|
$this->setTestCase($testCase); |
|
93
|
|
|
$this->save(); |
|
94
|
|
|
$this->getTestCase()->shouldHaveType(TestCase::class); |
|
95
|
|
|
|
|
96
|
|
|
$this->reset(); |
|
97
|
|
|
$this->getTestCase()->shouldBeNull(); |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
public function its_start_should_not_process_with_null_testCase( |
|
101
|
|
|
Dummy $driver |
|
102
|
|
|
) { |
|
103
|
|
|
$this->setTestCase(null); |
|
104
|
|
|
$driver->start(Argument::cetera())->shouldNotBeCalled(); |
|
|
|
|
|
|
105
|
|
|
|
|
106
|
|
|
$this->start($driver->getWrappedObject()); |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
|
|
public function its_start_should_handle_coverage_start_error( |
|
110
|
|
|
Dummy $driver |
|
111
|
|
|
) { |
|
112
|
|
|
$e = new \Exception('some error'); |
|
113
|
|
|
$driver |
|
|
|
|
|
|
114
|
|
|
->start(Argument::cetera()) |
|
115
|
|
|
->shouldBeCalled() |
|
116
|
|
|
->willThrow($e); |
|
117
|
|
|
$testCase = new TestCase('some'); |
|
118
|
|
|
$this->setTestCase($testCase); |
|
119
|
|
|
$this |
|
120
|
|
|
->shouldThrow(SessionException::class) |
|
121
|
|
|
->duringStart($driver); |
|
122
|
|
|
} |
|
123
|
|
|
|
|
124
|
|
|
public function its_stop_should_handle_coverage_stop_error( |
|
125
|
|
|
Dummy $driver |
|
126
|
|
|
) { |
|
127
|
|
|
$e = new \Exception('some error'); |
|
128
|
|
|
$testCase = new TestCase('test-case'); |
|
129
|
|
|
|
|
130
|
|
|
$driver->start(Argument::cetera())->shouldBeCalled(); |
|
|
|
|
|
|
131
|
|
|
$driver->stop()->willThrow($e); |
|
132
|
|
|
|
|
133
|
|
|
$this->setTestCase($testCase); |
|
134
|
|
|
$this->start($driver); |
|
135
|
|
|
$this |
|
136
|
|
|
->shouldThrow(SessionException::class) |
|
137
|
|
|
->duringStop(); |
|
138
|
|
|
} |
|
139
|
|
|
|
|
140
|
|
|
public function it_should_start_and_stop_code_coverage( |
|
141
|
|
|
ProcessorInterface $processor, |
|
142
|
|
|
Dummy $driver, |
|
143
|
|
|
TestCase $testCase |
|
144
|
|
|
) { |
|
145
|
|
|
$options = [ |
|
146
|
|
|
'addUncoveredFilesFromWhitelist' => false, |
|
147
|
|
|
]; |
|
148
|
|
|
$testCase->getName()->shouldBeCalledOnce()->willReturn('some-test'); |
|
149
|
|
|
$processor->merge(Argument::type(CodeCoverage::class)) |
|
150
|
|
|
->shouldBeCalled(); |
|
151
|
|
|
$processor->getCodeCoverageOptions() |
|
152
|
|
|
->willReturn($options); |
|
153
|
|
|
|
|
154
|
|
|
$driver->start(Argument::any())->shouldBeCalledOnce(); |
|
|
|
|
|
|
155
|
|
|
$driver->stop()->shouldBeCalledOnce()->willReturn([]); |
|
156
|
|
|
|
|
157
|
|
|
$this->setProcessor($processor); |
|
158
|
|
|
$this->setTestCase($testCase); |
|
159
|
|
|
$this->start($driver); |
|
160
|
|
|
|
|
161
|
|
|
$this->stop(); |
|
162
|
|
|
$this->hasExceptions()->shouldBe(false); |
|
163
|
|
|
} |
|
164
|
|
|
|
|
165
|
|
|
public function its_should_stop_coverage_during_shutdown( |
|
166
|
|
|
Dummy $driver |
|
167
|
|
|
) { |
|
168
|
|
|
$testCase = new TestCase('test-case'); |
|
169
|
|
|
|
|
170
|
|
|
$driver->start(Argument::cetera())->shouldBeCalledOnce(); |
|
|
|
|
|
|
171
|
|
|
$driver->stop()->willReturn([])->shouldBeCalledOnce(); |
|
172
|
|
|
|
|
173
|
|
|
$this->setTestCase($testCase); |
|
174
|
|
|
$this->start($driver); |
|
175
|
|
|
$this->shutdown(); |
|
176
|
|
|
} |
|
177
|
|
|
|
|
178
|
|
|
public function it_should_handle_error_during_coverage_stop( |
|
179
|
|
|
Dummy $driver |
|
180
|
|
|
) { |
|
181
|
|
|
$e = new \Exception('some error'); |
|
182
|
|
|
|
|
183
|
|
|
$testCase = new TestCase('test-case'); |
|
184
|
|
|
$driver->start(Argument::cetera())->shouldBeCalledOnce(); |
|
|
|
|
|
|
185
|
|
|
$driver->stop()->willThrow($e)->shouldBeCalledOnce(); |
|
186
|
|
|
|
|
187
|
|
|
$this->setTestCase($testCase); |
|
188
|
|
|
$this->start($driver); |
|
189
|
|
|
$this->shutdown(); |
|
190
|
|
|
$this->hasExceptions()->shouldBe(true); |
|
191
|
|
|
} |
|
192
|
|
|
} |
|
193
|
|
|
|
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