1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Liip\FunctionalTestBundle\Command; |
4
|
|
|
|
5
|
|
|
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; |
6
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
7
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
8
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
9
|
|
|
use Symfony\Component\Process\Process; |
10
|
|
|
use Symfony\Component\Console\Input\ArrayInput; |
11
|
|
|
use Symfony\Bundle\FrameworkBundle\Console\Application; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* Command used to update the project. |
15
|
|
|
*/ |
16
|
|
|
class RunParatestCommand extends ContainerAwareCommand |
17
|
|
|
{ |
18
|
|
|
private $output; |
19
|
|
|
|
20
|
|
|
private $process; |
21
|
|
|
|
22
|
|
|
private $testDbPath; |
23
|
|
|
|
24
|
|
|
private $phpunit; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* Configuration of the command. |
28
|
|
|
*/ |
29
|
11 |
|
protected function configure() |
30
|
|
|
{ |
31
|
|
|
$this |
32
|
11 |
|
->setName('paratest:run') |
33
|
11 |
|
->setDescription('Run phpunit tests with multiple processes') |
34
|
|
|
// Pass arguments from this command "paratest:run" to the paratest command. |
35
|
11 |
|
->addArgument('options', InputArgument::OPTIONAL, 'Options') |
36
|
|
|
; |
37
|
11 |
|
} |
38
|
|
|
|
39
|
|
|
protected function prepare() |
40
|
|
|
{ |
41
|
|
|
$this->phpunit = $this->getContainer()->getParameter('liip_functional_test.paratest.phpunit'); |
42
|
|
|
$this->process = $this->getContainer()->getParameter('liip_functional_test.paratest.process'); |
43
|
|
|
|
44
|
|
|
$this->testDbPath = $this->getContainer()->get('kernel')->getCacheDir(); |
45
|
|
|
$this->output->writeln("Cleaning old dbs in $this->testDbPath ..."); |
46
|
|
|
$createDirProcess = new Process('mkdir -p '.$this->testDbPath); |
47
|
|
|
$createDirProcess->run(); |
48
|
|
|
$cleanProcess = new Process("rm -fr $this->testDbPath/dbTest.db $this->testDbPath/dbTest*.db*"); |
49
|
|
|
$cleanProcess->run(); |
50
|
|
|
$this->output->writeln("Creating Schema in $this->testDbPath ..."); |
51
|
|
|
$application = new Application($this->getContainer()->get('kernel')); |
52
|
|
|
$input = new ArrayInput(array('doctrine:schema:create', '--env' => 'test')); |
53
|
|
|
$application->run($input, $this->output); |
54
|
|
|
|
55
|
|
|
$this->output->writeln('Initial schema created'); |
56
|
|
|
$input = new ArrayInput(array( |
57
|
|
|
'doctrine:fixtures:load', |
58
|
|
|
'-n' => '', |
59
|
|
|
'--env' => 'test', |
60
|
|
|
)); |
61
|
|
|
$application->run($input, $this->output); |
62
|
|
|
|
63
|
|
|
$this->output->writeln('Initial schema populated, duplicating....'); |
64
|
|
|
for ($a = 0; $a < $this->process; ++$a) { |
65
|
|
|
$test = new Process("cp $this->testDbPath/dbTest.db ".$this->testDbPath."/dbTest$a.db"); |
66
|
|
|
$test->run(); |
67
|
|
|
} |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* Content of the command. |
72
|
|
|
* |
73
|
|
|
* @param InputInterface $input |
74
|
|
|
* @param OutputInterface $output |
75
|
|
|
*/ |
76
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
77
|
|
|
{ |
78
|
|
|
$this->output = $output; |
79
|
|
|
$this->prepare(); |
80
|
|
|
if (true !== is_file('vendor/bin/paratest')) { |
81
|
|
|
$this->output->writeln('Error : Install paratest first'); |
82
|
|
|
} else { |
83
|
|
|
$this->output->writeln('Done...Running test.'); |
84
|
|
|
$runProcess = new Process('vendor/bin/paratest '. |
85
|
|
|
'-c phpunit.xml.dist '. |
86
|
|
|
'--phpunit '.$this->phpunit.' '. |
87
|
|
|
'--runner WrapRunner '. |
88
|
|
|
'-p '.$this->process.' '. |
89
|
|
|
$input->getArgument('options') |
90
|
|
|
); |
91
|
|
|
$runProcess->run(function ($type, $buffer) use ($output) { |
92
|
|
|
$output->write($buffer); |
93
|
|
|
}); |
94
|
|
|
} |
95
|
|
|
} |
96
|
|
|
} |
97
|
|
|
|