Passed
Push — paratest-pass-arguments ( c6cdcc )
by Alexis
08:17
created

RunParatestCommand::execute()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 20
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 16
CRAP Score 2.0054

Importance

Changes 4
Bugs 1 Features 2
Metric Value
c 4
b 1
f 2
dl 0
loc 20
ccs 16
cts 18
cp 0.8889
rs 9.4285
cc 2
eloc 15
nc 2
nop 2
crap 2.0054
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 $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...
17
    private $output;
18
    private $process;
19
    private $testDbPath;
20
    private $phpunit;
21
22
    /**
23
     * Configuration of the command.
24
     */
25 12
    protected function configure()
26
    {
27 12
        $this
28 12
            ->setName('paratest:run')
29 12
            ->setDescription('Run phpunit tests with multiple processes')
30
            // Pass arguments from this command "paratest:run" to the paratest binary.
31 12
            ->addArgument('options', InputArgument::OPTIONAL, 'Options')
32
        ;
33 12
    }
34
35 1
    protected function prepare()
36
    {
37 1
        $this->phpunit = $this->getContainer()->getParameter('liip_functional_test.paratest.phpunit');
38 1
        $this->process = $this->getContainer()->getParameter('liip_functional_test.paratest.process');
39
40 1
        $this->testDbPath = $this->getContainer()->get('kernel')->getRootDir();
41 1
        $this->output->writeln("Cleaning old dbs in $this->testDbPath ...");
42 1
        $createDirProcess = new Process('mkdir -p '.$this->testDbPath.'/cache/test/');
43 1
        $createDirProcess->run();
44 1
        $cleanProcess = new Process("rm -fr $this->testDbPath/cache/test/dbTest.db $this->testDbPath/cache/test/dbTest*.db*");
45 1
        $cleanProcess->run();
46 1
        $this->output->writeln("Creating Schema in $this->testDbPath ...");
47 1
        $createProcess = new Process('php app/console doctrine:schema:create --env=test');
48 1
        $createProcess->run();
49
50 1
        $this->output->writeln('Initial schema created');
51 1
        $populateProcess = new Process("php app/console doctrine:fixtures:load -n --fixtures $this->testDbPath/../src/overlord/AppBundle/Tests/DataFixtures/ORM/ --env=test");
52 1
        $populateProcess->run();
53
54 1
        $this->output->writeln('Initial schema populated, duplicating....');
55 1
        for ($a = 0; $a < $this->process; ++$a) {
56 1
            $test = new Process("cp $this->testDbPath/cache/test/dbTest.db ".$this->testDbPath."/cache/test/dbTest$a.db");
57 1
            $test->run();
58 1
        }
59 1
    }
60
61
    /**
62
     * Content of the command.
63
     *
64
     * @param InputInterface  $input
65
     * @param OutputInterface $output
66
     */
67 1
    protected function execute(InputInterface $input, OutputInterface $output)
68
    {
69 1
        $this->output = $output;
70 1
        $this->prepare();
71 1
        if (is_file('vendor/bin/paratest') !== true) {
72
            $this->output->writeln('Error : Install paratest first');
73
        } else {
74 1
            $this->output->writeln('Done...Running test.');
75 1
            $runProcess = new Process('vendor/bin/paratest '.
76 1
                '-c phpunit.xml.dist '.
77 1
                '--phpunit '.$this->phpunit.' '.
78 1
                '--runner WrapRunner '.
79 1
                '-p '.$this->process.' '.
80 1
                $input->getArgument('options')
81 1
            );
82 1
            $runProcess->run(function ($type, $buffer) use($output) {
83 1
                $output->write($buffer);
84 1
            });
85
        }
86 1
    }
87
}
88