Passed
Push — master ( 39e51c...ca88cb )
by Alex
03:38
created

CustomHeaderActionsUnitTest::actionsDataProvider()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 52
Code Lines 31

Duplication

Lines 0
Ratio 0 %

Importance

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

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