Completed
Pull Request — master (#555)
by Alexis
08:02
created

RunParatestCommand   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 6

Test Coverage

Coverage 68.18%

Importance

Changes 0
Metric Value
wmc 4
lcom 2
cbo 6
dl 0
loc 55
ccs 15
cts 22
cp 0.6818
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 0 9 1
A prepare() 0 5 1
A execute() 0 19 2
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 $phpunit;
38
39
    /**
40
     * Configuration of the command.
41
     */
42 15
    protected function configure(): void
43
    {
44
        $this
45 15
            ->setName('paratest:run')
46 15
            ->setDescription('Run phpunit tests with multiple processes')
47
            // Pass arguments from this command "paratest:run" to the paratest command.
48 15
            ->addArgument('options', InputArgument::OPTIONAL, 'Options')
49
        ;
50 15
    }
51
52 1
    protected function prepare(): void
53
    {
54 1
        $this->phpunit = $this->container->getParameter('liip_functional_test.paratest.phpunit');
55 1
        $this->process = $this->container->getParameter('liip_functional_test.paratest.process');
56 1
    }
57
58
    /**
59
     * Content of the command.
60
     *
61
     * @param InputInterface  $input
62
     * @param OutputInterface $output
63
     */
64 1
    protected function execute(InputInterface $input, OutputInterface $output): void
65
    {
66 1
        $this->output = $output;
67 1
        $this->prepare();
68 1
        if (true !== is_file('vendor/bin/paratest')) {
69 1
            $this->output->writeln('Error : Install paratest first');
70
        } else {
71
            $this->output->writeln('Done...Running test.');
72
            $runProcess = new Process('vendor/bin/paratest '.
0 ignored issues
show
Documentation introduced by
'vendor/bin/paratest ' ....>getArgument('options') is of type string, but the function expects a array.

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...
73
                '-c phpunit.xml.dist '.
74
                '--phpunit '.$this->phpunit.' '.
75
                '-p '.$this->process.' '.
76
                $input->getArgument('options')
77
            );
78
            $runProcess->run(function ($type, $buffer) use ($output): void {
79
                $output->write($buffer);
80
            });
81
        }
82 1
    }
83
}
84