Completed
Push — master ( e3663d...ab0db8 )
by Alex
03:22
created

ViewStaticUnitTest::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
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 8
rs 10
1
<?php
2
use Mezon\HtmlTemplate\HtmlTemplate;
3
use Mezon\Application\View;
4
5
/**
6
 * View class for testing purposes
7
 *
8
 * @author Dodonov A.A.
9
 */
10
class TestingView extends View
11
{
12
13
    public function viewTest(): string
14
    {
15
        return 'rendered content';
16
    }
17
18
    public function viewTest2(): string
19
    {
20
        return 'rendered content 2';
21
    }
22
}
23
24
class ViewStaticUnitTest extends \PHPUnit\Framework\TestCase
25
{
26
27
    /**
28
     * Testing constructor
29
     */
30
    public function testConstructor(): void
31
    {
32
        // setup
33
        $view = new TestingView(null, 'test');
34
35
        // test body and assertions
36
        $this->assertEquals('test', $view->getViewName(), 'Invalid constructor call');
37
    }
38
39
    /**
40
     * Testing render
41
     */
42
    public function testRender(): void
43
    {
44
        // setup
45
        $view = new TestingView(null, 'test');
46
47
        // test body and assertions
48
        $this->assertEquals('rendered content', $view->render(), 'Invalid view renderring');
49
        $this->assertEquals('rendered content 2', $view->render('test2'), 'Invalid view renderring');
50
    }
51
52
    /**
53
     * Testing render
54
     */
55
    public function testDefault(): void
56
    {
57
        // setup
58
        $view = new TestingView();
59
60
        // assertions
61
        $this->expectExceptionMessage('View Default was not found');
62
63
        // test body
64
        $view->render();
65
    }
66
67
    /**
68
     * Testing template getter
69
     */
70
    public function testGetTemplate(): void
71
    {
72
        // setup
73
        $view = new TestingView(new HtmlTemplate(__DIR__ . '/res/templates/'));
74
75
        // test body and assertions
76
        $this->assertInstanceOf(HtmlTemplate::class, $view->getTemplate());
77
    }
78
79
    /**
80
     * Testing template getter with exception
81
     */
82
    public function testGetTemplateException(): void
83
    {
84
        // setup and assertions
85
        $view = new TestingView();
86
        $this->expectException(\Exception::class);
87
88
        // test body
89
        $view->getTemplate();
90
    }
91
}
92