Passed
Push — master ( 175363...8a85d8 )
by Alex
02:15
created

ViewUnitTest::testSetErrorMessage()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

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