Completed
Push — master ( 9e0aa4...7401da )
by Alexis
07:55
created

RunParatestCommand   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 66
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 94.74%

Importance

Changes 7
Bugs 2 Features 2
Metric Value
wmc 5
c 7
b 2
f 2
lcom 1
cbo 5
dl 0
loc 66
ccs 36
cts 38
cp 0.9474
rs 10

3 Methods

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