Passed
Push — 253-fix-tests ( 9ce130...8be25e )
by Alexis
15:27 queued 07:28
created

RunParatestCommand::execute()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 20
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 17
CRAP Score 2

Importance

Changes 6
Bugs 1 Features 2
Metric Value
c 6
b 1
f 2
dl 0
loc 20
ccs 17
cts 17
cp 1
rs 9.4285
cc 2
eloc 14
nc 2
nop 2
crap 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 = 5;
18
    private $testDbPath;
19
    private $paratestPath;
20
    private $phpunit;
21
    private $xmlConfig;
22
23
    /**
24
     * Configuration of the command.
25
     */
26 13
    protected function configure()
27
    {
28 13
        $this
29 13
            ->setName('paratest:run')
30 13
            ->setDescription('Run phpunit tests with multiple process')
31 13
            ->addArgument('options', InputArgument::OPTIONAL, 'Options')
32
        ;
33 13
    }
34
35 2
    protected function prepare()
36
    {
37 2
        $container = $this->getContainer();
38
39 2
        $this->process = $container->getParameter('liip_functional_test.paratest.process');
40 2
        $this->paratestPath = $container->getParameter('liip_functional_test.paratest.path');
41 2
        $this->phpunit = $container->getParameter('liip_functional_test.paratest.phpunit');
42 2
        $this->xmlConfig = $container->getParameter('liip_functional_test.paratest.xml_config');
43
44 2
        $this->testDbPath = $container->getParameter('kernel.cache_dir');
45
46 2
        $this->output->writeln('Cleaning old dbs in '.$this->testDbPath.' ...');
47 2
        $cleanProcess = new Process('rm -fr '.$this->testDbPath.'/dbTest.db '.$this->testDbPath.'/dbTest*.db*');
48 2
        $cleanProcess->run();
49 2
    }
50
51
    /**
52
     * Content of the command.
53
     *
54
     * @param InputInterface  $input
55
     * @param OutputInterface $output
56
     */
57 2
    protected function execute(InputInterface $input, OutputInterface $output)
58
    {
59 2
        $this->output = $output;
60 2
        $this->prepare();
61
62 2
        if (is_file($this->paratestPath) !== true) {
63 1
            $this->output->writeln('Error : Install paratest first');
64 1
        } else {
65 1
            $this->output->writeln('Done...Running test.');
66 1
            $runProcess = new Process($this->paratestPath.' '.
67 1
                '-c '.$this->xmlConfig.' '.
68 1
                '--phpunit '.$this->phpunit.' '.
69 1
                '--runner WrapRunner -p '.$this->process.' '.
70 1
                $input->getArgument('options')
71 1
            );
72 1
            $runProcess->run(function ($type, $buffer) use ($output) {
73 1
                $output->write($buffer);
74 1
            });
75
        }
76 2
    }
77
}
78