Completed
Pull Request — master (#35)
by Alexis
18:52 queued 13:45
created

RunParatestCommand   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 84
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 91.3%

Importance

Changes 7
Bugs 2 Features 2
Metric Value
wmc 9
c 7
b 2
f 2
lcom 1
cbo 5
dl 0
loc 84
ccs 42
cts 46
cp 0.913
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 0 7 1
B prepare() 0 32 6
A execute() 0 23 2
1
<?php
2
3
namespace Liip\FunctionalTestBundle\Command;
4
5
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
6
use Symfony\Component\Console\Input\InputInterface;
7
use Symfony\Component\Console\Output\OutputInterface;
8
use Symfony\Component\Process\Process;
9
10
/**
11
 * Command used to update the project.
12
 */
13
class RunParatestCommand extends ContainerAwareCommand
14
{
15
    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...
16
    private $configuration;
17
    private $output;
18
    private $process = 5;
19
    private $testDbPath;
20
    // Relative path to phpunit.
21
    private $phpunit = '../vendor/bin/phpunit';
22
23
    /**
24
     * Configuration of the command.
25
     */
26 12
    protected function configure()
27
    {
28 12
        $this
29 12
            ->setName('test:run')
30 12
            ->setDescription('Run phpunit tests with multiple process')
31
        ;
32 12
    }
33
34 1
    protected function prepare()
35
    {
36 1
        $this->configuration = $this->getContainer()->hasParameter('liip_functional_test');
37 1
        $paratestCfg = (!isset($this->configuration['paratest'])) ? array('process' => $this->process, 'phpunit' => $this->phpunit) : $this->configuration['paratest'];
38
39 1
        $this->process = (!empty($this->configuration['process'])) ? $paratestCfg['process'] : $this->process;
40 1
        $this->phpunit = (!empty($this->configuration['phpunit'])) ? $paratestCfg['phpunit'] : $this->phpunit;
41 1
        $this->testDbPath = $this->getContainer()->getParameter('kernel.cache_dir').'/';
42
43 1
        $this->output->writeln("Cleaning old dbs in $this->testDbPath ...");
44 1
        if (!is_dir($this->testDbPath)) {
45
            mkdir($this->testDbPath, 0755, true);
46
        }
47
48 1
        $cleanProcess = new Process("rm -fr $this->testDbPath/dbTest.db $this->testDbPath/dbTest*.db*");
49 1
        $cleanProcess->run();
50 1
        $this->output->writeln("Creating Schema in $this->testDbPath ...");
51 1
        $createProcess = new Process('php app/console doctrine:schema:create --env=test');
52 1
        $createProcess->run();
53
54 1
        $this->output->writeln('Initial schema created');
55 1
        $populateProcess = new Process("php app/console doctrine:fixtures:load -n --fixtures $this->testDbPath/../src/overlord/AppBundle/Tests/DataFixtures/ORM/ --env=test");
56 1
        $populateProcess->run();
57
58 1
        $this->output->writeln('Initial schema populated, duplicating....');
59 1
        for ($a = 0; $a < $this->process; ++$a) {
60 1
            $test = new Process("cp $this->testDbPath/dbTest.db ".$this->testDbPath."test/dbTest$a.db");
61 1
            $test->run();
62
//            copy($this->testDbPath.'dbTest.db',
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...
63
//                $this->testDbPath.'dbTest'.$a.'.db');
64 1
        }
65 1
    }
66
67
    /**
68
     * Content of the command.
69
     *
70
     * @param InputInterface  $input
71
     * @param OutputInterface $output
72
     */
73 1
    protected function execute(InputInterface $input, OutputInterface $output)
74
    {
75 1
        $this->output = $output;
76 1
        $this->prepare();
77
78 1
        $paratestPath = __DIR__.'/../vendor/bin/paratest';
79
80 1
        if (is_file($paratestPath) !== true) {
81
            $this->output->writeln('Error : Install paratest first');
82
        } else {
83 1
            $this->output->writeln('Done...Running test.');
84 1
            $runProcess = new Process($paratestPath.' '.
85 1
                '-c '.__DIR__.'/../phpunit.xml.dist '.
86 1
                '--phpunit '.__DIR__.'/'.$this->phpunit.' '.
87 1
                '--runner WrapRunner  -p '.$this->process.' '.
88
                // Don't launch all the tests, that may create an infinite
89
                // loop if this current file is tested.
90 1
                __DIR__.'/../Tests/Test/');
91 1
            $runProcess->run(function ($type, $buffer) use ($output) {
92 1
                $output->write($buffer);
93 1
            });
94
        }
95 1
    }
96
}
97