Failed Conditions
Push — master ( 01d6ae...9ca6d9 )
by Philippe
534:14 queued 469:10
created

testSymfonyBootingProcessFailedException()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 17
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 10
nc 2
nop 0
dl 0
loc 17
rs 9.9332
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace PhpSpellcheck\Tests\Exception;
6
7
use PhpSpellcheck\Exception\ProcessFailedException;
8
use PHPUnit\Framework\TestCase;
9
use Symfony\Component\Process\Exception\ExceptionInterface;
10
use Symfony\Component\Process\Process;
11
12
class ProcessFailedExceptionTest extends TestCase
13
{
14
    public function testSymfonyRunningProcessFailedException()
15
    {
16
        $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

16
        $process = new Process(/** @scrutinizer ignore-type */ 'non_existing_binaries');
Loading history...
17
        try {
18
            $process->mustRun();
19
        } catch (ExceptionInterface $exception) {
20
            $processFailure = new ProcessFailedException($process, $exception);
21
            $this->assertSame(
22
                'Process with command "non_existing_binaries" has failed running with exit code 127(Command not found)',
23
                $processFailure->getMessage()
24
            );
25
        }
26
    }
27
28
    public function testSymfonyBootingProcessFailedException()
29
    {
30
31
        $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

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