Passed
Push — master ( 6af672...0107a4 )
by Peter
07:37
created

PageTest::createValidatorProvider()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 65
Code Lines 41

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 41
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 65
rs 9.264

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
3
declare(strict_types=1);
4
5
namespace AbterPhp\Website\Validation\Factory;
6
7
use AbterPhp\Admin\TestDouble\Validation\StubRulesFactory;
8
use AbterPhp\Framework\Validation\Rules\ExactlyOne;
9
use AbterPhp\Framework\Validation\Rules\Forbidden;
10
use AbterPhp\Framework\Validation\Rules\Uuid;
11
use Opulence\Validation\Rules\Factories\RulesFactory;
12
use PHPUnit\Framework\MockObject\MockObject;
13
use PHPUnit\Framework\TestCase;
14
15
class PageTest extends TestCase
16
{
17
    /** @var Page - System Under Test */
18
    protected $sut;
19
20
    /** @var RulesFactory|MockObject */
21
    protected $rulesFactoryMock;
22
23
    public function setUp(): void
24
    {
25
        parent::setUp();
26
27
        $this->rulesFactoryMock = StubRulesFactory::createRulesFactory(
28
            $this,
29
            [
30
                'forbidden'  => new Forbidden(),
31
                'uuid'       => new Uuid(),
32
                'exactlyOne' => new ExactlyOne(),
33
            ]
34
        );
35
36
        $this->sut = new Page($this->rulesFactoryMock);
37
    }
38
39
    /**
40
     * @return array
41
     */
42
    public function createValidatorProvider(): array
43
    {
44
        return [
45
            'empty-data'                                      => [
46
                [],
47
                false,
48
            ],
49
            'valid-data'                                      => [
50
                [
51
                    'identifier'  => 'foo',
52
                    'title'       => 'Foo',
53
                    'lede'        => 'bar',
54
                    'body'        => 'baz',
55
                    'is_draft'    => '1',
56
                    'category_id' => '5c032f90-bf10-4a77-81aa-b0b1254a8f66',
57
                    'layout_id'   => 'ebc97435-7280-4a67-855c-5d1ef0a2fd40',
58
                    'layout'      => '',
59
                    'header'      => 'thud',
60
                    'footer'      => 'grunt',
61
                    'css_files'   => 'bletch',
62
                    'js_files'    => 'fum',
63
                ],
64
                true,
65
            ],
66
            'valid-data-missing-all-not-required'             => [
67
                [
68
                    'title'     => 'Foo',
69
                    'layout_id' => 'ebc97435-7280-4a67-855c-5d1ef0a2fd40',
70
                ],
71
                true,
72
            ],
73
            'valid-data-missing-all-not-required-with-layout' => [
74
                [
75
                    'title'  => 'Foo',
76
                    'layout' => 'qux',
77
                ],
78
                true,
79
            ],
80
            'invalid-id-present'                              => [
81
                [
82
                    'id'        => 'baf16ace-8fae-48a8-bbad-a610d7960e31',
83
                    'title'     => 'Foo',
84
                    'layout_id' => 'ebc97435-7280-4a67-855c-5d1ef0a2fd40',
85
                ],
86
                false,
87
            ],
88
            'invalid-category-id-not-uuid'                    => [
89
                [
90
                    'layout_id' => 'ebc97435-7280-4a67-855c-5d1ef0a2fd4',
91
                ],
92
                false,
93
            ],
94
            'invalid-is-draft-is-not-numeric'                 => [
95
                [
96
                    'is_draft'  => 'foo',
97
                    'layout_id' => 'ebc97435-7280-4a67-855c-5d1ef0a2fd40',
98
                ],
99
                false,
100
            ],
101
            'invalid-layout-id-not-uuid'                      => [
102
                [
103
                    'category_id' => '5c032f90-bf10-4a77-81aa-b0b1254a8f6',
104
                    'layout_id'   => 'ebc97435-7280-4a67-855c-5d1ef0a2fd40',
105
                ],
106
                false,
107
            ],
108
        ];
109
    }
110
111
    /**
112
     * @dataProvider createValidatorProvider
113
     *
114
     * @param array $data
115
     * @param bool  $expectedResult
116
     */
117
    public function testCreateValidator(array $data, bool $expectedResult)
118
    {
119
        $validator = $this->sut->createValidator();
120
121
        $actualResult = $validator->isValid($data);
122
123
        $this->assertSame($expectedResult, $actualResult);
124
    }
125
}
126