Completed
Pull Request — master (#217)
by
unknown
03:02
created

BaseRunner   A

Complexity

Total Complexity 20

Size/Duplication

Total Lines 182
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Test Coverage

Coverage 65%

Importance

Changes 7
Bugs 2 Features 1
Metric Value
wmc 20
c 7
b 2
f 1
lcom 1
cbo 6
dl 0
loc 182
ccs 39
cts 60
cp 0.65
rs 10

10 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A run() 0 12 2
A verifyConfiguration() 0 7 3
A load() 0 10 3
A getExitCode() 0 4 1
A log() 0 9 2
A logCoverage() 0 20 4
A initCoverage() 0 8 2
A hasCoverage() 0 4 1
A getCoverage() 0 4 1
1
<?php
2
3
namespace ParaTest\Runners\PHPUnit;
4
5
use ParaTest\Coverage\CoverageMerger;
6
use ParaTest\Logging\LogInterpreter;
7
use ParaTest\Logging\JUnit\Writer;
8
9
abstract class BaseRunner
10
{
11
    const PHPUNIT_FATAL_ERROR = 255;
12
13
    /**
14
     * @var Options
15
     */
16
    protected $options;
17
18
    /**
19
     * @var \ParaTest\Logging\LogInterpreter
20
     */
21
    protected $interpreter;
22
23
    /**
24
     * @var ResultPrinter
25
     */
26
    protected $printer;
27
28
    /**
29
     * A collection of pending ExecutableTest objects that have
30
     * yet to run
31
     *
32
     * @var array
33
     */
34
    protected $pending = array();
35
36
    /**
37
     * A collection of ExecutableTest objects that have processes
38
     * currently running
39
     *
40
     * @var array
41
     */
42
    protected $running = array();
43
44
    /**
45
     * A tallied exit code that returns the highest exit
46
     * code returned out of the entire collection of tests
47
     *
48
     * @var int
49
     */
50
    protected $exitcode = -1;
51
52
    /**
53
     * CoverageMerger to hold track of the accumulated coverage
54
     *
55
     * @var CoverageMerger
56
     */
57
    protected $coverage = null;
58
59
    /**
60
     * Indicates whether the starting messages were printed or not.
61
     *
62
     * @var bool
63
     */
64
    protected $starting_messages_printed = false;
65
66
67 8
    public function __construct($opts = array())
68
    {
69 8
        $this->options = new Options($opts);
70 8
        $this->interpreter = new LogInterpreter();
71 8
        $this->printer = new ResultPrinter($this->interpreter);
72 8
    }
73
74 2
    public function run()
75
    {
76 2
        $this->verifyConfiguration();
77 2
        $this->initCoverage();
78 2
        $this->load();
79
80
        // Print the starting messages only if they were not printed yet.
81 2
        if (!$this->starting_messages_printed) {
82 2
            $this->printer->start($this->options);
83 2
            $this->starting_messages_printed = true;
84 2
        }
85 2
    }
86
87
    /**
88
     * Ensures a valid configuration was supplied. If not
89
     * causes ParaTest to print the error message and exit immediately
90
     * with an exit code of 1
91
     */
92 2
    protected function verifyConfiguration()
93
    {
94 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...
95
            $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...
96
            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...
97
        }
98 2
    }
99
100
    /**
101
     * Builds the collection of pending ExecutableTest objects
102
     * to run. If functional mode is enabled $this->pending will
103
     * contain a collection of TestMethod objects instead of Suite
104
     * objects
105
     */
106 2
    protected function load()
107
    {
108 2
        $loader = new SuiteLoader($this->options);
109 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...
110 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...
111 2
        $this->pending = array_merge($this->pending, $executables);
112 2
        foreach ($this->pending as $pending) {
113 2
            $this->printer->addTest($pending);
114 2
        }
115 2
    }
116
117
    /**
118
     * Returns the highest exit code encountered
119
     * throughout the course of test execution
120
     *
121
     * @return int
122
     */
123 1
    public function getExitCode()
124
    {
125 1
        return $this->exitcode;
126
    }
127
128
    /**
129
     * Write output to JUnit format if requested
130
     */
131
    protected function log()
132
    {
133
        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...
134
            return;
135
        }
136
        $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...
137
        $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...
138
        $writer->write($output);
139
    }
140
141
    /**
142
     * Write coverage to file if requested
143
     */
144 2
    protected function logCoverage()
145 2
    {
146 2
        if (!$this->hasCoverage()) {
147
            return;
148
        }
149
150
        $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...
151
152
        $reporter = $this->getCoverage()->getReporter();
153
154
        if (isset($filteredOptions['coverage-clover'])) {
155
            $reporter->clover($filteredOptions['coverage-clover']);
156
        }
157
158
        if (isset($filteredOptions['coverage-html'])) {
159
            $reporter->html($filteredOptions['coverage-html']);
160
        }
161
162
        $reporter->php($filteredOptions['coverage-php']);
163
    }
164
165 2
    protected function initCoverage()
166
    {
167 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...
168
            return;
169
        }
170
171 2
        $this->coverage = new CoverageMerger();
172 2
    }
173
174
    /**
175
     * @return bool
176
     */
177 2
    protected function hasCoverage()
178
    {
179 2
        return $this->getCoverage() !== null;
180
    }
181
182
    /**
183
     * @return CoverageMerger
184
     */
185 2
    protected function getCoverage()
186
    {
187 2
        return $this->coverage;
188
    }
189
190
}
191