NameUserValidationTest::testItNameValid()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 2
c 1
b 0
f 0
dl 0
loc 5
rs 10
cc 1
nc 1
nop 1
1
<?php declare(strict_types=1);
2
/*
3
 * This file is part of FlexPHP.
4
 *
5
 * (c) Freddie Gar <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
namespace FlexPHP\Database\Tests\Unit\Validations;
11
12
use FlexPHP\Database\Exception\NameUserValidationException;
13
use FlexPHP\Database\Tests\TestCase;
14
use FlexPHP\Database\Validations\NameUserValidation;
15
16
class NameUserValidationTest extends TestCase
17
{
18
    /**
19
     * @dataProvider getNameInvalid
20
     *
21
     * @param string $name
22
     * @return void
23
     */
24
    public function testItNameInvalidThrowException($name): void
25
    {
26
        $this->expectException(NameUserValidationException::class);
27
28
        (new NameUserValidation($name))->validate();
29
    }
30
31
    /**
32
     * @dataProvider getNameValid
33
     *
34
     * @param string $name
35
     * @return void
36
     */
37
    public function testItNameValid($name): void
38
    {
39
        (new NameUserValidation($name))->validate();
40
41
        $this->assertTrue(true);
42
    }
43
44
    public function getNameInvalid(): array
45
    {
46
        return [
47
            // [null],
48
            // [[]],
49
            [''],
50
            [' '],
51
            ['has space'],
52
            ['1jon'],
53
            ['j?on'],
54
            ['j!on'],
55
            ['ñon'],
56
            ['_jon'],
57
            ['j' . str_repeat('o', 31) . 'n'],
58
        ];
59
    }
60
61
    public function getNameValid(): array
62
    {
63
        return [
64
            ['jon'],
65
            ['jon_doe'],
66
            ['jon-doe'],
67
            ['jon1'],
68
            ['jon_'],
69
            ['j' . str_repeat('o', 30) . 'n'],
70
        ];
71
    }
72
}
73