Completed
Push — master ( 21ef4f...df9e52 )
by Alex
04:31
created

PresenterUnitTest   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 72
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 18
c 1
b 0
f 1
dl 0
loc 72
rs 10
wmc 5

5 Methods

Rating   Name   Duplication   Size   Complexity  
A testSetPresenterName() 0 10 1
A testBuildRoute() 0 13 1
A testConstructor() 0 6 1
A testRender() 0 7 1
A testDefault() 0 10 1
1
<?php
2
3
/**
4
 * Presenter class for testing purposes
5
 *
6
 * @author Dodonov A.A.
7
 */
8
class TestingPresenter extends \Mezon\Application\Presenter
0 ignored issues
show
Deprecated Code introduced by
The class Mezon\Application\Presenter has been deprecated: since 2020-06-26 ( Ignorable by Annotation )

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

8
class TestingPresenter extends /** @scrutinizer ignore-deprecated */ \Mezon\Application\Presenter
Loading history...
9
{
10
11
    public function presenterTest(): string
12
    {
13
        return 'computed content';
14
    }
15
16
    public function presenterTest2(): string
17
    {
18
        return 'computed content 2';
19
    }
20
}
21
22
class PresenterUnitTest extends \PHPUnit\Framework\TestCase
23
{
24
25
    /**
26
     * Testing constructor
27
     */
28
    public function testConstructor(): void
29
    {
30
        // setupp
31
        $presenter = new TestingPresenter('Test');
32
33
        $this->assertEquals('Test', $presenter->getPresenterName(), 'Invalid constructor call');
34
    }
35
36
    /**
37
     * Testing render
38
     */
39
    public function testRender(): void
40
    {
41
        // setupp
42
        $presenter = new TestingPresenter('Test');
43
44
        $this->assertEquals('computed content', $presenter->run(), 'Invalid controller execution');
45
        $this->assertEquals('computed content 2', $presenter->run('test2'), 'Invalid controller execution');
46
    }
47
48
    /**
49
     * Testing default controller
50
     */
51
    public function testDefault(): void
52
    {
53
        // setupp
54
        $presenter = new TestingPresenter();
55
56
        // assertionss
57
        $this->expectExceptionMessage('Presenter Default was not found');
58
59
        // test bodyy
60
        $presenter->run();
61
    }
62
63
    /**
64
     * Method tests buildRoute
65
     */
66
    public function testBuildRoute(): void
67
    {
68
        // setup
69
        $presenter = new TestingPresenter();
70
71
        // test body
72
        $route = $presenter->buildRoute('/test/', 'POST', 'controllerTest');
73
74
        // assertions
75
        $this->assertEquals('/test/', $route['route']);
76
        $this->assertEquals('POST', $route['method']);
77
        $this->assertInstanceOf(TestingPresenter::class, $route['callback'][0]);
78
        $this->assertEquals('controllerTest', $route['callback'][1]);
79
    }
80
81
    /**
82
     * Testing method setPresenterName
83
     */
84
    public function testSetPresenterName(): void
85
    {
86
        // setup
87
        $presenter = new TestingPresenter();
88
89
        // test body
90
        $presenter->setPresenterName('SomeName');
91
92
        // assertions
93
        $this->assertEquals('SomeName', $presenter->getPresenterName());
94
    }
95
}
96