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
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* Command used to update the project. |
13
|
|
|
*/ |
14
|
|
|
class RunParatestCommand extends ContainerAwareCommand |
15
|
|
|
{ |
16
|
|
|
private $output; |
17
|
|
|
private $process = 5; |
18
|
|
|
private $testDbPath; |
19
|
|
|
private $paratestPath; |
20
|
|
|
private $phpunit; |
21
|
|
|
private $xmlConfig; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* Configuration of the command. |
25
|
|
|
*/ |
26
|
12 |
|
protected function configure() |
27
|
|
|
{ |
28
|
12 |
|
$this |
29
|
12 |
|
->setName('paratest:run') |
30
|
12 |
|
->setDescription('Run phpunit tests with multiple process') |
31
|
12 |
|
->addArgument('options', InputArgument::OPTIONAL, 'Options') |
32
|
|
|
; |
33
|
12 |
|
} |
34
|
|
|
|
35
|
1 |
|
protected function prepare() |
36
|
|
|
{ |
37
|
1 |
|
$container = $this->getContainer(); |
38
|
|
|
|
39
|
1 |
|
$this->process = $container->getParameter('liip_functional_test.paratest.process'); |
40
|
1 |
|
$this->paratestPath = $container->getParameter('liip_functional_test.paratest.path'); |
41
|
1 |
|
$this->phpunit = $container->getParameter('liip_functional_test.paratest.phpunit'); |
42
|
1 |
|
$this->xmlConfig = $container->getParameter('liip_functional_test.paratest.xml_config'); |
43
|
|
|
|
44
|
1 |
|
$this->testDbPath = $container->getParameter('kernel.cache_dir'); |
45
|
|
|
|
46
|
1 |
|
$this->output->writeln('Cleaning old dbs in '.$this->testDbPath.' ...'); |
47
|
1 |
|
$cleanProcess = new Process('rm -fr '.$this->testDbPath.'/dbTest.db '.$this->testDbPath.'/dbTest*.db*'); |
48
|
1 |
|
$cleanProcess->run(); |
49
|
|
|
|
50
|
|
|
// $this->output->writeln('Creating Schema in '.$this->testDbPath.' ...'); |
|
|
|
|
51
|
|
|
// $createProcess = new Process('php app/console doctrine:schema:create --env=test'); |
52
|
|
|
// $createProcess->run(); |
53
|
|
|
// |
54
|
|
|
// $this->output->writeln('Initial schema created'); |
55
|
|
|
// $populateProcess = new Process('php app/console doctrine:fixtures:load -n --env=test'); |
56
|
|
|
// $populateProcess->run(); |
57
|
|
|
// |
58
|
|
|
// $this->output->writeln('Initial schema populated, duplicating....'); |
59
|
|
|
// for ($a = 0; $a < $this->process; ++$a) { |
60
|
|
|
// copy($this->testDbPath.'/dbTest.db', $this->testDbPath.'/dbTest'.$a.'.db'); |
61
|
|
|
// } |
62
|
1 |
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* Content of the command. |
66
|
|
|
* |
67
|
|
|
* @param InputInterface $input |
68
|
|
|
* @param OutputInterface $output |
69
|
|
|
*/ |
70
|
1 |
|
protected function execute(InputInterface $input, OutputInterface $output) |
71
|
|
|
{ |
72
|
1 |
|
$this->output = $output; |
73
|
1 |
|
$this->prepare(); |
74
|
|
|
|
75
|
1 |
|
if (is_file($this->paratestPath) !== true) { |
76
|
|
|
$this->output->writeln('Error : Install paratest first'); |
77
|
|
|
} else { |
78
|
1 |
|
$this->output->writeln('Done...Running test.'); |
79
|
|
|
// die($this->paratestPath.' '. |
|
|
|
|
80
|
|
|
// '-c '.$this->xmlConfig.' '. |
81
|
|
|
// '--phpunit '.$this->phpunit.' '. |
82
|
|
|
// '--runner WrapRunner -p '.$this->process.' '. |
83
|
|
|
// $input->getArgument('options')); |
84
|
1 |
|
$runProcess = new Process($this->paratestPath.' '. |
85
|
1 |
|
'-c '.$this->xmlConfig.' '. |
86
|
1 |
|
'--phpunit '.$this->phpunit.' '. |
87
|
1 |
|
'--runner WrapRunner -p '.$this->process.' '. |
88
|
1 |
|
$input->getArgument('options') |
89
|
1 |
|
); |
90
|
1 |
|
$runProcess->run(function ($type, $buffer) use ($output) { |
91
|
1 |
|
$output->write($buffer); |
92
|
1 |
|
}); |
93
|
|
|
} |
94
|
1 |
|
} |
95
|
|
|
} |
96
|
|
|
|
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.