Completed
Pull Request — master (#214)
by Mikhail
04:39
created

BaseRunner::addCoverageFromFile()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 13
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 4.25

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 13
ccs 6
cts 8
cp 0.75
rs 9.2
cc 4
eloc 7
nc 3
nop 1
crap 4.25
1
<?php
2
3
namespace ParaTest\Runners\PHPUnit;
4
5
use ParaTest\Coverage\CoverageMerger;
6
use ParaTest\Coverage\CoverageReporter3;
7
use ParaTest\Logging\LogInterpreter;
8
use ParaTest\Logging\JUnit\Writer;
9
use PHP_CodeCoverage_Report_Clover;
10
use PHP_CodeCoverage_Report_HTML;
11
use PHP_CodeCoverage_Report_PHP;
12
use RuntimeException;
13
14
abstract class BaseRunner
15
{
16
    const PHPUNIT_FATAL_ERROR = 255;
17
18
    /**
19
     * @var Options
20
     */
21
    protected $options;
22
23
    /**
24
     * @var \ParaTest\Logging\LogInterpreter
25
     */
26
    protected $interpreter;
27
28
    /**
29
     * @var ResultPrinter
30
     */
31
    protected $printer;
32
33
    /**
34
     * A collection of pending ExecutableTest objects that have
35
     * yet to run
36
     *
37
     * @var array
38
     */
39
    protected $pending = array();
40
41
    /**
42
     * A collection of ExecutableTest objects that have processes
43
     * currently running
44
     *
45
     * @var array
46
     */
47
    protected $running = array();
48
49
    /**
50
     * A tallied exit code that returns the highest exit
51
     * code returned out of the entire collection of tests
52
     *
53
     * @var int
54
     */
55
    protected $exitcode = -1;
56
57
    /**
58
     * CoverageMerger to hold track of the accumulated coverage
59
     *
60
     * @var CoverageMerger
61
     */
62
    protected $coverage = null;
63
64
65 8
    public function __construct($opts = array())
66
    {
67 8
        $this->options = new Options($opts);
68 8
        $this->interpreter = new LogInterpreter();
69 8
        $this->printer = new ResultPrinter($this->interpreter);
70 8
    }
71
72 2
    public function run()
73
    {
74 2
        $this->verifyConfiguration();
75 2
        $this->initCoverage();
76 2
        $this->load();
77 2
        $this->printer->start($this->options);
78 2
    }
79
80
    /**
81
     * Ensures a valid configuration was supplied. If not
82
     * causes ParaTest to print the error message and exit immediately
83
     * with an exit code of 1
84
     */
85 2
    protected function verifyConfiguration()
86
    {
87 2
        if (isset($this->options->filtered['configuration']) && !file_exists($this->options->filtered['configuration']->getPath())) {
0 ignored issues
show
Documentation introduced by
The property $filtered is declared protected in ParaTest\Runners\PHPUnit\Options. Since you implemented __get(), maybe consider adding a @property or @property-read annotation. This makes it easier for IDEs to provide auto-completion.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
88 1
            $this->printer->println(sprintf('Could not read "%s".', $this->options->filtered['configuration']));
0 ignored issues
show
Documentation introduced by
The property $filtered is declared protected in ParaTest\Runners\PHPUnit\Options. Since you implemented __get(), maybe consider adding a @property or @property-read annotation. This makes it easier for IDEs to provide auto-completion.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
89
            exit(1);
0 ignored issues
show
Coding Style Compatibility introduced by
The method verifyConfiguration() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
90
        }
91 2
    }
92
93
    /**
94
     * Builds the collection of pending ExecutableTest objects
95
     * to run. If functional mode is enabled $this->pending will
96
     * contain a collection of TestMethod objects instead of Suite
97
     * objects
98
     */
99 2
    protected function load()
100
    {
101 2
        $loader = new SuiteLoader($this->options);
102 2
        $loader->load($this->options->path);
0 ignored issues
show
Documentation introduced by
The property $path is declared protected in ParaTest\Runners\PHPUnit\Options. Since you implemented __get(), maybe consider adding a @property or @property-read annotation. This makes it easier for IDEs to provide auto-completion.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
103 2
        $executables = $this->options->functional ? $loader->getTestMethods() : $loader->getSuites();
0 ignored issues
show
Documentation introduced by
The property $functional is declared protected in ParaTest\Runners\PHPUnit\Options. Since you implemented __get(), maybe consider adding a @property or @property-read annotation. This makes it easier for IDEs to provide auto-completion.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
104 2
        $this->pending = array_merge($this->pending, $executables);
105 2
        foreach ($this->pending as $pending) {
106 2
            $this->printer->addTest($pending);
107 2
        }
108 2
    }
109
110
    /**
111
     * Returns the highest exit code encountered
112
     * throughout the course of test execution
113
     *
114
     * @return int
115
     */
116 1
    public function getExitCode()
117
    {
118 1
        return $this->exitcode;
119
    }
120
121
    /**
122
     * Write output to JUnit format if requested
123
     */
124 2
    protected function log()
125
    {
126 2
        if (!isset($this->options->filtered['log-junit'])) {
0 ignored issues
show
Documentation introduced by
The property $filtered is declared protected in ParaTest\Runners\PHPUnit\Options. Since you implemented __get(), maybe consider adding a @property or @property-read annotation. This makes it easier for IDEs to provide auto-completion.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
127 1
            return;
128
        }
129 1
        $output = $this->options->filtered['log-junit'];
0 ignored issues
show
Documentation introduced by
The property $filtered is declared protected in ParaTest\Runners\PHPUnit\Options. Since you implemented __get(), maybe consider adding a @property or @property-read annotation. This makes it easier for IDEs to provide auto-completion.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
130 1
        $writer = new Writer($this->interpreter, $this->options->path);
0 ignored issues
show
Documentation introduced by
The property $path is declared protected in ParaTest\Runners\PHPUnit\Options. Since you implemented __get(), maybe consider adding a @property or @property-read annotation. This makes it easier for IDEs to provide auto-completion.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
131 1
        $writer->write($output);
132 1
    }
133
134
    /**
135
     * Write coverage to file if requested
136
     */
137 2
    protected function logCoverage()
138
    {
139 2
        if (!$this->hasCoverage()) {
140 2
            return;
141 2
        }
142
143 2
        $filteredOptions = $this->options->filtered;
0 ignored issues
show
Documentation introduced by
The property $filtered is declared protected in ParaTest\Runners\PHPUnit\Options. Since you implemented __get(), maybe consider adding a @property or @property-read annotation. This makes it easier for IDEs to provide auto-completion.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
144
145 2
        $reporter = $this->getCoverage()->getReporter();
146
147 2
        if (isset($filteredOptions['coverage-clover'])) {
148
            $reporter->clover($filteredOptions['coverage-clover']);
149
        }
150
151 2
        if (isset($filteredOptions['coverage-html'])) {
152
            $reporter->html($filteredOptions['coverage-html']);
153
        }
154
155 2
        $reporter->php($filteredOptions['coverage-php']);
156 2
    }
157
158 2
    protected function initCoverage()
159
    {
160 2
        if (!isset($this->options->filtered['coverage-php'])) {
0 ignored issues
show
Documentation introduced by
The property $filtered is declared protected in ParaTest\Runners\PHPUnit\Options. Since you implemented __get(), maybe consider adding a @property or @property-read annotation. This makes it easier for IDEs to provide auto-completion.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
161
            return;
162
        }
163
164 2
        $this->coverage = new CoverageMerger();
165 2
    }
166
167
    /**
168
     * @return bool
169
     */
170 2
    protected function hasCoverage()
171
    {
172 2
        return $this->getCoverage() !== null;
173
    }
174
175
    /**
176
     * @return CoverageMerger
177
     */
178 2
    protected function getCoverage()
179
    {
180 2
        return $this->coverage;
181
    }
182
183
}
184