1
|
|
|
<?php |
2
|
|
|
use Mezon\Transport\HttpRequestParams; |
3
|
|
|
use Mezon\Router\Router; |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* Presenter class for testing purposes |
7
|
|
|
* |
8
|
|
|
* @author Dodonov A.A. |
9
|
|
|
*/ |
10
|
|
|
class TestingPresenter extends \Mezon\Application\Presenter |
|
|
|
|
11
|
|
|
{ |
12
|
|
|
|
13
|
|
|
public function presenterTest(): string |
14
|
|
|
{ |
15
|
|
|
return 'computed content'; |
16
|
|
|
} |
17
|
|
|
|
18
|
|
|
public function presenterTest2(): string |
19
|
|
|
{ |
20
|
|
|
return 'computed content 2'; |
21
|
|
|
} |
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
class PresenterUnitTest extends \PHPUnit\Framework\TestCase |
25
|
|
|
{ |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Testing constructor |
29
|
|
|
*/ |
30
|
|
|
public function testConstructor(): void |
31
|
|
|
{ |
32
|
|
|
// setupp |
33
|
|
|
$presenter = new TestingPresenter('Test'); |
34
|
|
|
|
35
|
|
|
$this->assertEquals('Test', $presenter->getPresenterName(), 'Invalid constructor call'); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Testing render |
40
|
|
|
*/ |
41
|
|
|
public function testRender(): void |
42
|
|
|
{ |
43
|
|
|
// setupp |
44
|
|
|
$presenter = new TestingPresenter('Test'); |
45
|
|
|
|
46
|
|
|
$this->assertEquals('computed content', $presenter->run(), 'Invalid controller execution'); |
47
|
|
|
$this->assertEquals('computed content 2', $presenter->run('test2'), 'Invalid controller execution'); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* Testing default controller |
52
|
|
|
*/ |
53
|
|
|
public function testDefault(): void |
54
|
|
|
{ |
55
|
|
|
// setupp |
56
|
|
|
$presenter = new TestingPresenter(); |
57
|
|
|
|
58
|
|
|
// assertionss |
59
|
|
|
$this->expectExceptionMessage('Presenter Default was not found'); |
60
|
|
|
|
61
|
|
|
// test bodyy |
62
|
|
|
$presenter->run(); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* Method tests buildRoute |
67
|
|
|
*/ |
68
|
|
|
public function testBuildRoute(): void |
69
|
|
|
{ |
70
|
|
|
// setup |
71
|
|
|
$presenter = new TestingPresenter(); |
72
|
|
|
|
73
|
|
|
// test body |
74
|
|
|
$route = $presenter->buildRoute('/test/', 'POST', 'controllerTest'); |
75
|
|
|
|
76
|
|
|
// assertions |
77
|
|
|
$this->assertEquals('/test/', $route['route']); |
78
|
|
|
$this->assertEquals('POST', $route['method']); |
79
|
|
|
$this->assertInstanceOf(TestingPresenter::class, $route['callback'][0]); |
80
|
|
|
$this->assertEquals('controllerTest', $route['callback'][1]); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* Testing method setPresenterName |
85
|
|
|
*/ |
86
|
|
|
public function testSetPresenterName(): void |
87
|
|
|
{ |
88
|
|
|
// setup |
89
|
|
|
$presenter = new TestingPresenter(); |
90
|
|
|
|
91
|
|
|
// test body |
92
|
|
|
$presenter->setPresenterName('SomeName'); |
93
|
|
|
|
94
|
|
|
// assertions |
95
|
|
|
$this->assertEquals('SomeName', $presenter->getPresenterName()); |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* Testing method getParamsFetcher |
100
|
|
|
*/ |
101
|
|
|
public function testGetParamsFetcher(): void |
102
|
|
|
{ |
103
|
|
|
// setup |
104
|
|
|
$router = new Router(); |
105
|
|
|
$presenter = new TestingPresenter('', new HttpRequestParams($router)); |
106
|
|
|
|
107
|
|
|
// test body |
108
|
|
|
$fetcher = $presenter->getParamsFetcher(); |
109
|
|
|
|
110
|
|
|
// assertions |
111
|
|
|
$this->assertInstanceOf(HttpRequestParams::class, $fetcher); |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* Testing method getParamsFetcher with exception |
116
|
|
|
*/ |
117
|
|
|
public function testGetParamsFetcherWithException() : void |
118
|
|
|
{ |
119
|
|
|
// setup |
120
|
|
|
$presenter = new TestingPresenter(); |
121
|
|
|
|
122
|
|
|
// assertions |
123
|
|
|
$this->expectException(\Exception::class); |
124
|
|
|
|
125
|
|
|
// test body |
126
|
|
|
$presenter->getParamsFetcher(); |
127
|
|
|
} |
128
|
|
|
} |
129
|
|
|
|