doyolabs /
code-coverage
| 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; |
||
| 15 | use Robo\Tasks; |
||
| 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); |
||
| 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'); |
||
| 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('php', 'build/all.cov') |
||
| 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 |
||
| 119 | */ |
||
| 120 | private function configureBehat() |
||
|
0 ignored issues
–
show
|
|||
| 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 |
||
| 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. 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
|
|||
| 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 |
This check looks for private methods that have been defined, but are not used inside the class.