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

RunParatestCommand::configure()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 3
Bugs 0 Features 1
Metric Value
c 3
b 0
f 1
dl 0
loc 7
ccs 5
cts 5
cp 1
rs 9.4285
cc 1
eloc 4
nc 1
nop 0
crap 1
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