Passed
Pull Request — master (#612)
by Sergei
11:39
created

ErrorTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A testGetValuePath() 0 5 1
A dataGetValuePath() 0 26 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
27
            // deprecated
28
            'true' => [
29
                ['user', 'data\.age'],
30
                ['user', 'data.age'],
31
                true,
32
            ],
33
34
            // deprecated
35
            'false' => [
36
                ['user', 'data.age'],
37
                ['user', 'data.age'],
38
                false,
39
            ],
40
        ];
41
    }
42
43
    /**
44
     * @dataProvider dataGetValuePath
45
     */
46
    public function testGetValuePath(array $expectedValuePath, array $valuePath, bool|string|null $escape): void
47
    {
48
        $error = new Error('', valuePath: $valuePath);
49
50
        $this->assertSame($expectedValuePath, $error->getValuePath($escape));
51
    }
52
53
    public function testTooLongEscapeSymbol(): void
54
    {
55
        $error = new Error('');
56
57
        $this->expectException(InvalidArgumentException::class);
58
        $this->expectExceptionMessage('Escape symbol must contain exactly one character.');
59
        $error->getValuePath('..');
60
    }
61
}
62