-
Notifications
You must be signed in to change notification settings - Fork 184
/
ViewTest.php
95 lines (81 loc) · 2.64 KB
/
ViewTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
<?php
namespace Facade\Ignition\Tests;
use Facade\Ignition\Exceptions\ViewException;
use Facade\Ignition\Exceptions\ViewExceptionWithSolution;
use Facade\IgnitionContracts\BaseSolution;
use Facade\IgnitionContracts\ProvidesSolution;
use Facade\IgnitionContracts\Solution;
use Illuminate\Foundation\Auth\User;
use Illuminate\Support\Facades\View;
class ViewTest extends TestCase
{
public function setUp(): void
{
parent::setUp();
View::addLocation(__DIR__.'/stubs/views');
}
/** @test */
public function it_detects_blade_view_exceptions()
{
$this->expectException(ViewException::class);
view('blade-exception')->render();
}
/** @test */
public function it_detects_the_original_line_number_in_view_exceptions()
{
try {
view('blade-exception')->render();
} catch (ViewException $exception) {
$this->assertSame(3, $exception->getLine());
}
}
/** @test */
public function it_detects_the_original_line_number_in_view_exceptions_with_utf8_characters()
{
try {
view('blade-exception-utf8')->render();
} catch (ViewException $exception) {
$this->assertSame(11, $exception->getLine());
}
}
/** @test */
public function it_adds_additional_blade_information_to_the_exception()
{
$viewData = [
'app' => 'foo',
'data' => true,
'user' => new User(),
];
try {
view('blade-exception', $viewData)->render();
} catch (ViewException $exception) {
$this->assertSame($viewData, $exception->getViewData());
}
}
/** @test */
public function it_adds_base_exception_solution_to_view_exception()
{
try {
$exception = new ExceptionWithSolution();
view('solution-exception', ['exception' => $exception])->render();
} catch (ViewException $exception) {
$this->assertTrue($exception instanceof ViewExceptionWithSolution);
$this->assertInstanceOf(Solution::class, $exception->getSolution());
$this->assertSame('This is a solution', $exception->getSolution()->getSolutionTitle());
}
}
/** @test */
public function it_detects_php_view_exceptions()
{
$this->expectException(ViewException::class);
view('php-exception')->render();
}
}
class ExceptionWithSolution extends \Exception implements ProvidesSolution
{
public function getSolution(): Solution
{
return BaseSolution::create('This is a solution')
->setSolutionDescription('With a description');
}
}