EmbeddingTest::setUp()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 7
c 1
b 0
f 0
dl 0
loc 11
rs 10
cc 1
nc 1
nop 0
1
<?php
2
declare(strict_types=1);
3
4
namespace Shoot\Shoot\Tests\Integration\Embedding;
5
6
use PHPUnit\Framework\MockObject\MockObject;
7
use Shoot\Shoot\PresenterInterface;
8
use Shoot\Shoot\Tests\Integration\IntegrationTestCase;
9
10
final class EmbeddingTest extends IntegrationTestCase
11
{
12
    /** @var PresenterInterface|MockObject */
13
    private $pagePresenter;
14
15
    protected function setUp(): void
16
    {
17
        $this->pagePresenter = $this->createMock(PresenterInterface::class);
18
        $this->pagePresenter
19
            ->method('present')
20
            ->will($this->returnArgument(1));
21
22
        $this->addToContainer('PagePresenter', $this->pagePresenter);
23
        $this->setTemplateDirectory(__DIR__ . '/Templates');
24
25
        parent::setUp();
26
    }
27
28
    public function testEmbeddedTemplatesShouldHaveTheirPresentersInvoked(): void
29
    {
30
        $output = $this->renderTemplate('page.twig');
31
32
        $this->assertContains('<li><a href="/">Home</a></li>', $output);
33
    }
34
35
    public function testOverriddenBlocksShouldReceiveVariablesFromParent(): void
36
    {
37
        $output = $this->renderTemplate('page.twig');
38
39
        $this->assertContains('<title>page_title</title>', $output);
40
        $this->assertContains('<h1>page_title</h1>', $output);
41
        $this->assertContains('<p>page_content</p>', $output);
42
    }
43
44
    public function testEmbeddedTemplatesShouldReceiveVariablesPassedAsArguments(): void
45
    {
46
        $output = $this->renderTemplate('page.twig');
47
48
        $this->assertContains('<main class="main--overriden">', $output);
49
    }
50
51
    public function testPresentersShouldOnlyBeCalledOnce(): void
52
    {
53
        $this->pagePresenter
54
            ->expects($this->once())
55
            ->method('present');
56
57
        $this->renderTemplate('page.twig');
58
    }
59
}
60