Completed
Push — develop ( 2faf16...be2583 )
by ANTHONIUS
15s queued 11s
created

RoboFile::mergeCoverage()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 9
nc 1
nop 0
dl 0
loc 11
rs 9.9666
c 1
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
/*
15
 * This file is part of the doyo/behat-code-coverage project.
16
 *
17
 * (c) Anthonius Munthi <[email protected]>
18
 *
19
 * For the full copyright and license information, please view the LICENSE
20
 * file that was distributed with this source code.
21
 */
22
23
use Lurker\Event\FilesystemEvent;
0 ignored issues
show
Bug introduced by
The type Lurker\Event\FilesystemEvent 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
use Robo\Tasks;
0 ignored issues
show
Bug introduced by
The type Robo\Tasks 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...
25
26
/**
27
 * This is project's console commands configuration for Robo task runner.
28
 *
29
 * @see http://robo.li/
30
 */
31
class RoboFile extends Tasks
32
{
33
    private $coverage = false;
34
35
    private $watch = false;
36
37
    /**
38
     * @param array $options
39
     */
40
    public function watch($options = ['coverage' => false])
41
    {
42
        $this->watch = true;
43
44
        $paths = [
45
            'src',
46
            'tests',
47
            'spec',
48
            'features',
49
        ];
50
51
        $this->taskWatch()
52
            ->monitor(
53
                $paths,
54
                function (FilesystemEvent $event) use ($options) {
55
                    $resource = (string) $event->getResource();
56
                    if (
57
                        false !== strpos($resource, 'build')
58
                        || false !== strpos($resource, 'var')
59
                    ) {
60
                        return;
61
                    }
62
                    $this->test($options);
0 ignored issues
show
Unused Code introduced by
The call to RoboFile::test() has too many arguments starting with $options. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

62
                    $this->/** @scrutinizer ignore-call */ 
63
                           test($options);

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
63
                },
64
                FilesystemEvent::ALL
65
            )
66
            ->run();
67
    }
68
69
    public function test()
70
    {
71
        $this->taskExec('clear')->run();
72
73
        if ($this->coverage) {
74
            $this->taskFilesystemStack()
75
                ->mkdir(__DIR__.'/build', 0775)
76
                ->mkdir(__DIR__.'/build/cov', 0775)
77
                ->run();
78
        }
79
80
        /** @var \Robo\Result[] $results */
81
        $results   = [];
82
        $results[] = $this->configurePhpSpec()->run();
83
        $results[] = $this->configurePhpUnit()->run();
84
85
        if (!$this->watch) {
86
            $results[] = $this->configureBehat()->run();
87
        }
88
89
        $hasError = false;
90
        foreach ($results as $result) {
91
            if (0 !== $result->getExitCode()) {
92
                $hasError = true;
93
            }
94
        }
95
96
        if ($this->coverage) {
97
            $this->mergeCoverage();
98
        }
99
100
        if (!$this->watch) {
101
            if ($hasError) {
102
                throw new \Robo\Exception\TaskException($this, 'Tests failed');
0 ignored issues
show
Bug introduced by
The type Robo\Exception\TaskException 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...
103
            }
104
        }
105
    }
106
107
    public function coverage()
108
    {
109
        $this->coverage = true;
110
        $this->test();
111
    }
112
113
    public function mergeCoverage()
114
    {
115
        $this
116
            ->taskExec('phpdbg -qrr ./vendor/bin/phpcov')
117
            ->arg('merge')
118
            ->option('clover', 'build/logs/clover.xml')
119
            ->option('html', 'build/html')
120
            ->option('text')
121
            ->option('ansi')
122
            ->arg('build/cov')
123
            ->run();
124
    }
125
126
    /**
127
     * @return \Robo\Task\Base\Exec|\Robo\Task\Testing\Behat
0 ignored issues
show
Bug introduced by
The type Robo\Task\Base\Exec 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...
Bug introduced by
The type Robo\Task\Testing\Behat 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...
128
     */
129
    private function configureBehat()
130
    {
131
        $task = $this->taskBehat();
132
        $task->noInteraction()
133
            ->format('progress')
134
            ->colors();
135
136
        if ($this->coverage) {
137
            $task->option('coverage');
138
            $command = $task->getCommand();
139
            $task    = $this->taskExec('phpdbg -qrr '.$command);
140
        } else {
141
            $task->option('tags', '~@remote');
142
        }
143
144
        return $task;
145
    }
146
147
    /**
148
     * @return \Robo\Task\Base\Exec|\Robo\Task\Testing\Phpspec
0 ignored issues
show
Bug introduced by
The type Robo\Task\Testing\Phpspec 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...
149
     */
150
    private function configurePhpSpec()
151
    {
152
        $task = $this->taskPhpspec();
153
        $task->noCodeGeneration()
154
            ->noInteraction()
155
            ->format('dot');
156
157
        if ($this->coverage) {
158
            $task->option('coverage');
159
            $task = $this->taskExec('phpdbg -qrr '.$task->getCommand());
160
        }
161
162
        return $task;
163
    }
164
165
    /**
166
     * @return \Robo\Task\Base\Exec|\Robo\Task\Testing\PHPUnit
0 ignored issues
show
Bug introduced by
The type Robo\Task\Testing\PHPUnit 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...
167
     */
168
    private function configurePhpUnit()
169
    {
170
        $task = $this->taskPhpUnit();
171
172
        if ($this->coverage) {
173
            $task = $this->taskExec('phpdbg -qrr '.$task->getCommand());
174
            $task->option('coverage-php', 'build/cov/01-phpunit.cov')
175
                ->option('coverage-html', 'build/phpunit');
176
        }
177
178
        return $task;
179
    }
180
}
181