Passed
Push — master ( ebf663...def3a6 )
by Alexander
02:38
created

ErrorTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A testGetValuePath() 0 5 1
A dataGetValuePath() 0 31 1
A testTooLongEscapeSymbol() 0 7 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Validator\Tests;
6
7
use InvalidArgumentException;
8
use PHPUnit\Framework\TestCase;
9
use Yiisoft\Validator\Error;
10
11
final class ErrorTest extends TestCase
12
{
13
    public function dataGetValuePath(): array
14
    {
15
        return [
16
            'null' => [
17
                ['user', 'data.age'],
18
                ['user', 'data.age'],
19
                null,
20
            ],
21
            'symbol' => [
22
                ['user', 'the.data\-age'],
23
                ['user', 'the.data-age'],
24
                '-',
25
            ],
26
            'emoji' => [
27
                ['user', 'the.data\😎age'],
28
                ['user', 'the.data😎age'],
29
                '😎',
30
            ],
31
32
            // deprecated
33
            'true' => [
34
                ['user', 'data\.age'],
35
                ['user', 'data.age'],
36
                true,
37
            ],
38
39
            // deprecated
40
            'false' => [
41
                ['user', 'data.age'],
42
                ['user', 'data.age'],
43
                false,
44
            ],
45
        ];
46
    }
47
48
    /**
49
     * @dataProvider dataGetValuePath
50
     */
51
    public function testGetValuePath(array $expectedValuePath, array $valuePath, bool|string|null $escape): void
52
    {
53
        $error = new Error('', valuePath: $valuePath);
54
55
        $this->assertSame($expectedValuePath, $error->getValuePath($escape));
56
    }
57
58
    public function testTooLongEscapeSymbol(): void
59
    {
60
        $error = new Error('');
61
62
        $this->expectException(InvalidArgumentException::class);
63
        $this->expectExceptionMessage('Escape symbol must be exactly one character.');
64
        $error->getValuePath('..');
65
    }
66
}
67