Passed
Push — master ( 141848...a80b50 )
by Philippe
06:19
created

ProcessFailedExceptionTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 19
dl 0
loc 34
rs 10
c 0
b 0
f 0
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A testSymfonyRunningProcessFailedException() 0 11 2
A testSymfonyBootingProcessFailedException() 0 17 2
1
<?php
2
3
declare(strict_types=1);
4
5
use PhpSpellcheck\Exception\ProcessFailedException;
6
use PHPUnit\Framework\TestCase;
7
use Symfony\Component\Process\Exception\ExceptionInterface;
8
use Symfony\Component\Process\Process;
9
10
class ProcessFailedExceptionTest extends TestCase
11
{
12
    public function testSymfonyRunningProcessFailedException(): void
13
    {
14
        $process = new Process('non_existing_binaries');
0 ignored issues
show
Bug introduced by
'non_existing_binaries' of type string is incompatible with the type array expected by parameter $command of Symfony\Component\Process\Process::__construct(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

14
        $process = new Process(/** @scrutinizer ignore-type */ 'non_existing_binaries');
Loading history...
15
16
        try {
17
            $process->mustRun();
18
        } catch (ExceptionInterface $exception) {
19
            $processFailure = new ProcessFailedException($process, $exception);
20
            $this->assertSame(
21
                'Process with command "non_existing_binaries" has failed running with exit code 127(Command not found)',
22
                $processFailure->getMessage()
23
            );
24
        }
25
    }
26
27
    public function testSymfonyBootingProcessFailedException(): void
28
    {
29
        $process = new Process('echo test', __DIR__ . '/notfound/');
0 ignored issues
show
Bug introduced by
'echo test' of type string is incompatible with the type array expected by parameter $command of Symfony\Component\Process\Process::__construct(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

29
        $process = new Process(/** @scrutinizer ignore-type */ 'echo test', __DIR__ . '/notfound/');
Loading history...
30
31
        try {
32
            $process->mustRun();
33
        } catch (ExceptionInterface $exception) {
34
            $processFailure = new ProcessFailedException($process, $exception);
35
            $this->assertSame(
36
                'Process with command "echo test" has failed with exit code 0()',
37
                $processFailure->getMessage()
38
            );
39
40
            return;
41
        }
42
43
        $this->markTestSkipped('Test is only relevant for symfony/process: ^4.0');
44
    }
45
}
46