Passed
Push — 253-fix-tests ( c8f909...4c5adb )
by Alexis
08:01
created

RunParatestCommand::execute()   B

Complexity

Conditions 2
Paths 2

Size

Total Lines 25
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 15
CRAP Score 2.0065

Importance

Changes 5
Bugs 1 Features 2
Metric Value
c 5
b 1
f 2
dl 0
loc 25
ccs 15
cts 17
cp 0.8824
rs 8.8571
cc 2
eloc 14
nc 2
nop 2
crap 2.0065
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 12
    protected function configure()
27
    {
28 12
        $this
29 12
            ->setName('paratest:run')
30 12
            ->setDescription('Run phpunit tests with multiple process')
31 12
            ->addArgument('options', InputArgument::OPTIONAL, 'Options')
32
        ;
33 12
    }
34
35 1
    protected function prepare()
36
    {
37 1
        $container = $this->getContainer();
38
39 1
        $this->process = $container->getParameter('liip_functional_test.paratest.process');
40 1
        $this->paratestPath = $container->getParameter('liip_functional_test.paratest.path');
41 1
        $this->phpunit = $container->getParameter('liip_functional_test.paratest.phpunit');
42 1
        $this->xmlConfig = $container->getParameter('liip_functional_test.paratest.xml_config');
43
44 1
        $this->testDbPath = $container->getParameter('kernel.cache_dir');
45
46 1
        $this->output->writeln('Cleaning old dbs in '.$this->testDbPath.' ...');
47 1
        $cleanProcess = new Process('rm -fr '.$this->testDbPath.'/dbTest.db '.$this->testDbPath.'/dbTest*.db*');
48 1
        $cleanProcess->run();
49
50
//        $this->output->writeln('Creating Schema in '.$this->testDbPath.' ...');
0 ignored issues
show
Unused Code Comprehensibility introduced by
55% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
51
//        $createProcess = new Process('php app/console doctrine:schema:create --env=test');
52
//        $createProcess->run();
53
//
54
//        $this->output->writeln('Initial schema created');
55
//        $populateProcess = new Process('php app/console doctrine:fixtures:load -n --env=test');
56
//        $populateProcess->run();
57
//
58
//        $this->output->writeln('Initial schema populated, duplicating....');
59
//        for ($a = 0; $a < $this->process; ++$a) {
60
//            copy($this->testDbPath.'/dbTest.db', $this->testDbPath.'/dbTest'.$a.'.db');
61
//        }
62 1
    }
63
64
    /**
65
     * Content of the command.
66
     *
67
     * @param InputInterface  $input
68
     * @param OutputInterface $output
69
     */
70 1
    protected function execute(InputInterface $input, OutputInterface $output)
71
    {
72 1
        $this->output = $output;
73 1
        $this->prepare();
74
75 1
        if (is_file($this->paratestPath) !== true) {
76
            $this->output->writeln('Error : Install paratest first');
77
        } else {
78 1
            $this->output->writeln('Done...Running test.');
79
//            die($this->paratestPath.' '.
0 ignored issues
show
Unused Code Comprehensibility introduced by
49% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
80
//                '-c '.$this->xmlConfig.' '.
81
//                '--phpunit '.$this->phpunit.' '.
82
//                '--runner WrapRunner -p '.$this->process.' '.
83
//                $input->getArgument('options'));
84 1
            $runProcess = new Process($this->paratestPath.' '.
85 1
                '-c '.$this->xmlConfig.' '.
86 1
                '--phpunit '.$this->phpunit.' '.
87 1
                '--runner WrapRunner -p '.$this->process.' '.
88 1
                $input->getArgument('options')
89 1
            );
90 1
            $runProcess->run(function ($type, $buffer) use ($output) {
91 1
                $output->write($buffer);
92 1
            });
93
        }
94 1
    }
95
}
96