Completed
Pull Request — master (#556)
by Vlad
11:35 queued 33s
created

RunParatestCommand::prepare()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 5
ccs 4
cts 4
cp 1
rs 10
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\Component\Console\Command\Command;
17
use Symfony\Component\Console\Input\InputArgument;
18
use Symfony\Component\Console\Input\InputInterface;
19
use Symfony\Component\Console\Output\OutputInterface;
20
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
21
use Symfony\Component\DependencyInjection\ContainerAwareTrait;
22
use Symfony\Component\Process\Process;
23
24
/**
25
 * Command used to update the project.
26
 */
27
class RunParatestCommand extends Command implements ContainerAwareInterface
28
{
29
    use ContainerAwareTrait;
30
31
    private $output;
32
33
    private $process;
34
35
    private $testDbPath;
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
     * @return int
65
     */
66 1
    protected function execute(InputInterface $input, OutputInterface $output)
67
    {
68 1
        $this->output = $output;
69 1
        $this->prepare();
70 1
        if (true !== is_file('vendor/bin/paratest')) {
71 1
            $this->output->writeln('Error : Install paratest first');
72 1
            return 1;
73
        } else {
74
            $this->output->writeln('Done...Running test.');
75
            $runProcess = new Process(['vendor/bin/paratest '.
76
                '-c phpunit.xml.dist '.
77
                '--phpunit '.$this->phpunit.' '.
78
                '-p '.$this->process.' '.
79
                $input->getArgument('options'),
80
            ]);
81
            $runProcess->run(function ($type, $buffer) use ($output): void {
82
                $output->write($buffer);
83
            });
84
            return 0;
85
        }
86
    }
87
}
88