Completed
Push — master ( c97ea9...aac971 )
by Alex
03:39
created

DataProvider()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 52
Code Lines 31

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 31
nc 1
nop 0
dl 0
loc 52
rs 9.424
c 1
b 0
f 1

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
namespace Mezon\Gui\Tests;
3
4
use Mezon\Gui\ListBuilder;
5
6
class CommonListBuilderCustomHeaderActionsUnitTest extends ListBuilderTestsBase
7
{
8
9
    /**
10
     * Testing data provider
11
     *
12
     * @return array testing data
13
     */
14
    public function DataProvider(): array
15
    {
16
        return [
17
            // #0, the first case - simple header
18
            [
19
                function (): object {
20
                    // setup
21
                    unset($_GET['create-button']);
22
                    $listBuilder = new ListBuilder\Common($this->getFields(), new FakeAdapter($this->getRecords()));
23
                    $listBuilder->setCustomHeaderActions('custom header actions');
24
                    return $listBuilder;
25
                },
26
                function ($result): void {
27
                    // asserting method
28
                    $this->assertStringContainsString('<form', $result);
29
                    $this->assertStringContainsString('</form>', $result);
30
                    $this->assertStringContainsString('method="post"', $result);
31
                    $this->assertStringContainsString('custom header actions', $result);
32
                }
33
            ],
34
            // #1, the first case - full header
35
            [
36
                function (): object {
37
                    // setup
38
                    $_GET['create-button'] = 1;
39
                    $listBuilder = new ListBuilder\Common($this->getFields(), new FakeAdapter($this->getRecords()));
40
                    $listBuilder->setCustomHeaderActions('custom header actions');
41
                    return $listBuilder;
42
                },
43
                function ($result): void {
44
                    // asserting method
45
                    $this->assertStringContainsString('<form', $result);
46
                    $this->assertStringContainsString('</form>', $result);
47
                    $this->assertStringContainsString('method="post"', $result);
48
                    $this->assertStringContainsString('custom header actions', $result);
49
                }
50
            ],
51
            // #2, the first case - simple header
52
            [
53
                function (): object {
54
                    // setup
55
                    $_GET['create-button'] = 1;
56
                    $listBuilder = new ListBuilder\Common($this->getFields(), new FakeAdapter([]));
57
                    $listBuilder->setCustomHeaderActions('custom header actions');
58
                    return $listBuilder;
59
                },
60
                function ($result): void {
61
                    // asserting method
62
                    $this->assertStringNotContainsString('<form', $result);
63
                    $this->assertStringNotContainsString('</form>', $result);
64
                    $this->assertStringNotContainsString('method="post"', $result);
65
                    $this->assertStringNotContainsString('custom header actions', $result);
66
                }
67
            ]
68
        ];
69
    }
70
71
    /**
72
     * Testing method
73
     *
74
     * @param callable $setup
75
     *            setup method
76
     * @param callable $assertions
77
     *            assertions method
78
     * @dataProvider DataProvider
79
     */
80
    public function testCustomHeaderActions(callable $setup, callable $assertions): void
81
    {
82
        // setup
83
        $obj = $setup();
84
85
        // test body
86
        $result = $obj->listingForm();
87
88
        // assertions
89
        $assertions($result);
90
    }
91
}
92