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