1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace ParaTest\Console\Commands; |
6
|
|
|
|
7
|
|
|
use Composer\Semver\Comparator; |
8
|
|
|
use ParaTest\Console\Testers\Tester; |
9
|
|
|
use Symfony\Component\Console\Command\Command; |
10
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
11
|
|
|
use Symfony\Component\Console\Input\InputOption; |
12
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
13
|
|
|
|
14
|
|
|
class ParaTestCommand extends Command |
15
|
|
|
{ |
16
|
|
|
/** |
17
|
|
|
* @var \ParaTest\Console\Testers\Tester |
18
|
|
|
*/ |
19
|
|
|
protected $tester; |
20
|
|
|
|
21
|
7 |
|
public function __construct(Tester $tester) |
22
|
|
|
{ |
23
|
7 |
|
parent::__construct('paratest'); |
24
|
7 |
|
$this->tester = $tester; |
25
|
7 |
|
$this->tester->configure($this); |
26
|
7 |
|
} |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @return bool |
30
|
|
|
*/ |
31
|
9 |
|
public static function isWhitelistSupported(): bool |
32
|
|
|
{ |
33
|
9 |
|
return Comparator::greaterThanOrEqualTo(\PHPUnit\Runner\Version::id(), '5.0.0'); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* Ubiquitous configuration options for ParaTest. |
38
|
|
|
*/ |
39
|
7 |
|
protected function configure() |
40
|
|
|
{ |
41
|
|
|
$this |
42
|
7 |
|
->addOption('processes', 'p', InputOption::VALUE_REQUIRED, 'The number of test processes to run.', 5) |
43
|
7 |
|
->addOption('functional', 'f', InputOption::VALUE_NONE, 'Run methods instead of suites in separate processes.') |
44
|
7 |
|
->addOption('no-test-tokens', null, InputOption::VALUE_NONE, 'Disable TEST_TOKEN environment variables. <comment>(default: variable is set)</comment>') |
45
|
7 |
|
->addOption('help', 'h', InputOption::VALUE_NONE, 'Display this help message.') |
46
|
7 |
|
->addOption('coverage-clover', null, InputOption::VALUE_REQUIRED, 'Generate code coverage report in Clover XML format.') |
47
|
7 |
|
->addOption('coverage-html', null, InputOption::VALUE_REQUIRED, 'Generate code coverage report in HTML format.') |
48
|
7 |
|
->addOption('coverage-php', null, InputOption::VALUE_REQUIRED, 'Serialize PHP_CodeCoverage object to file.') |
49
|
7 |
|
->addOption('max-batch-size', 'm', InputOption::VALUE_REQUIRED, 'Max batch size (only for functional mode).', 0) |
50
|
7 |
|
->addOption('filter', null, InputOption::VALUE_REQUIRED, 'Filter (only for functional mode).'); |
51
|
|
|
|
52
|
7 |
|
if (self::isWhitelistSupported()) { |
53
|
7 |
|
$this->addOption('whitelist', null, InputOption::VALUE_REQUIRED, 'Directory to add to the coverage whitelist.'); |
54
|
|
|
} |
55
|
7 |
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* Executes the specified tester. |
59
|
|
|
* |
60
|
|
|
* @param InputInterface $input |
61
|
|
|
* @param OutputInterface $output |
62
|
|
|
* |
63
|
|
|
* @return int|mixed|null |
64
|
|
|
*/ |
65
|
1 |
|
public function execute(InputInterface $input, OutputInterface $output) |
66
|
|
|
{ |
67
|
1 |
|
return $this->tester->execute($input, $output); |
68
|
|
|
} |
69
|
|
|
} |
70
|
|
|
|