Passed
Push — master ( b2b167...7e189a )
by Philippe
01:56
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
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');
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/');
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