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

ErrorTest::testGetValuePath()   A

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
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 3
dl 0
loc 5
rs 10
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