Completed
Push — develop ( dc7798...5a6da7 )
by ANTHONIUS
12s queued 10s
created

RoboFile.php (9 issues)

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
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
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
            'features',
40
        ];
41
42
        $this->taskWatch()
43
            ->monitor(
44
                $paths,
45
                function (FilesystemEvent $event) use ($options) {
46
                    $resource = (string) $event->getResource();
47
                    if (
48
                        false !== strpos($resource, 'build')
49
                        || false !== strpos($resource, 'var')
50
                    ) {
51
                        return;
52
                    }
53
                    $this->test($options);
0 ignored issues
show
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

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

This check looks for private methods that have been defined, but are not used inside the class.

Loading history...
160
    {
161
        $task = $this->taskPhpUnit();
162
163
        if ($this->coverage) {
164
            $task = $this->taskExec('phpdbg -qrr '.$task->getCommand());
165
            $task->option('coverage-php', 'build/cov/01-phpunit.cov')
166
                ->option('coverage-html', 'build/phpunit');
167
        }
168
169
        return $task;
170
    }
171
}
172