Completed
Push — 1.6-dev ( 4f019b )
by Alexis
09:21
created

RunParatestCommand   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 69
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 5
Bugs 1 Features 2
Metric Value
wmc 8
c 5
b 1
f 2
lcom 1
cbo 5
dl 0
loc 69
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 0 7 1
B prepare() 0 27 5
A execute() 0 14 2
1
<?php
2
3
namespace Liip\FunctionalTestBundle\Command;
4
5
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
6
use Symfony\Component\Console\Input\InputInterface;
7
use Symfony\Component\Console\Output\OutputInterface;
8
use Symfony\Component\Process\Process;
9
10
/**
11
 * Command used to update the project.
12
 */
13
class RunParatestCommand extends ContainerAwareCommand
14
{
15
    private $container;
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
Unused Code introduced by
The property $container is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
16
    private $configuration;
17
    private $output;
18
    private $process = 5;
19
    private $testDbPath;
20
    private $phpunit = './bin/phpunit';
21
22
    /**
23
     * Configuration of the command.
24
     */
25
    protected function configure()
26
    {
27
        $this
28
            ->setName('test:run')
29
            ->setDescription('Run phpunit tests with multiple process')
30
        ;
31
    }
32
33
    protected function prepare()
34
    {
35
        $this->configuration = $this->getContainer()->hasParameter('liip_functional_test');
36
        $paratestCfg = (!isset($this->configuration['paratest'])) ? array('process' => $this->process, 'phpunit' => $this->phpunit) : $this->configuration['paratest'];
37
38
        $this->process = (!empty($this->configuration['process'])) ? $paratestCfg['process'] : $this->process;
39
        $this->phpunit = (!empty($this->configuration['phpunit'])) ? $paratestCfg['phpunit'] : $this->phpunit;
40
        $this->testDbPath = $this->getContainer()->get('kernel')->getRootDir();
41
        $this->output->writeln("Cleaning old dbs in $this->testDbPath ...");
42
        $createDirProcess = new Process('mkdir -p '.$this->testDbPath.'/cache/test/');
43
        $createDirProcess->run();
44
        $cleanProcess = new Process("rm -fr $this->testDbPath/cache/test/dbTest.db $this->testDbPath/cache/test/dbTest*.db*");
45
        $cleanProcess->run();
46
        $this->output->writeln("Creating Schema in $this->testDbPath ...");
47
        $createProcess = new Process('php app/console doctrine:schema:create --env=test');
48
        $createProcess->run();
49
50
        $this->output->writeln('Initial schema created');
51
        $populateProcess = new Process("php app/console doctrine:fixtures:load -n --fixtures $this->testDbPath/../src/overlord/AppBundle/Tests/DataFixtures/ORM/ --env=test");
52
        $populateProcess->run();
53
54
        $this->output->writeln('Initial schema populated, duplicating....');
55
        for ($a = 0; $a < $this->process; ++$a) {
56
            $test = new Process("cp $this->testDbPath/cache/test/dbTest.db ".$this->testDbPath."/cache/test/dbTest$a.db");
57
            $test->run();
58
        }
59
    }
60
61
    /**
62
     * Content of the command.
63
     *
64
     * @param InputInterface  $input
65
     * @param OutputInterface $output
66
     */
67
    protected function execute(InputInterface $input, OutputInterface $output)
68
    {
69
        $this->output = $output;
70
        $this->prepare();
71
        if (is_file('vendor/bin/paratest') !== true) {
72
            $this->output->writeln('Error : Install paratest first');
73
        } else {
74
            $this->output->writeln('Done...Running test.');
75
            $runProcess = new Process('vendor/bin/paratest -c phpunit.xml.dist --phpunit '.$this->phpunit.' --runner WrapRunner  -p '.$this->process);
76
            $runProcess->run(function ($type, $buffer) {
77
                echo $buffer;
78
            });
79
        }
80
    }
81
}
82