Passed
Pull Request — master (#3)
by ANTHONIUS
04:17
created

RoboFile::configurePhpSpec()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 13
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 8
nc 2
nop 0
dl 0
loc 13
rs 10
c 1
b 0
f 0
1
<?php
2
3
/*
4
 * This file is part of the doyo/behat-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
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...
15
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...
16
17
/**
18
 * This is project's console commands configuration for Robo task runner.
19
 *
20
 * @see http://robo.li/
21
 */
22
class RoboFile extends Tasks
23
{
24
    private $coverage = false;
25
26
    private $watch = false;
27
28
    /**
29
     * @param array $options
30
     */
31
    public function watch($options = ['coverage' => false])
32
    {
33
        $this->watch = true;
34
35
        $paths = [
36
            'src',
37
            'tests',
38
            'spec',
39
        ];
40
41
        $this->taskWatch()
42
            ->monitor(
43
                $paths,
44
                function (FilesystemEvent $event) use ($options) {
45
                    $resource = (string) $event->getResource();
46
                    if (
47
                        false !== strpos($resource, 'build')
48
                        || false !== strpos($resource, 'var')
49
                    ) {
50
                        return;
51
                    }
52
                    $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

52
                    $this->/** @scrutinizer ignore-call */ 
53
                           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...
53
                },
54
                FilesystemEvent::ALL
55
            )
56
            ->run();
57
    }
58
59
    public function test()
60
    {
61
        $this->taskExec('clear')->run();
62
63
        if ($this->coverage) {
64
            $this->taskFilesystemStack()
65
                ->mkdir(__DIR__.'/build', 0775)
66
                ->mkdir(__DIR__.'/build/cov', 0775)
67
                ->run();
68
        }
69
70
        /** @var \Robo\Result[] $results */
71
        $results   = [];
72
        $results[] = $this->configurePhpSpec()->run();
73
        //$results[] = $this->configurePhpUnit()->run();
74
75
        if (!$this->watch) {
76
            $results[] = $this->configureBehat()->run();
77
        }
78
79
        $hasError = false;
80
        foreach ($results as $result) {
81
            if (0 !== $result->getExitCode()) {
82
                $hasError = true;
83
            }
84
        }
85
86
        if ($this->coverage) {
87
            $this->mergeCoverage();
88
        }
89
90
        if (!$this->watch) {
91
            if ($hasError) {
92
                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...
93
            }
94
        }
95
    }
96
97
    public function coverage()
98
    {
99
        $this->coverage = true;
100
        $this->test();
101
    }
102
103
    public function mergeCoverage()
104
    {
105
        $this
106
            ->taskExec('phpdbg -qrr ./vendor/bin/phpcov')
107
            ->arg('merge')
108
            ->option('clover', 'build/logs/clover.xml')
109
            ->option('html', 'build/html')
110
            ->option('ansi')
111
            ->arg('build/cov')
112
            ->run();
113
    }
114
115
    /**
116
     * @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...
117
     */
118
    private function configureBehat()
119
    {
120
        $task = $this->taskBehat();
121
        $task->noInteraction()
122
            ->format('progress')
123
            ->colors();
124
125
        if ($this->coverage) {
126
            $task->option('coverage');
127
            $command = $task->getCommand();
128
            $task    = $this->taskExec('phpdbg -qrr '.$command);
129
        } else {
130
            $task->option('tags', '~@coverage && ~@remote');
131
        }
132
133
        return $task;
134
    }
135
136
    /**
137
     * @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...
138
     */
139
    private function configurePhpSpec()
140
    {
141
        $task = $this->taskPhpspec();
142
        $task->noCodeGeneration()
143
            ->noInteraction()
144
            ->format('dot');
145
146
        if ($this->coverage) {
147
            $task->option('coverage');
148
            $task = $this->taskExec('phpdbg -qrr '.$task->getCommand());
149
        }
150
151
        return $task;
152
    }
153
}
154