FileDownloadTest   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 103
Duplicated Lines 0 %

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 10 1
A createValidatorProvider() 0 61 1
A testCreateValidator() 0 9 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 AbterPhp\Framework\Validation\Rules\Uuid;
10
use Opulence\Validation\IValidator;
11
use Opulence\Validation\Rules\Factories\RulesFactory;
12
use PHPUnit\Framework\MockObject\MockObject;
13
use PHPUnit\Framework\TestCase;
14
15
class FileDownloadTest extends TestCase
16
{
17
    /** @var FileDownload - 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(), 'uuid' => new Uuid()]
30
        );
31
32
        $this->sut = new FileDownload($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'               => [
46
                [
47
                    'user_id' => '465c91df-9cc7-47e2-a2ef-8fe645753148',
48
                    'file_id' => '69da7b0b-8315-43c9-8f5d-a6a5ea09b051',
49
                ],
50
                true,
51
            ],
52
            'invalid-user-id-present'  => [
53
                [
54
                    'id'      => '465c91df-9cc7-47e2-a2ef-8fe64575314',
55
                    'user_id' => '465c91df-9cc7-47e2-a2ef-8fe64575314',
56
                    'file_id' => '69da7b0b-8315-43c9-8f5d-a6a5ea09b051',
57
                ],
58
                false,
59
            ],
60
            'invalid-user-id-not-uuid' => [
61
                [
62
                    'user_id' => '465c91df-9cc7-47e2-a2ef-8fe64575314',
63
                    'file_id' => '69da7b0b-8315-43c9-8f5d-a6a5ea09b051',
64
                ],
65
                false,
66
            ],
67
            'invalid-user-id-missing'  => [
68
                [
69
                    'file_id' => '69da7b0b-8315-43c9-8f5d-a6a5ea09b051',
70
                ],
71
                false,
72
            ],
73
            'invalid-user-id-empty'    => [
74
                [
75
                    'user_id' => '',
76
                    'file_id' => '69da7b0b-8315-43c9-8f5d-a6a5ea09b051',
77
                ],
78
                false,
79
            ],
80
            'invalid-file-id-not-uuid' => [
81
                [
82
                    'user_id' => '465c91df-9cc7-47e2-a2ef-8fe645753148',
83
                    'file_id' => '69da7b0b-8315-43c9-8f5d-a6a5ea09b05',
84
                ],
85
                false,
86
            ],
87
            'invalid-file-missing'     => [
88
                [
89
                    'user_id' => '465c91df-9cc7-47e2-a2ef-8fe645753148',
90
                ],
91
                false,
92
            ],
93
            'invalid-file-empty'       => [
94
                [
95
                    'user_id' => '465c91df-9cc7-47e2-a2ef-8fe645753148',
96
                    'file_id' => '',
97
                ],
98
                false,
99
            ],
100
        ];
101
    }
102
103
    /**
104
     * @dataProvider createValidatorProvider
105
     *
106
     * @param array $data
107
     * @param bool  $expectedResult
108
     */
109
    public function testCreateValidator(array $data, bool $expectedResult)
110
    {
111
        $validator = $this->sut->createValidator();
112
113
        $this->assertInstanceOf(IValidator::class, $validator);
114
115
        $actualResult = $validator->isValid($data);
116
117
        $this->assertSame($expectedResult, $actualResult);
118
    }
119
}
120