BlockTest::testCreateValidator()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
c 1
b 0
f 0
nc 1
nop 2
dl 0
loc 7
rs 10
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 BlockTest extends TestCase
16
{
17
    /** @var Block - 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
            ['forbidden' => new Forbidden(), 'exactlyOne' => new ExactlyOne(), 'uuid' => new Uuid()]
30
        );
31
32
        $this->sut = new Block($this->rulesFactoryMock);
33
    }
34
35
    /**
36
     * @return array
37
     */
38
    public function createValidatorProvider(): array
39
    {
40
        return [
41
            'empty-data'                              => [
42
                [],
43
                false,
44
            ],
45
            'valid-data-with-layout'                  => [
46
                [
47
                    'identifier' => 'foo',
48
                    'title'      => 'bar',
49
                    'body'       => 'baz',
50
                    'layout'     => 'quix',
51
                    'layout_id'  => '',
52
                ],
53
                true,
54
            ],
55
            'valid-data-with-layout-id'               => [
56
                [
57
                    'identifier' => 'foo',
58
                    'title'      => 'bar',
59
                    'body'       => 'baz',
60
                    'layout_id'  => '2d60b546-ddbc-4fc4-be66-a2824e61334f',
61
                ],
62
                true,
63
            ],
64
            'valid-data-missing-all-not-required'     => [
65
                [
66
                    'title'  => 'bar',
67
                    'layout' => 'quix',
68
                ],
69
                true,
70
            ],
71
            'invalid-id-present'                      => [
72
                [
73
                    'id'    => 'baf16ace-8fae-48a8-bbad-a610d7960e31',
74
                    'title' => 'bar',
75
                ],
76
                false,
77
            ],
78
        ];
79
    }
80
81
    /**
82
     * @dataProvider createValidatorProvider
83
     *
84
     * @param array $data
85
     * @param bool  $expectedResult
86
     */
87
    public function testCreateValidator(array $data, bool $expectedResult)
88
    {
89
        $validator = $this->sut->createValidator();
90
91
        $actualResult = $validator->isValid($data);
92
93
        $this->assertSame($expectedResult, $actualResult);
94
    }
95
}
96