|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Paraunit\Command; |
|
4
|
|
|
|
|
5
|
|
|
use Paraunit\Configuration\ParallelConfiguration; |
|
6
|
|
|
use Paraunit\Configuration\PHPUnitConfig; |
|
7
|
|
|
use Paraunit\Configuration\PHPUnitOption; |
|
8
|
|
|
use Paraunit\Filter\Filter; |
|
9
|
|
|
use Paraunit\Runner\Runner; |
|
10
|
|
|
use Symfony\Component\Console\Command\Command; |
|
11
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
|
12
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
13
|
|
|
use Symfony\Component\Console\Input\InputOption; |
|
14
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* Class ParallelCommand. |
|
18
|
|
|
*/ |
|
19
|
|
|
class ParallelCommand extends Command |
|
20
|
|
|
{ |
|
21
|
|
|
/** @var ParallelConfiguration */ |
|
22
|
|
|
protected $configuration; |
|
23
|
|
|
|
|
24
|
|
|
/** @var PHPUnitOption[] */ |
|
25
|
|
|
private $phpunitOptions; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* ParallelCommand constructor. |
|
29
|
|
|
* @param ParallelConfiguration $configuration |
|
30
|
|
|
*/ |
|
31
|
10 |
|
public function __construct(ParallelConfiguration $configuration) |
|
32
|
|
|
{ |
|
33
|
10 |
|
$this->phpunitOptions = array( |
|
34
|
10 |
|
new PHPUnitOption('filter'), |
|
35
|
10 |
|
new PHPUnitOption('testsuite'), |
|
36
|
10 |
|
new PHPUnitOption('group'), |
|
37
|
10 |
|
new PHPUnitOption('exclude-group'), |
|
38
|
10 |
|
new PHPUnitOption('test-suffix'), |
|
39
|
|
|
|
|
40
|
10 |
|
new PHPUnitOption('report-useless-tests', false), |
|
41
|
10 |
|
new PHPUnitOption('strict-global-state', false), |
|
42
|
10 |
|
new PHPUnitOption('disallow-test-output', false), |
|
43
|
10 |
|
new PHPUnitOption('enforce-time-limit', false), |
|
44
|
10 |
|
new PHPUnitOption('disallow-todo-tests', false), |
|
45
|
|
|
|
|
46
|
10 |
|
new PHPUnitOption('process-isolation', false), |
|
47
|
10 |
|
new PHPUnitOption('no-globals-backup', false), |
|
48
|
10 |
|
new PHPUnitOption('static-backup', false), |
|
49
|
|
|
|
|
50
|
10 |
|
new PHPUnitOption('loader'), |
|
51
|
10 |
|
new PHPUnitOption('repeat'), |
|
52
|
10 |
|
new PHPUnitOption('printer'), |
|
53
|
|
|
|
|
54
|
10 |
|
new PHPUnitOption('bootstrap'), |
|
55
|
10 |
|
new PHPUnitOption('configuration', true, 'c'), |
|
56
|
10 |
|
new PHPUnitOption('no-configuration'), |
|
57
|
10 |
|
new PHPUnitOption('include-path'), |
|
58
|
|
|
); |
|
59
|
|
|
|
|
60
|
10 |
|
parent::__construct(); |
|
61
|
10 |
|
$this->configuration = $configuration; |
|
62
|
10 |
|
} |
|
63
|
|
|
|
|
64
|
10 |
|
protected function configure() |
|
65
|
|
|
{ |
|
66
|
10 |
|
$this->setName('run'); |
|
67
|
10 |
|
$this->setDescription('Run all the requested tests in parallel'); |
|
68
|
10 |
|
$this->addArgument('stringFilter', InputArgument::OPTIONAL, 'A case-insensitive string to filter tests filename'); |
|
69
|
10 |
|
$this->addOption('parallel', null, InputOption::VALUE_REQUIRED, 'Number of concurrent processes to launch', 10); |
|
70
|
10 |
|
$this->addOption('debug', null, InputOption::VALUE_NONE, 'Print verbose debug output'); |
|
71
|
|
|
|
|
72
|
10 |
|
foreach ($this->phpunitOptions as $option) { |
|
73
|
10 |
|
$this->addOption( |
|
74
|
10 |
|
$option->getName(), |
|
75
|
10 |
|
$option->getShortName(), |
|
76
|
10 |
|
$option->hasValue() ? InputOption::VALUE_OPTIONAL : InputOption::VALUE_NONE, |
|
77
|
10 |
|
'Option carried over to every single PHPUnit process, see PHPUnit docs for usage' |
|
78
|
|
|
); |
|
79
|
|
|
} |
|
80
|
10 |
|
} |
|
81
|
|
|
|
|
82
|
|
|
/** |
|
83
|
|
|
* @param InputInterface $input |
|
84
|
|
|
* @param OutputInterface $output |
|
85
|
|
|
* |
|
86
|
|
|
* @return int|null |
|
87
|
|
|
* |
|
88
|
|
|
* @throws \Exception |
|
89
|
|
|
*/ |
|
90
|
8 |
|
protected function execute(InputInterface $input, OutputInterface $output) |
|
91
|
|
|
{ |
|
92
|
8 |
|
$container = $this->configuration->buildContainer($input); |
|
93
|
|
|
|
|
94
|
|
|
/** @var PHPUnitConfig $config */ |
|
95
|
8 |
|
$config = $container->get('paraunit.configuration.phpunit_config'); |
|
96
|
8 |
|
$this->addPHPUnitOptions($config, $input); |
|
97
|
|
|
|
|
98
|
|
|
/** @var Runner $runner */ |
|
99
|
8 |
|
$runner = $container->get('paraunit.runner.runner'); |
|
100
|
|
|
|
|
101
|
8 |
|
return $runner->run($output, $input->getOption('debug')); |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
/** |
|
105
|
|
|
* @param PHPUnitConfig $config |
|
106
|
|
|
* @param InputInterface $input |
|
107
|
|
|
* @return PHPUnitConfig |
|
108
|
|
|
*/ |
|
109
|
8 |
|
private function addPHPUnitOptions(PHPUnitConfig $config, InputInterface $input) |
|
110
|
|
|
{ |
|
111
|
8 |
|
foreach ($this->phpunitOptions as $option) { |
|
112
|
8 |
|
$cliOption = $input->getOption($option->getName()); |
|
113
|
8 |
|
if ($cliOption) { |
|
114
|
1 |
|
$option->setValue($cliOption); |
|
115
|
8 |
|
$config->addPhpunitOption($option); |
|
116
|
|
|
} |
|
117
|
|
|
} |
|
118
|
|
|
|
|
119
|
8 |
|
return $config; |
|
120
|
|
|
} |
|
121
|
|
|
} |
|
122
|
|
|
|