SessionSpec   A
last analyzed

Complexity

Total Complexity 15

Size/Duplication

Total Lines 164
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 80
dl 0
loc 164
rs 10
c 0
b 0
f 0
wmc 15

15 Methods

Rating   Name   Duplication   Size   Complexity  
A its_exceptions_should_be_mutable() 0 7 1
A its_start_should_not_process_with_null_testCase() 0 7 1
A its_start_should_handle_coverage_start_error() 0 13 1
A it_is_initializable() 0 3 1
A let() 0 9 1
A it_should_handle_error_during_coverage_stop() 0 13 1
A its_should_stop_coverage_during_shutdown() 0 11 1
A it_should_create_and_reset_session() 0 12 1
A it_should_start_and_stop_code_coverage() 0 23 1
A its_name_should_be_mutable() 0 3 1
A its_stop_should_handle_coverage_stop_error() 0 14 1
A it_should_be_serializable() 0 3 1
A its_xdebugPatch_should_be_mutable() 0 5 1
A its_cache_adapter_should_be_mutable() 0 6 1
A its_test_case_should_be_mutable() 0 5 1
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;
0 ignored issues
show
Bug introduced by
The type PhpSpec\ObjectBehavior was not found. Maybe you did not declare it correctly or list all dependencies?

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:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
22
use Prophecy\Argument;
0 ignored issues
show
Bug introduced by
The type Prophecy\Argument was not found. Maybe you did not declare it correctly or list all dependencies?

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:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
23
use SebastianBergmann\CodeCoverage\CodeCoverage;
0 ignored issues
show
Bug introduced by
The type SebastianBergmann\CodeCoverage\CodeCoverage was not found. Maybe you did not declare it correctly or list all dependencies?

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:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
24
use SebastianBergmann\CodeCoverage\Filter;
0 ignored issues
show
Bug introduced by
The type SebastianBergmann\CodeCoverage\Filter was not found. Maybe you did not declare it correctly or list all dependencies?

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:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
25
use Symfony\Component\Cache\Adapter\FilesystemAdapter;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\Cache\Adapter\FilesystemAdapter was not found. Maybe you did not declare it correctly or list all dependencies?

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:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
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();
0 ignored issues
show
Bug introduced by
Are you sure the usage of $driver->start(Prophecy\Argument::cetera()) targeting Doyo\Bridge\CodeCoverage...pat\BaseDummy6::start() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
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
0 ignored issues
show
Bug introduced by
Are you sure the usage of $driver->start(Prophecy\Argument::cetera()) targeting Doyo\Bridge\CodeCoverage...pat\BaseDummy6::start() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
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();
0 ignored issues
show
Bug introduced by
Are you sure the usage of $driver->start(Prophecy\Argument::cetera()) targeting Doyo\Bridge\CodeCoverage...pat\BaseDummy6::start() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
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();
0 ignored issues
show
Bug introduced by
Are you sure the usage of $driver->start(Prophecy\Argument::any()) targeting Doyo\Bridge\CodeCoverage...pat\BaseDummy6::start() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
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();
0 ignored issues
show
Bug introduced by
Are you sure the usage of $driver->start(Prophecy\Argument::cetera()) targeting Doyo\Bridge\CodeCoverage...pat\BaseDummy6::start() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
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();
0 ignored issues
show
Bug introduced by
Are you sure the usage of $driver->start(Prophecy\Argument::cetera()) targeting Doyo\Bridge\CodeCoverage...pat\BaseDummy6::start() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
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