Passed
Push — master ( 421eba...09fd73 )
by Alexis
03:20 queued 11s
created

RunParatestCommand::configure()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 9
ccs 5
cts 5
cp 1
rs 9.9666
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the Liip/FunctionalTestBundle
7
 *
8
 * (c) Lukas Kahwe Smith <[email protected]>
9
 *
10
 * This source file is subject to the MIT license that is bundled
11
 * with this source code in the file LICENSE.
12
 */
13
14
namespace Liip\FunctionalTestBundle\Command;
15
16
use Symfony\Bundle\FrameworkBundle\Console\Application;
17
use Symfony\Component\Console\Command\Command;
18
use Symfony\Component\Console\Input\ArrayInput;
19
use Symfony\Component\Console\Input\InputArgument;
20
use Symfony\Component\Console\Input\InputInterface;
21
use Symfony\Component\Console\Output\OutputInterface;
22
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
23
use Symfony\Component\DependencyInjection\ContainerAwareTrait;
24
use Symfony\Component\Process\Process;
25
26
/**
27
 * Command used to update the project.
28
 */
29
class RunParatestCommand extends Command implements ContainerAwareInterface
30
{
31
    use ContainerAwareTrait;
32
33
    private $output;
34
35
    private $process;
36
37
    private $testDbPath;
38
39
    private $phpunit;
40
41
    /**
42
     * Configuration of the command.
43
     */
44 14
    protected function configure(): void
45
    {
46
        $this
47 14
            ->setName('paratest:run')
48 14
            ->setDescription('Run phpunit tests with multiple processes')
49
            // Pass arguments from this command "paratest:run" to the paratest command.
50 14
            ->addArgument('options', InputArgument::OPTIONAL, 'Options')
51
        ;
52 14
    }
53
54
    protected function prepare(): void
55
    {
56
        $this->phpunit = $this->container->getParameter('liip_functional_test.paratest.phpunit');
57
        $this->process = $this->container->getParameter('liip_functional_test.paratest.process');
58
59
        $this->testDbPath = $this->container->get('kernel')->getCacheDir();
60
        $this->output->writeln("Cleaning old dbs in $this->testDbPath ...");
61
        $createDirProcess = new Process('mkdir -p '.$this->testDbPath);
62
        $createDirProcess->run();
63
        $cleanProcess = new Process("rm -fr $this->testDbPath/dbTest.db $this->testDbPath/dbTest*.db*");
64
        $cleanProcess->run();
65
        $this->output->writeln("Creating Schema in $this->testDbPath ...");
66
        $application = new Application($this->container->get('kernel'));
0 ignored issues
show
Documentation introduced by
$this->container->get('kernel') is of type object|null, but the function expects a object<Symfony\Component...Kernel\KernelInterface>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
67
        $input = new ArrayInput(['doctrine:schema:create', '--env' => 'test']);
68
        $application->run($input, $this->output);
69
70
        $this->output->writeln('Initial schema created');
71
        $input = new ArrayInput([
72
            'doctrine:fixtures:load',
73
            '-n' => '',
74
            '--env' => 'test',
75
        ]);
76
        $application->run($input, $this->output);
77
78
        $this->output->writeln('Initial schema populated, duplicating....');
79
        for ($a = 0; $a < $this->process; ++$a) {
80
            $test = new Process("cp $this->testDbPath/dbTest.db ".$this->testDbPath."/dbTest$a.db");
81
            $test->run();
82
        }
83
    }
84
85
    /**
86
     * Content of the command.
87
     *
88
     * @param InputInterface  $input
89
     * @param OutputInterface $output
90
     */
91
    protected function execute(InputInterface $input, OutputInterface $output): void
92
    {
93
        $this->output = $output;
94
        $this->prepare();
95
        if (true !== is_file('vendor/bin/paratest')) {
96
            $this->output->writeln('Error : Install paratest first');
97
        } else {
98
            $this->output->writeln('Done...Running test.');
99
            $runProcess = new Process('vendor/bin/paratest '.
100
                '-c phpunit.xml.dist '.
101
                '--phpunit '.$this->phpunit.' '.
102
                '--runner WrapRunner '.
103
                '-p '.$this->process.' '.
104
                $input->getArgument('options')
105
            );
106
            $runProcess->run(function ($type, $buffer) use ($output): void {
107
                $output->write($buffer);
108
            });
109
        }
110
    }
111
}
112