|
1
|
|
|
<?php |
|
2
|
|
|
declare(strict_types=1); |
|
3
|
|
|
|
|
4
|
|
|
namespace Shoot\Shoot\Tests\Integration\ErrorSuppression; |
|
5
|
|
|
|
|
6
|
|
|
use Shoot\Shoot\Middleware\SuppressionMiddleware; |
|
7
|
|
|
use Shoot\Shoot\Tests\Integration\IntegrationTestCase; |
|
8
|
|
|
|
|
9
|
|
|
final class ErrorSuppressionTest extends IntegrationTestCase |
|
10
|
|
|
{ |
|
11
|
|
|
protected function setUp(): void |
|
12
|
|
|
{ |
|
13
|
|
|
$this->addMiddleware(new SuppressionMiddleware()); |
|
14
|
|
|
$this->setTemplateDirectory(__DIR__ . '/Templates'); |
|
15
|
|
|
|
|
16
|
|
|
parent::setUp(); |
|
17
|
|
|
} |
|
18
|
|
|
|
|
19
|
|
|
public function testTemplateShouldRenderIfNoExceptionIsThrown(): void |
|
20
|
|
|
{ |
|
21
|
|
|
$output = $this->renderTemplate('page.twig'); |
|
22
|
|
|
|
|
23
|
|
|
$this->assertContains('<h1>page_title</h1>', $output); |
|
24
|
|
|
$this->assertContains('<!-- before -->', $output); |
|
25
|
|
|
$this->assertContains('<p>item</p>', $output); |
|
26
|
|
|
$this->assertContains('<!-- after -->', $output); |
|
27
|
|
|
$this->assertContains('<p>page_footer</p>', $output); |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
public function testIncludedTemplateShouldThrowAnException(): void |
|
31
|
|
|
{ |
|
32
|
|
|
$this->expectExceptionMessage('item_exception'); |
|
33
|
|
|
|
|
34
|
|
|
$this->getRequestMock() |
|
35
|
|
|
->method('getAttribute') |
|
36
|
|
|
->will($this->returnValueMap([ |
|
37
|
|
|
['throw_logic_exception', 'n', 'n'], |
|
38
|
|
|
['throw_runtime_exception', 'n', 'y'], |
|
39
|
|
|
])); |
|
40
|
|
|
|
|
41
|
|
|
$this->renderTemplate('item.twig'); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
public function testOptionalBlocksShouldDiscardTheirContentsOnRuntimeExceptions(): void |
|
45
|
|
|
{ |
|
46
|
|
|
$this->getRequestMock() |
|
47
|
|
|
->method('getAttribute') |
|
48
|
|
|
->will($this->returnValueMap([ |
|
49
|
|
|
['throw_logic_exception', 'n', 'n'], |
|
50
|
|
|
['throw_runtime_exception', 'n', 'y'], |
|
51
|
|
|
])); |
|
52
|
|
|
|
|
53
|
|
|
$output = $this->renderTemplate('page.twig'); |
|
54
|
|
|
|
|
55
|
|
|
$this->assertContains('<h1>page_title</h1>', $output); |
|
56
|
|
|
$this->assertNotContains('<!-- before -->', $output); |
|
57
|
|
|
$this->assertNotContains('<p>item</p>', $output); |
|
58
|
|
|
$this->assertNotContains('<!-- after -->', $output); |
|
59
|
|
|
$this->assertContains('<p>page_footer</p>', $output); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
public function testOptionalBlocksShouldNotSuppressLogicExceptions(): void |
|
63
|
|
|
{ |
|
64
|
|
|
$this->expectExceptionMessage('Variable "unknown_variable" does not exist'); |
|
65
|
|
|
|
|
66
|
|
|
$this->getRequestMock() |
|
67
|
|
|
->method('getAttribute') |
|
68
|
|
|
->will($this->returnValueMap([ |
|
69
|
|
|
['throw_logic_exception', 'n', 'y'], |
|
70
|
|
|
['throw_runtime_exception', 'n', 'n'], |
|
71
|
|
|
])); |
|
72
|
|
|
|
|
73
|
|
|
$this->renderTemplate('page.twig'); |
|
74
|
|
|
} |
|
75
|
|
|
} |
|
76
|
|
|
|