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

testGetSetDataWithRealTemplate()   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\Transport\HttpRequestParams;
5
use Mezon\Router\Router;
6
use Mezon\HtmlTemplate\HtmlTemplate;
7
8
class PresenterUnitTest extends \PHPUnit\Framework\TestCase
9
{
10
11
    /**
12
     * Testing constructor
13
     */
14
    public function testConstructor(): void
15
    {
16
        // setupp
17
        $presenter = new TestingPresenter(new TestingView(), 'Test');
18
19
        $this->assertEquals('Test', $presenter->getPresenterName(), 'Invalid constructor call');
20
    }
21
22
    /**
23
     * Testing render
24
     */
25
    public function testRender(): void
26
    {
27
        // setupp
28
        $presenter = new TestingPresenter(new TestingView(), 'Test');
29
30
        $this->assertEquals('computed content', $presenter->run(), 'Invalid controller execution');
31
        $this->assertEquals('computed content 2', $presenter->run('test2'), 'Invalid controller execution');
32
    }
33
34
    /**
35
     * Testing default controller
36
     */
37
    public function testDefault(): void
38
    {
39
        // setupp
40
        $presenter = new TestingPresenter(new TestingView());
41
42
        // assertionss
43
        $this->expectExceptionMessage('Presenter Default was not found');
44
45
        // test bodyy
46
        $presenter->run();
47
    }
48
49
    /**
50
     * Method tests buildRoute
51
     */
52
    public function testBuildRoute(): void
53
    {
54
        // setup
55
        $presenter = new TestingPresenter(new TestingView());
56
57
        // test body
58
        $route = $presenter->buildRoute('/test/', 'POST', 'controllerTest');
0 ignored issues
show
Deprecated Code introduced by
The function Mezon\Application\Presenter::buildRoute() has been deprecated: Deprecated since 2020-08-28, use Application::buildRoute ( Ignorable by Annotation )

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

58
        $route = /** @scrutinizer ignore-deprecated */ $presenter->buildRoute('/test/', 'POST', 'controllerTest');

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
59
60
        // assertions
61
        $this->assertEquals('/test/', $route['route']);
62
        $this->assertEquals('POST', $route['method']);
63
        $this->assertInstanceOf(TestingPresenter::class, $route['callback'][0]);
64
        $this->assertEquals('controllerTest', $route['callback'][1]);
65
    }
66
67
    /**
68
     * Testing method setPresenterName
69
     */
70
    public function testSetPresenterName(): void
71
    {
72
        // setup
73
        $presenter = new TestingPresenter(new TestingView());
74
75
        // test body
76
        $presenter->setPresenterName('SomeName');
77
78
        // assertions
79
        $this->assertEquals('SomeName', $presenter->getPresenterName());
80
    }
81
82
    /**
83
     * Testing method getRequestParamsFetcher
84
     */
85
    public function testGetParamsFetcher(): void
86
    {
87
        // setup
88
        $router = new Router();
89
        $presenter = new TestingPresenter(new TestingView(), '', new HttpRequestParams($router));
90
91
        // test body
92
        $fetcher = $presenter->getRequestParamsFetcher();
93
94
        // assertions
95
        $this->assertInstanceOf(HttpRequestParams::class, $fetcher);
96
    }
97
98
    /**
99
     * Testing method getRequestParamsFetcher with exception
100
     */
101
    public function testGetParamsFetcherWithException(): void
102
    {
103
        // setup
104
        $presenter = new TestingPresenter(new TestingView());
105
106
        // assertions
107
        $this->expectException(\Exception::class);
108
109
        // test body
110
        $presenter->getRequestParamsFetcher();
111
    }
112
113
    /**
114
     * Testing get/set method
115
     */
116
    public function testNullViewInPresenterConstructor(): void
117
    {
118
        // setup
119
        $presenter = new TestingPresenter(null);
120
121
        // test body
122
        $presenter->setErrorCode(11);
123
        $presenter->setErrorMessage('msg1');
124
125
        // assertions
126
        $this->assertEquals(11, $presenter->getErrorCode());
127
        $this->assertEquals('msg1', $presenter->getErrorMessage());
128
    }
129
130
    /**
131
     * Testing get/set method
132
     */
133
    public function testUnsetViewInPresenterConstructor(): void
134
    {
135
        // setup
136
        $presenter = new TestingPresenter();
137
138
        // test body
139
        $presenter->setErrorCode(12);
140
        $presenter->setErrorMessage('msg2');
141
142
        // assertions
143
        $this->assertEquals(12, $presenter->getErrorCode());
144
        $this->assertEquals('msg2', $presenter->getErrorMessage());
145
    }
146
147
    /**
148
     * Testing get/set method
149
     */
150
    public function testGetSetDataWithRealTemplate(): void
151
    {
152
        // setup
153
        $presenter = new TestingPresenter(new TestingView(new HtmlTemplate(__DIR__, 'index')));
154
155
        // test body
156
        $presenter->setErrorCode(13);
157
        $presenter->setErrorMessage('msg3');
158
159
        // assertions
160
        $this->assertEquals(13, $presenter->getErrorCode());
161
        $this->assertEquals('msg3', $presenter->getErrorMessage());
162
    }
163
}
164