|
1
|
|
|
<?php |
|
2
|
|
|
declare(strict_types=1); |
|
3
|
|
|
|
|
4
|
|
|
namespace Shoot\Shoot\Tests\Integration\ErrorSuppression; |
|
5
|
|
|
|
|
6
|
|
|
use Shoot\Shoot\Tests\Integration\IntegrationTestCase; |
|
7
|
|
|
|
|
8
|
|
|
final class ErrorSuppressionTest extends IntegrationTestCase |
|
9
|
|
|
{ |
|
10
|
|
|
/** @var string */ |
|
11
|
|
|
protected $templateDirectory = __DIR__ . '/Templates'; |
|
12
|
|
|
|
|
13
|
|
|
public function testTemplateShouldRenderIfNoExceptionIsThrown() |
|
14
|
|
|
{ |
|
15
|
|
|
$output = $this->renderTemplate('page.twig'); |
|
16
|
|
|
|
|
17
|
|
|
$this->assertContains('<h1>page_title</h1>', $output); |
|
18
|
|
|
$this->assertContains('<!-- before -->', $output); |
|
19
|
|
|
$this->assertContains('<p>item</p>', $output); |
|
20
|
|
|
$this->assertContains('<!-- after -->', $output); |
|
21
|
|
|
$this->assertContains('<p>page_footer</p>', $output); |
|
22
|
|
|
} |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* @return void |
|
26
|
|
|
*/ |
|
27
|
|
|
public function testIncludedTemplateShouldThrowAnException() |
|
28
|
|
|
{ |
|
29
|
|
|
$this->expectExceptionMessage('item_exception'); |
|
30
|
|
|
|
|
31
|
|
|
$this->request |
|
32
|
|
|
->method('getAttribute') |
|
|
|
|
|
|
33
|
|
|
->will($this->returnValueMap([ |
|
34
|
|
|
['throw_logic_exception', 'n', 'n'], |
|
35
|
|
|
['throw_runtime_exception', 'n', 'y'], |
|
36
|
|
|
])); |
|
37
|
|
|
|
|
38
|
|
|
$this->renderTemplate('item.twig'); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* @return void |
|
43
|
|
|
*/ |
|
44
|
|
|
public function testOptionalBlocksShouldDiscardTheirContentsOnRuntimeExceptions() |
|
45
|
|
|
{ |
|
46
|
|
|
$this->request |
|
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
|
|
|
/** |
|
63
|
|
|
* @return void |
|
64
|
|
|
*/ |
|
65
|
|
|
public function testOptionalBlocksShouldNotSuppressLogicExceptions() |
|
66
|
|
|
{ |
|
67
|
|
|
$this->expectExceptionMessage('Variable "unknown_variable" does not exist'); |
|
68
|
|
|
|
|
69
|
|
|
$this->request |
|
70
|
|
|
->method('getAttribute') |
|
71
|
|
|
->will($this->returnValueMap([ |
|
72
|
|
|
['throw_logic_exception', 'n', 'y'], |
|
73
|
|
|
['throw_runtime_exception', 'n', 'n'], |
|
74
|
|
|
])); |
|
75
|
|
|
|
|
76
|
|
|
$this->renderTemplate('page.twig'); |
|
77
|
|
|
} |
|
78
|
|
|
} |
|
79
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.