Completed
Push — master ( 060b9b...08fbde )
by Pablo
02:06
created

PhpUnitHandler::processBuilder()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
3
namespace PhpGitHooks\Application\PhpUnit;
4
5
use PhpGitHooks\Application\Message\MessageConfigData;
6
use PhpGitHooks\Command\BadJobLogo;
7
use PhpGitHooks\Command\OutputHandlerInterface;
8
use PhpGitHooks\Infrastructure\Common\ProcessBuilderInterface;
9
use PhpGitHooks\Infrastructure\Common\ToolHandler;
10
use PhpGitHooks\Infrastructure\PhpUnit\PhpUnitProcessBuilder;
11
12
/**
13
 * Class PhpUnitHandler.
14
 */
15
class PhpUnitHandler extends ToolHandler
16
{
17
    /** @var PhpUnitProcessBuilder  */
18
    protected $phpUnitProcessBuilder;
19
20
    /**
21
     * @param OutputHandlerInterface  $outputHandler
22
     * @param ProcessBuilderInterface $processBuilderInterface
23
     */
24 3
    public function __construct(OutputHandlerInterface $outputHandler, ProcessBuilderInterface $processBuilderInterface)
25
    {
26 3
        parent::__construct($outputHandler);
27
28 3
        $this->phpUnitProcessBuilder = $processBuilderInterface;
0 ignored issues
show
Documentation Bug introduced by
$processBuilderInterface is of type object<PhpGitHooks\Infra...rocessBuilderInterface>, but the property $phpUnitProcessBuilder was declared to be of type object<PhpGitHooks\Infra...\PhpUnitProcessBuilder>. Are you sure that you always receive this specific sub-class here, or does it make sense to add an instanceof check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a given class or a super-class is assigned to a property that is type hinted more strictly.

Either this assignment is in error or an instanceof check should be added for that assignment.

class Alien {}

class Dalek extends Alien {}

class Plot
{
    /** @var  Dalek */
    public $villain;
}

$alien = new Alien();
$plot = new Plot();
if ($alien instanceof Dalek) {
    $plot->villain = $alien;
}
Loading history...
29 3
    }
30
31
    /**
32
     * @param array $messages
33
     *
34
     * @throws UnitTestsException
35
     */
36 2
    public function run(array $messages)
37
    {
38 2
        $this->setTitle();
39
40 2
        $processBuilder = $this->processBuilder();
41 2
        $processBuilder->setTimeout(3600);
42 2
        $phpunit = $processBuilder->getProcess();
43 2
        $this->phpUnitProcessBuilder
44 2
            ->executeProcess($phpunit, $this->output);
45
46 2
        if (!$phpunit->isSuccessful()) {
47 1
            $this->output->writeln(BadJobLogo::paint($messages[MessageConfigData::KEY_ERROR_MESSAGE]));
48 1
            throw new UnitTestsException();
49
        }
50 1
    }
51
52
    /**
53
     * @return \Symfony\Component\Process\ProcessBuilder
54
     */
55 2
    protected function processBuilder()
56
    {
57 2
        return $this->phpUnitProcessBuilder->getProcessBuilder($this->getBinPath('phpunit'));
58
    }
59
60 2
    private function setTitle()
61
    {
62 2
        $this->outputHandler->setTitle('Running unit tests');
63 2
        $this->output->write($this->outputHandler->getTitle());
64 2
        $this->output->writeln($this->outputHandler->getSuccessfulStepMessage('Executing'));
65 2
    }
66
}
67