|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
/* |
|
6
|
|
|
* This file is part of the Liip/FunctionalTestBundle |
|
7
|
|
|
* |
|
8
|
|
|
* (c) Lukas Kahwe Smith <[email protected]> |
|
9
|
|
|
* |
|
10
|
|
|
* This source file is subject to the MIT license that is bundled |
|
11
|
|
|
* with this source code in the file LICENSE. |
|
12
|
|
|
*/ |
|
13
|
|
|
|
|
14
|
|
|
namespace Liip\FunctionalTestBundle\Command; |
|
15
|
|
|
|
|
16
|
|
|
use Symfony\Component\Console\Command\Command; |
|
17
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
|
18
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
19
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
20
|
|
|
use Symfony\Component\DependencyInjection\ContainerAwareInterface; |
|
21
|
|
|
use Symfony\Component\DependencyInjection\ContainerAwareTrait; |
|
22
|
|
|
use Symfony\Component\Process\Exception\ProcessFailedException; |
|
23
|
|
|
use Symfony\Component\Process\Process; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* Command used to update the project. |
|
27
|
|
|
*/ |
|
28
|
|
|
class RunParatestCommand extends Command implements ContainerAwareInterface |
|
29
|
|
|
{ |
|
30
|
|
|
use ContainerAwareTrait; |
|
31
|
|
|
|
|
32
|
|
|
private $output; |
|
33
|
|
|
|
|
34
|
|
|
private $process; |
|
35
|
|
|
|
|
36
|
|
|
private $phpunit; |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* Configuration of the command. |
|
40
|
|
|
*/ |
|
41
|
15 |
|
protected function configure(): void |
|
42
|
|
|
{ |
|
43
|
|
|
$this |
|
44
|
15 |
|
->setName('paratest:run') |
|
45
|
15 |
|
->setDescription('Run phpunit tests with multiple processes') |
|
46
|
|
|
// Pass arguments from this command "paratest:run" to the paratest command. |
|
47
|
15 |
|
->addArgument('options', InputArgument::OPTIONAL, 'Options') |
|
48
|
|
|
; |
|
49
|
15 |
|
} |
|
50
|
|
|
|
|
51
|
1 |
|
protected function prepare(): void |
|
52
|
|
|
{ |
|
53
|
1 |
|
$this->phpunit = $this->container->getParameter('liip_functional_test.paratest.phpunit'); |
|
54
|
1 |
|
$this->process = $this->container->getParameter('liip_functional_test.paratest.process'); |
|
55
|
1 |
|
} |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* Content of the command. |
|
59
|
|
|
* |
|
60
|
|
|
* @param InputInterface $input |
|
61
|
|
|
* @param OutputInterface $output |
|
62
|
|
|
* |
|
63
|
|
|
* @return int |
|
64
|
|
|
*/ |
|
65
|
1 |
|
protected function execute(InputInterface $input, OutputInterface $output) |
|
66
|
|
|
{ |
|
67
|
1 |
|
$this->output = $output; |
|
68
|
1 |
|
$this->prepare(); |
|
69
|
1 |
|
if (true !== is_file('vendor/bin/paratest')) { |
|
70
|
|
|
$this->output->writeln('Error : Install paratest first'); |
|
71
|
|
|
|
|
72
|
|
|
return 1; |
|
73
|
|
|
} else { |
|
74
|
1 |
|
$runProcess = new Process( |
|
75
|
|
|
[ |
|
76
|
1 |
|
'php', |
|
77
|
1 |
|
'vendor/bin/paratest', |
|
78
|
1 |
|
'-c', |
|
79
|
1 |
|
'phpunit.xml.dist', |
|
80
|
1 |
|
'--phpunit', |
|
81
|
1 |
|
$this->phpunit, |
|
82
|
1 |
|
'-p', |
|
83
|
1 |
|
$this->process, |
|
84
|
1 |
|
$input->getArgument('options'), |
|
85
|
|
|
] |
|
86
|
|
|
); |
|
87
|
1 |
|
$runProcess->setTimeout(10); |
|
88
|
|
|
|
|
89
|
|
|
try { |
|
90
|
1 |
|
$runProcess->mustRun(); |
|
91
|
|
|
|
|
92
|
1 |
|
$output->write($runProcess->getOutput()); |
|
93
|
|
|
|
|
94
|
1 |
|
return 0; |
|
95
|
|
|
} catch (ProcessFailedException $exception) { |
|
96
|
|
|
$output->write($exception->getMessage()); |
|
97
|
|
|
|
|
98
|
|
|
return 1; |
|
99
|
|
|
} |
|
100
|
|
|
} |
|
101
|
|
|
} |
|
102
|
|
|
} |
|
103
|
|
|
|