|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* This file is part of Collision. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) Nuno Maduro <[email protected]> |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace NunoMaduro\Collision\Adapters\Phpunit; |
|
13
|
|
|
|
|
14
|
|
|
use NunoMaduro\Collision\Writer; |
|
15
|
|
|
use PHPUnit\Framework\AssertionFailedError; |
|
16
|
|
|
use PHPUnit\Framework\ExceptionWrapper; |
|
17
|
|
|
use PHPUnit\Framework\ExpectationFailedException; |
|
18
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
19
|
|
|
use Throwable; |
|
20
|
|
|
use Whoops\Exception\Inspector; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* @internal |
|
24
|
|
|
*/ |
|
25
|
|
|
final class OnError |
|
26
|
|
|
{ |
|
27
|
|
|
/** |
|
28
|
|
|
* Displays the error using Collision's writer |
|
29
|
|
|
* and terminates with exit code === 1. |
|
30
|
|
|
* |
|
31
|
|
|
* @param OutputInterface $output |
|
32
|
|
|
* @param Throwable $throwable |
|
33
|
|
|
* |
|
34
|
|
|
* @return void |
|
35
|
|
|
*/ |
|
36
|
|
|
public static function display(OutputInterface $output, Throwable $throwable) |
|
37
|
|
|
{ |
|
38
|
|
|
$writer = (new Writer())->setOutput($output); |
|
39
|
|
|
|
|
40
|
|
|
if ($throwable instanceof AssertionFailedError) { |
|
41
|
|
|
$writer->showTitle(false); |
|
42
|
|
|
$output->write('', true); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
$writer->ignoreFilesIn([ |
|
46
|
|
|
'/vendor\/phpunit\/phpunit\/src/', |
|
47
|
|
|
'/vendor\/mockery\/mockery/', |
|
48
|
|
|
'/vendor\/laravel\/framework\/src\/Illuminate\/Testing/', |
|
49
|
|
|
'/vendor\/laravel\/framework\/src\/Illuminate\/Foundation\/Testing/', |
|
50
|
|
|
]); |
|
51
|
|
|
|
|
52
|
|
|
if ($throwable instanceof ExceptionWrapper && $throwable->getOriginalException() !== null) { |
|
53
|
|
|
$throwable = $throwable->getOriginalException(); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
$inspector = new Inspector($throwable); |
|
57
|
|
|
|
|
58
|
|
|
$writer->write($inspector); |
|
59
|
|
|
|
|
60
|
|
|
if ($throwable instanceof ExpectationFailedException && $comparisionFailure = $throwable->getComparisonFailure()) { |
|
61
|
|
|
$output->write($comparisionFailure->getDiff()); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
exit(1); |
|
65
|
|
|
} |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
|