doyolabs /
code-coverage
| 1 | <?php |
||
| 2 | |||
| 3 | /* |
||
| 4 | * This file is part of the doyo/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 | ]; |
||
| 38 | |||
| 39 | $this->taskWatch() |
||
| 40 | ->monitor( |
||
| 41 | $paths, |
||
| 42 | function (FilesystemEvent $event) use ($options) { |
||
| 43 | $resource = (string) $event->getResource(); |
||
| 44 | if ( |
||
| 45 | false !== strpos($resource, 'build') |
||
| 46 | || false !== strpos($resource, 'var') |
||
| 47 | ) { |
||
| 48 | return; |
||
| 49 | } |
||
| 50 | $this->test($options); |
||
| 51 | }, |
||
| 52 | FilesystemEvent::ALL |
||
| 53 | ) |
||
| 54 | ->run(); |
||
| 55 | } |
||
| 56 | |||
| 57 | public function test() |
||
| 58 | { |
||
| 59 | $this->taskExec('clear')->run(); |
||
| 60 | |||
| 61 | if ($this->coverage) { |
||
| 62 | $this->taskFilesystemStack() |
||
| 63 | ->mkdir(__DIR__.'/build', 0775) |
||
| 64 | ->mkdir(__DIR__.'/build/cov', 0775) |
||
| 65 | ->run(); |
||
| 66 | } |
||
| 67 | |||
| 68 | /** @var \Robo\Result[] $results */ |
||
| 69 | $results = []; |
||
| 70 | $results[] = $this->configurePhpSpec()->run(); |
||
| 71 | |||
| 72 | if (!$this->watch) { |
||
| 73 | $results[] = $this->configureBehat()->run(); |
||
| 74 | } |
||
| 75 | |||
| 76 | $hasError = false; |
||
| 77 | foreach ($results as $result) { |
||
| 78 | if (0 !== $result->getExitCode()) { |
||
| 79 | $hasError = true; |
||
| 80 | } |
||
| 81 | } |
||
| 82 | |||
| 83 | if ($this->coverage) { |
||
| 84 | $this->mergeCoverage(); |
||
| 85 | } |
||
| 86 | |||
| 87 | if (!$this->watch) { |
||
| 88 | if ($hasError) { |
||
| 89 | throw new \Robo\Exception\TaskException($this, 'Tests failed'); |
||
|
0 ignored issues
–
show
|
|||
| 90 | } |
||
| 91 | } |
||
| 92 | } |
||
| 93 | |||
| 94 | public function coverage() |
||
| 95 | { |
||
| 96 | $this->coverage = true; |
||
| 97 | $this->test(); |
||
| 98 | } |
||
| 99 | |||
| 100 | public function mergeCoverage() |
||
| 101 | { |
||
| 102 | $this |
||
| 103 | ->taskExec('phpdbg -qrr ./vendor/bin/phpcov') |
||
| 104 | ->arg('merge') |
||
| 105 | ->option('clover', 'build/logs/clover.xml') |
||
| 106 | ->option('html', 'build/html') |
||
| 107 | ->option('ansi') |
||
| 108 | ->arg('build/cov') |
||
| 109 | ->run(); |
||
| 110 | } |
||
| 111 | |||
| 112 | /** |
||
| 113 | * @return \Robo\Task\Base\Exec|\Robo\Task\Testing\Behat |
||
| 114 | */ |
||
| 115 | private function configureBehat() |
||
| 116 | { |
||
| 117 | $task = $this->taskBehat(); |
||
| 118 | $task->noInteraction() |
||
| 119 | ->format('progress') |
||
| 120 | ->colors(); |
||
| 121 | |||
| 122 | if ($this->coverage) { |
||
| 123 | $task->option('coverage'); |
||
| 124 | $command = $task->getCommand(); |
||
| 125 | $task = $this->taskExec('phpdbg -qrr '.$command); |
||
| 126 | } else { |
||
| 127 | $task->option('tags', '~@coverage && ~@remote'); |
||
| 128 | } |
||
| 129 | |||
| 130 | return $task; |
||
| 131 | } |
||
| 132 | |||
| 133 | /** |
||
| 134 | * @return \Robo\Task\Base\Exec|\Robo\Task\Testing\Phpspec |
||
| 135 | */ |
||
| 136 | private function configurePhpSpec() |
||
| 137 | { |
||
| 138 | $task = $this->taskPhpspec(); |
||
| 139 | $task->noCodeGeneration() |
||
| 140 | ->noInteraction() |
||
| 141 | ->format('dot'); |
||
| 142 | |||
| 143 | if ($this->coverage) { |
||
| 144 | $task->option('coverage'); |
||
| 145 | $task = $this->taskExec('phpdbg -qrr '.$task->getCommand()); |
||
| 146 | } |
||
| 147 | |||
| 148 | return $task; |
||
| 149 | } |
||
| 150 | } |
||
| 151 |
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:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths