Completed
Push — master ( 04f83a...b71153 )
by Alex
09:15
created

ViewUnitTest::testGetTemplateException()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 0
dl 0
loc 8
rs 10
c 0
b 0
f 0
1
<?php
2
namespace Mezon\Application\Tests;
3
4
use Mezon\HtmlTemplate\HtmlTemplate;
5
use Mezon\Application\Presenter;
6
use Mezon\Application\View;
7
8
class ViewUnitTest extends \PHPUnit\Framework\TestCase
9
{
10
11
    /**
12
     * Testing constructor
13
     */
14
    public function testConstructor(): void
15
    {
16
        // setup
17
        $view = new TestingView(null, 'test');
18
19
        // test body and assertions
20
        $this->assertEquals('test', $view->getViewName(), 'Invalid constructor call');
21
    }
22
23
    /**
24
     * Testing render
25
     */
26
    public function testRender(): void
27
    {
28
        // setup
29
        $view = new TestingView(null, 'test');
30
31
        // test body and assertions
32
        $this->assertEquals('rendered content', $view->render(), 'Invalid view renderring');
33
        $this->assertEquals('rendered content 2', $view->render('test2'), 'Invalid view renderring');
34
    }
35
36
    /**
37
     * Testing render
38
     */
39
    public function testDefault(): void
40
    {
41
        // setup
42
        $view = new TestingView();
43
44
        // assertions
45
        $this->expectExceptionMessage('View Default was not found');
46
47
        // test body
48
        $view->render();
49
    }
50
51
    /**
52
     * Testing template getter
53
     */
54
    public function testGetTemplate(): void
55
    {
56
        // setup
57
        $view = new TestingView(new HtmlTemplate(__DIR__ . '/res/templates/'));
58
59
        // test body and assertions
60
        $this->assertInstanceOf(HtmlTemplate::class, $view->getTemplate());
61
    }
62
63
    /**
64
     * Testing template getter with exception
65
     */
66
    public function testGetTemplateException(): void
67
    {
68
        // setup and assertions
69
        $view = new TestingView();
70
        $this->expectException(\Exception::class);
71
72
        // test body
73
        $view->getTemplate();
74
    }
75
76
    /**
77
     * Testing method setErrorCode
78
     */
79
    public function testSetErrorCode(): void
80
    {
81
        // setup
82
        $view = new TestingView(new HtmlTemplate(__DIR__));
83
84
        // test body
85
        $view->setErrorCode(111);
86
87
        // assertions
88
        $this->assertEquals(111, $view->getErrorCode());
89
        $this->assertEquals(111, $view->getTemplate()
90
            ->getPageVar(TestingView::ERROR_CODE));
91
    }
92
93
    /**
94
     * Testing method setErrorMessage
95
     */
96
    public function testSetErrorMessage(): void
97
    {
98
        // setup
99
        $view = new TestingView(new HtmlTemplate(__DIR__));
100
101
        // test body
102
        $view->setErrorMessage('111');
103
104
        // assertions
105
        $this->assertEquals('111', $view->getErrorMessage());
106
        $this->assertEquals('111', $view->getTemplate()
107
            ->getPageVar(TestingView::ERROR_MESSAGE));
108
    }
109
}
110