Passed
Push — master ( f83aa9...a7daae )
by Alex
03:39
created

ResultUnitTest::resultMethodDataProvider()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 36
Code Lines 24

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 24
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 36
rs 9.536
1
<?php
2
namespace Mezon\Application\Tests;
3
4
use Mezon\Rest;
5
use Mezon\Application\View;
6
use PHPUnit\Framework\TestCase;
7
8
class ResultUnitTest extends TestCase
9
{
10
11
    /**
12
     * Data provider
13
     *
14
     * @return array data provider
15
     */
16
    public function resultMethodDataProvider(): array
17
    {
18
        $presenter = new TestingPresenter(new View(), 'Result');
19
        return [
20
            [ // #0 testing presenter
21
                function (): TestCommonApplication {
22
                    unset($_GET['action-message']);
23
                    return new TestCommonApplication();
24
                },
25
                $presenter,
26
                function (array $params) {
27
                    $this->assertTrue($params[0]->wasCalled);
28
                }
29
            ],
30
            [ // #1 testing action message setup
31
                function (): TestCommonApplication {
32
                    $_GET['action-message'] = 'test-error';
33
                    return new TestCommonApplication();
34
                },
35
                $presenter,
36
                function (array $params): void {
37
                    $this->assertEquals('error', $params[1]->getTemplate()
38
                        ->getPageVar('action-message'));
39
                }
40
            ],
41
            [ // #2 no file with the messages
42
                function (): TestCommonApplication {
43
                    $_GET['action-message'] = 'test-error';
44
                    $application = new TestCommonApplication();
45
                    $application->hasMessages = false;
46
                    return $application;
47
                },
48
                $presenter,
49
                function (array $params): void {
50
                    $this->assertEquals('', $params[1]->getTemplate()
51
                        ->getPageVar('action-message'));
52
                }
53
            ]
54
        ];
55
    }
56
57
    /**
58
     * Testing result() method
59
     *
60
     * @param callable $setup
61
     *            setup of the test
62
     * @param object $handler
63
     *            controller or presenter
64
     * @param callable $assert
65
     *            asserter
66
     * @dataProvider resultMethodDataProvider
67
     */
68
    public function testResultMethod(callable $setup, object $handler, callable $assert = null): void
69
    {
70
        // setup
71
        $application = $setup();
72
73
        // test body
74
        $application->result($handler);
75
76
        // assertions
77
        if ($assert !== null) {
78
            $assert([
79
                $handler,
80
                $application
81
            ]);
82
        }
83
    }
84
}
85