Passed
Push — master ( 517a56...adf5dc )
by Alexander
02:50
created

PHPUnitCommand   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
eloc 18
c 1
b 0
f 0
dl 0
loc 30
ccs 0
cts 13
cp 0
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A run() 0 24 1
A __construct() 0 2 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Yii\Debug\Api\Inspector\Command;
6
7
use Symfony\Component\Process\Process;
8
use Yiisoft\Aliases\Aliases;
9
use Yiisoft\Yii\Debug\Api\Inspector\Test\PHPUnitJSONReporter;
10
11
class PHPUnitCommand
12
{
13
    public function __construct(private Aliases $aliases)
14
    {
15
    }
16
17
    public function run()
18
    {
19
        $projectDirectory = $this->aliases->get('@root');
20
        $debugDirectory = $this->aliases->get('@runtime/debug');
21
22
        $extension = PHPUnitJSONReporter::class;
23
        $params = [
24
            'vendor/bin/phpunit',
25
            '--printer',
26
            $extension,
27
            '-vvv',
28
        ];
29
30
        $process = new Process($params);
31
32
        $process
33
            ->setEnv([PHPUnitJSONReporter::ENVIRONMENT_VARIABLE_DIRECTORY_NAME => $debugDirectory])
34
            ->setWorkingDirectory($projectDirectory)
35
            ->setTimeout(null)
36
            ->run();
37
38
        return json_decode(
39
            file_get_contents($debugDirectory . DIRECTORY_SEPARATOR . PHPUnitJSONReporter::FILENAME),
40
            true
41
        );
42
    }
43
}
44