Passed
Pull Request — develop (#8)
by ANTHONIUS
04:35
created

Processor::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 2
dl 0
loc 4
ccs 3
cts 3
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
/*
4
 * This file is part of the doyo/behat-coverage-extension 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 Doyo\Behat\Coverage\Bridge\CodeCoverage;
15
16
use Doyo\Behat\Coverage\Bridge\Exception\ProcessorException;
17
use SebastianBergmann\CodeCoverage\CodeCoverage;
18
use SebastianBergmann\CodeCoverage\Driver\Driver;
19
use SebastianBergmann\CodeCoverage\Filter;
20
21
/**
22
 * Provide bridge to PHP Code Coverage.
23
 *
24
 * @method        append(array $data, $id = null, $append = true, $linesToBeCovered = [], array $linesToBeUsed = [], $ignoreForceCoversAnnotation = false)
25
 * @method        setAddUncoveredFilesFromWhitelist(bool $flag)
26
 * @method        clear()
27
 * @method array  getTests()
28
 * @method Driver getDriver()
29
 * @method Filter filter()
30
 * @method array  stop(bool $append = true, $linesToBeCovered = [], array $linesToBeUsed = [], bool $ignoreForceCoversAnnotation = false)
31
 */
32
class Processor
33
{
34
    /**
35
     * @var CodeCoverage
36
     */
37
    private $codeCoverage;
38
39
    /**
40
     * @var TestCase[]
41
     */
42
    private $testCases;
43
44
    private $completed = false;
45
46 23
    public function __construct($driver = null, $filter = null)
47
    {
48 23
        $codeCoverage       = new CodeCoverage($driver, $filter);
49 23
        $this->codeCoverage = $codeCoverage;
50
    }
51
52 1
    public function setCodeCoverage(CodeCoverage $codeCoverage)
53
    {
54 1
        $this->codeCoverage = $codeCoverage;
55
    }
56
57
    /**
58
     * @return CodeCoverage
59
     */
60 4
    public function getCodeCoverage()
61
    {
62 4
        return $this->codeCoverage;
63
    }
64
65 3
    public function addTestCase(TestCase $testCase)
66
    {
67 3
        $this->testCases[$testCase->getName()] = $testCase;
68
    }
69
70 3
    public function complete()
71
    {
72 3
        $coverage  = $this->codeCoverage;
73 3
        $testCases = $this->testCases;
74 3
        $tests     = $coverage->getTests();
75
76 3
        foreach ($testCases as $testCase) {
77 3
            $name                   = $testCase->getName();
78 3
            $tests[$name]['status'] = $testCase->getResult();
79
        }
80
81 3
        $coverage->setTests($tests);
82 3
        $this->completed = true;
83
    }
84
85 4
    public function start(TestCase $testCase, $clear = false)
86
    {
87 4
        $this->codeCoverage->start($testCase->getName(), $clear);
88 2
    }
89
90 8
    public function __call($name, $arguments)
91
    {
92 8
        $codeCoverage = $this->codeCoverage;
93 8
        if (method_exists($codeCoverage, $name)) {
94 7
            return \call_user_func_array([$codeCoverage, $name], $arguments);
95
        }
96 1
        throw new ProcessorException('Method name: '.$name.' not supported.');
97
    }
98
}
99