FileCategoryTest   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 71
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 27
c 1
b 0
f 0
dl 0
loc 71
rs 10
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A createValidatorProvider() 0 32 1
A testCreateValidator() 0 9 1
A setUp() 0 7 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace AbterPhp\Files\Validation\Factory;
6
7
use AbterPhp\Admin\TestDouble\Validation\StubRulesFactory;
8
use AbterPhp\Framework\Validation\Rules\Forbidden;
9
use Opulence\Validation\IValidator;
10
use Opulence\Validation\Rules\Factories\RulesFactory;
11
use PHPUnit\Framework\MockObject\MockObject;
12
use PHPUnit\Framework\TestCase;
13
14
class FileCategoryTest extends TestCase
15
{
16
    /** @var FileCategory - System Under Test */
17
    protected $sut;
18
19
    /** @var RulesFactory|MockObject */
20
    protected $rulesFactoryMock;
21
22
    public function setUp(): void
23
    {
24
        parent::setUp();
25
26
        $this->rulesFactoryMock = StubRulesFactory::createRulesFactory($this, ['forbidden' => new Forbidden()]);
27
28
        $this->sut = new FileCategory($this->rulesFactoryMock);
29
    }
30
31
    /**
32
     * @return array
33
     */
34
    public function createValidatorProvider(): array
35
    {
36
        return [
37
            'empty-data'           => [
38
                [],
39
                false,
40
            ],
41
            'valid-data'           => [
42
                [
43
                    'name' => 'foo',
44
                ],
45
                true,
46
            ],
47
            'invalid-id-present'   => [
48
                [
49
                    'id'   => '465c91df-9cc7-47e2-a2ef-8fe64575314',
50
                    'name' => 'foo',
51
                ],
52
                false,
53
            ],
54
            'invalid-name-missing' => [
55
                [
56
                    'id' => '465c91df-9cc7-47e2-a2ef-8fe64575314',
57
                ],
58
                false,
59
            ],
60
            'invalid-name-empty'   => [
61
                [
62
                    'id'   => '465c91df-9cc7-47e2-a2ef-8fe64575314',
63
                    'name' => '',
64
                ],
65
                false,
66
            ],
67
        ];
68
    }
69
70
    /**
71
     * @dataProvider createValidatorProvider
72
     *
73
     * @param array $data
74
     * @param bool  $expectedResult
75
     */
76
    public function testCreateValidator(array $data, bool $expectedResult)
77
    {
78
        $validator = $this->sut->createValidator();
79
80
        $this->assertInstanceOf(IValidator::class, $validator);
81
82
        $actualResult = $validator->isValid($data);
83
84
        $this->assertSame($expectedResult, $actualResult);
85
    }
86
}
87