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

PresenterUnitTest::testConstructor()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 6
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
7
class PresenterUnitTest extends \PHPUnit\Framework\TestCase
8
{
9
10
    /**
11
     * Testing constructor
12
     */
13
    public function testConstructor(): void
14
    {
15
        // setupp
16
        $presenter = new TestingPresenter(new TestingView(), 'Test');
17
18
        $this->assertEquals('Test', $presenter->getPresenterName(), 'Invalid constructor call');
19
    }
20
21
    /**
22
     * Testing render
23
     */
24
    public function testRender(): void
25
    {
26
        // setupp
27
        $presenter = new TestingPresenter(new TestingView(), 'Test');
28
29
        $this->assertEquals('computed content', $presenter->run(), 'Invalid controller execution');
30
        $this->assertEquals('computed content 2', $presenter->run('test2'), 'Invalid controller execution');
31
    }
32
33
    /**
34
     * Testing default controller
35
     */
36
    public function testDefault(): void
37
    {
38
        // setupp
39
        $presenter = new TestingPresenter(new TestingView());
40
41
        // assertionss
42
        $this->expectExceptionMessage('Presenter Default was not found');
43
44
        // test bodyy
45
        $presenter->run();
46
    }
47
48
    /**
49
     * Method tests buildRoute
50
     */
51
    public function testBuildRoute(): void
52
    {
53
        // setup
54
        $presenter = new TestingPresenter(new TestingView());
55
56
        // test body
57
        $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

57
        $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...
58
59
        // assertions
60
        $this->assertEquals('/test/', $route['route']);
61
        $this->assertEquals('POST', $route['method']);
62
        $this->assertInstanceOf(TestingPresenter::class, $route['callback'][0]);
63
        $this->assertEquals('controllerTest', $route['callback'][1]);
64
    }
65
66
    /**
67
     * Testing method setPresenterName
68
     */
69
    public function testSetPresenterName(): void
70
    {
71
        // setup
72
        $presenter = new TestingPresenter(new TestingView());
73
74
        // test body
75
        $presenter->setPresenterName('SomeName');
76
77
        // assertions
78
        $this->assertEquals('SomeName', $presenter->getPresenterName());
79
    }
80
81
    /**
82
     * Testing method getRequestParamsFetcher
83
     */
84
    public function testGetParamsFetcher(): void
85
    {
86
        // setup
87
        $router = new Router();
88
        $presenter = new TestingPresenter(new TestingView(), '', new HttpRequestParams($router));
89
90
        // test body
91
        $fetcher = $presenter->getRequestParamsFetcher();
92
93
        // assertions
94
        $this->assertInstanceOf(HttpRequestParams::class, $fetcher);
95
    }
96
97
    /**
98
     * Testing method getRequestParamsFetcher with exception
99
     */
100
    public function testGetParamsFetcherWithException(): void
101
    {
102
        // setup
103
        $presenter = new TestingPresenter(new TestingView());
104
105
        // assertions
106
        $this->expectException(\Exception::class);
107
108
        // test body
109
        $presenter->getRequestParamsFetcher();
110
    }
111
}
112