Passed
Push — master ( c32af1...923c61 )
by ANTHONIUS
04:29
created

CoverageListenerSpec   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 5
eloc 16
dl 0
loc 45
rs 10
c 0
b 0
f 0
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\PhpSpec\CodeCoverage\Listener;
15
16
use Doyo\Bridge\CodeCoverage\CodeCoverageInterface;
17
use Doyo\Bridge\CodeCoverage\TestCase;
18
use Doyo\PhpSpec\CodeCoverage\Listener\CoverageListener;
19
use PhpSpec\Event\ExampleEvent;
20
use PhpSpec\Loader\Node\ExampleNode;
21
use PhpSpec\Loader\Node\SpecificationNode;
22
use PhpSpec\ObjectBehavior;
23
use Prophecy\Argument;
24
25
/**
26
 * Class CoverageListenerSpec.
27
 *
28
 * @covers \Doyo\PhpSpec\CodeCoverage\Listener\CoverageListener
29
 */
30
class CoverageListenerSpec extends ObjectBehavior
31
{
32
    public function let(CodeCoverageInterface $coverage)
33
    {
34
        $this->beConstructedWith($coverage);
35
    }
36
37
    public function it_is_initializable()
38
    {
39
        $this->shouldHaveType(CoverageListener::class);
40
    }
41
42
    public function its_beforeExample_should_start_coverage(
43
        ExampleEvent $exampleEvent,
44
        SpecificationNode $specification,
45
        ExampleNode $example,
46
        CodeCoverageInterface $coverage
47
    ) {
48
        $exampleEvent->getExample()->willReturn($example);
49
        $example->getSpecification()->willReturn($specification);
50
        $specification->getTitle()->willReturn('spec')->shouldBeCalledOnce();
51
        $example->getTitle()->willReturn('title')->shouldBeCalledOnce();
52
53
        $coverage->start(Argument::type(TestCase::class))
54
            ->shouldBeCalled();
55
        $this->beforeExample($exampleEvent);
56
    }
57
58
    public function its_afterExample_should_stop_coverage(
59
        ExampleEvent $exampleEvent,
60
        CodeCoverageInterface $coverage
61
    ) {
62
        $exampleEvent->getResult()->shouldBeCalled()->willReturn(0);
63
64
        $coverage->setResult(0)->shouldBeCalled();
65
        $coverage->stop()->shouldBeCalled();
66
67
        $this->afterExample($exampleEvent);
68
    }
69
70
    public function its_afterSuite_should_complete_coverage(
71
        CodeCoverageInterface $coverage
72
    ) {
73
        $coverage->complete()->shouldBeCalledOnce();
74
        $this->afterSuite();
75
    }
76
}
77