Completed
Pull Request — master (#557)
by Alexis
14:04
created

RunParatestCommand::prepare()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 5
cts 5
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 $phpunit;
36
37
    private $bundleRoot;
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
        $this->bundleRoot = __DIR__.'/../../';
57 1
    }
58
59
    /**
60
     * Content of the command.
61
     *
62
     * @param InputInterface  $input
63
     * @param OutputInterface $output
64
     *
65
     * @return int
66
     */
67 1
    protected function execute(InputInterface $input, OutputInterface $output)
68
    {
69 1
        $this->output = $output;
70 1
        $this->prepare();
71 1
        if (true !== is_file($this->bundleRoot .'vendor/bin/paratest')) {
72
            $this->output->writeln('Error : Install paratest first');
73
74
            return 1;
75
        } else {
76 1
            $this->output->writeln('Done...Running test.');
77 1
            $runProcess = new Process(
78
                [
79
                    'php vendor/bin/paratest '.
80
                    '-c phpunit.xml.dist '.
81 1
                    '--phpunit '.$this->phpunit.' '.
82 1
                    '-p '.$this->process.' '.
83 1
                    $input->getArgument('options'),
84
                ],
85 1
                $this->bundleRoot
86
            );
87
            $runProcess->run(function ($type, $buffer) use ($output): void {
88 1
                $output->write($buffer);
89 1
            });
90
91 1
            return 0;
92
        }
93
    }
94
}
95