Issues (142)

Spec/Session/RemoteSessionSpec.php (4 issues)

Labels
Severity
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\Processor;
17
use Doyo\Bridge\CodeCoverage\ProcessorInterface;
18
use Doyo\Bridge\CodeCoverage\Session\RemoteSession;
19
use Doyo\Bridge\CodeCoverage\TestCase;
20
use PhpSpec\Exception\Example\SkippingException;
0 ignored issues
show
The type PhpSpec\Exception\Example\SkippingException 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...
21
use PhpSpec\ObjectBehavior;
0 ignored issues
show
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 SebastianBergmann\CodeCoverage\Filter;
0 ignored issues
show
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...
23
use SebastianBergmann\Environment\Runtime;
0 ignored issues
show
The type SebastianBergmann\Environment\Runtime 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
25
class RemoteSessionSpec extends ObjectBehavior
26
{
27
    public function let(
28
        ProcessorInterface $processor
29
    ) {
30
        $filter = new Filter();
31
        $this->beConstructedWith('spec-remote');
32
        $processor->getCodeCoverageOptions()->willReturn([]);
33
        $processor->getCodeCoverageFilter()->willReturn($filter);
34
        $processor->clear()->willReturn(null);
35
        $this->setProcessor($processor);
36
    }
37
38
    public function it_is_initializable()
39
    {
40
        $this->shouldHaveType(RemoteSession::class);
41
    }
42
43
    public function it_should_init_coverage_session()
44
    {
45
        $config =[
46
            'filterOptions' => [
47
                'whitelistedFiles' => [
48
                    __FILE__ => true,
49
                ],
50
            ],
51
            'codeCoverageOptions' => [
52
                'addUncoveredFilesFromWhitelist' => false,
53
            ],
54
        ];
55
        $this->init($config);
56
        $processor = $this->getProcessor();
57
        $processor->shouldHaveType(Processor::class);
58
        $processor->getCodeCoverageOptions()->shouldHaveKeyWithValue('addUncoveredFilesFromWhitelist', false);
59
        $processor->getCodeCoverageFilter()->shouldHaveType(Filter::class);
60
        $processor->getCodeCoverageFilter()->getWhitelistedFiles()->shouldHaveKeyWithValue(__FILE__, true);
61
    }
62
63
    public function it_should_start_new_session(
64
        ProcessorInterface $processor
65
    ) {
66
        $runtime = new Runtime();
67
        if (!$runtime->canCollectCodeCoverage()) {
68
            throw new SkippingException('not in phpdbg or xdebug');
69
        }
70
71
        $_SERVER[RemoteSession::HEADER_SESSION_KEY]   = 'spec-remote';
72
        $_SERVER[RemoteSession::HEADER_TEST_CASE_KEY] = 'spec-test-case';
73
74
        $filter = new Filter();
75
        $processor->getCodeCoverageFilter()->willReturn($filter);
76
        $this->setProcessor($processor);
77
        $this->save();
78
79
        $this->startSession()->shouldReturn(true);
80
        $this->refresh();
81
        $this->getName()->shouldReturn('spec-remote');
82
        $this->getTestCase()->shouldHaveType(TestCase::class);
83
        $this->getTestCase()->getName()->shouldReturn('spec-test-case');
84
    }
85
86
    public function it_should_not_start_session_with_undefined_session()
87
    {
88
        $this->reset();
89
        unset($_SERVER[RemoteSession::HEADER_SESSION_KEY]);
90
        unset($_SERVER[RemoteSession::HEADER_TEST_CASE_KEY]);
91
        $this->startSession()->shouldBe(false);
92
93
        $_SERVER[RemoteSession::HEADER_SESSION_KEY] = 'spec-remote';
94
95
        $this->startSession()->shouldBe(false);
96
    }
97
98
    public function its_doStartSession_should_start_coverage()
99
    {
100
        $runtime = new Runtime();
101
        if (!$runtime->canCollectCodeCoverage()) {
102
            throw new SkippingException('not in phpdbg or xdebug');
103
        }
104
105
        $this->reset();
106
        $_SERVER[RemoteSession::HEADER_SESSION_KEY]   = 'spec-remote';
107
        $_SERVER[RemoteSession::HEADER_TEST_CASE_KEY] = 'test-case';
108
109
        $this->doStartSession();
110
        $this->save();
111
        $this->refresh();
112
        $this->getTestCase()->shouldBeAnInstanceOf(TestCase::class);
113
    }
114
115
    public function its_doStartSession_should_start_coverage_error(
116
        ProcessorInterface $processor
117
    ) {
118
        $this->reset();
119
        $_SERVER[RemoteSession::HEADER_SESSION_KEY]   = 'spec-remote';
120
        $_SERVER[RemoteSession::HEADER_TEST_CASE_KEY] = 'test-case';
121
122
        $e = new \Exception('some error');
123
        $processor->getCodeCoverageFilter()->willThrow($e);
124
        $this->hasExceptions()->shouldBe(false);
125
        $this->doStartSession();
126
        $this->hasExceptions()->shouldBe(true);
127
    }
128
}
129