Completed
Pull Request — master (#265)
by Alexis
06:47
created

RunParatestCommand   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 73
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Test Coverage

Coverage 95.56%

Importance

Changes 8
Bugs 3 Features 2
Metric Value
wmc 5
c 8
b 3
f 2
lcom 1
cbo 6
dl 0
loc 73
ccs 43
cts 45
cp 0.9556
rs 10

3 Methods

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