Passed
Pull Request — master (#15)
by Victor
03:33
created

testTemplateShouldRenderIfNoExceptionIsThrown()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 6
dl 0
loc 9
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
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')
0 ignored issues
show
Bug introduced by
The method method() does not exist on Psr\Http\Message\ServerRequestInterface. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

32
            ->/** @scrutinizer ignore-call */ 
33
              method('getAttribute')

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.

Loading history...
Bug introduced by
The method method() does not exist on PHPUnit\Framework\MockObject\MockObject. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

32
            ->/** @scrutinizer ignore-call */ 
33
              method('getAttribute')

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.

Loading history...
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