|
1
|
|
|
<?php |
|
2
|
|
|
declare(strict_types=1); |
|
3
|
|
|
|
|
4
|
|
|
namespace Paraunit\Command; |
|
5
|
|
|
|
|
6
|
|
|
use Paraunit\Configuration\CoverageConfiguration; |
|
7
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
8
|
|
|
use Symfony\Component\Console\Input\InputOption; |
|
9
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* Class CoverageCommand |
|
13
|
|
|
* @package Paraunit\Command |
|
14
|
|
|
*/ |
|
15
|
|
|
class CoverageCommand extends ParallelCommand |
|
16
|
|
|
{ |
|
17
|
|
|
const COVERAGE_METHODS = [ |
|
18
|
|
|
'clover', |
|
19
|
|
|
'html', |
|
20
|
|
|
'xml', |
|
21
|
9 |
|
'text', |
|
22
|
|
|
'text-to-console', |
|
23
|
9 |
|
'crap4j', |
|
24
|
|
|
'php', |
|
25
|
|
|
]; |
|
26
|
9 |
|
|
|
27
|
|
|
/** |
|
28
|
9 |
|
* ParallelCommand constructor. |
|
29
|
|
|
* @param CoverageConfiguration $configuration |
|
30
|
9 |
|
*/ |
|
31
|
9 |
|
public function __construct(CoverageConfiguration $configuration) |
|
32
|
9 |
|
{ |
|
33
|
9 |
|
parent::__construct($configuration); |
|
34
|
9 |
|
} |
|
35
|
9 |
|
|
|
36
|
9 |
|
protected function configure() |
|
37
|
9 |
|
{ |
|
38
|
9 |
|
parent::configure(); |
|
39
|
|
|
|
|
40
|
|
|
$this->setName('coverage'); |
|
41
|
|
|
$this->setDescription('Fetch the coverage of your tests in parallel'); |
|
42
|
|
|
$this->addOption('clover', null, InputOption::VALUE_REQUIRED, 'Output file for Clover XML coverage result'); |
|
43
|
|
|
$this->addOption('xml', null, InputOption::VALUE_REQUIRED, 'Output dir for PHPUnit XML coverage result'); |
|
44
|
|
|
$this->addOption('html', null, InputOption::VALUE_REQUIRED, 'Output dir for HTML coverage result'); |
|
45
|
|
|
$this->addOption('text', null, InputOption::VALUE_REQUIRED, 'Output file for text coverage result'); |
|
46
|
|
|
$this->addOption('text-to-console', null, InputOption::VALUE_NONE, 'Output text coverage directly to console'); |
|
47
|
|
|
$this->addOption('crap4j', null, InputOption::VALUE_REQUIRED, 'Output file for Crap4j coverage result'); |
|
48
|
|
|
$this->addOption('php', null, InputOption::VALUE_REQUIRED, 'Output file for PHP coverage result'); |
|
49
|
8 |
|
} |
|
50
|
|
|
|
|
51
|
8 |
|
/** |
|
52
|
1 |
|
* @param InputInterface $input |
|
53
|
|
|
* @param OutputInterface $output |
|
54
|
|
|
* |
|
55
|
7 |
|
* @return int|null |
|
56
|
|
|
* |
|
57
|
|
|
* @throws \Exception |
|
58
|
8 |
|
*/ |
|
59
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
|
60
|
8 |
|
{ |
|
61
|
8 |
|
if (! $this->hasChosenCoverageMethod($input)) { |
|
62
|
8 |
|
$coverageMethods = implode(self::COVERAGE_METHODS, ', '); |
|
63
|
8 |
|
|
|
64
|
8 |
|
throw new \InvalidArgumentException('You should choose at least one method of coverage output between ' . $coverageMethods); |
|
65
|
8 |
|
} |
|
66
|
8 |
|
|
|
67
|
|
|
return parent::execute($input, $output); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
private function hasChosenCoverageMethod(InputInterface $input): bool |
|
71
|
|
|
{ |
|
72
|
|
|
foreach (self::COVERAGE_METHODS as $coverageMethod) { |
|
73
|
|
|
if ($input->getOption($coverageMethod)) { |
|
74
|
|
|
return true; |
|
75
|
|
|
} |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
return false; |
|
79
|
|
|
} |
|
80
|
|
|
} |
|
81
|
|
|
|