Completed
Pull Request — master (#258)
by Alexis
28:48 queued 21:16
created

RunParatestCommand::configure()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 1

Importance

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