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

RunParatestCommand::configure()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 2
Bugs 0 Features 1
Metric Value
c 2
b 0
f 1
dl 0
loc 7
ccs 5
cts 5
cp 1
rs 9.4285
cc 1
eloc 4
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\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