Passed
Push — master ( d25e4d...dba989 )
by Mr
06:54
created

ValuePathParserTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 13
c 1
b 0
f 0
dl 0
loc 39
ccs 8
cts 8
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A provideValuePathTestData() 0 14 1
A testTypePath() 0 6 1
A testInvalidPath() 0 4 1
1
<?php declare(strict_types=1);
2
/**
3
 * This file is part of the daikon-cqrs/entity project.
4
 *
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 */
8
9
namespace Daikon\Tests\Entity\Entity\Path;
10
11
use Daikon\Entity\Path\ValuePath;
12
use Daikon\Entity\Path\ValuePathParser;
13
use InvalidArgumentException;
14
use PHPUnit\Framework\TestCase;
15
16
class ValuePathParserTest extends TestCase
17
{
18
    /**
19
     * @dataProvider provideValuePathTestData
20
     * @param string $pathExpression
21
     * @param int $expectedLength
22
     */
23 3
    public function testTypePath(string $pathExpression, int $expectedLength): void
24
    {
25 3
        $typePath = ValuePathParser::create()->parse($pathExpression);
26
27 3
        $this->assertCount($expectedLength, $typePath);
28 3
        $this->assertEquals($pathExpression, $typePath->__toString());
29 3
    }
30
31 1
    public function testInvalidPath(): void
32
    {
33 1
        $this->expectException(InvalidArgumentException::class);
34 1
        ValuePathParser::create()->parse('2-teasers');
35
    } // @codeCoverageIgnore
36
37
    /**
38
     * @codeCoverageIgnore
39
     * @return mixed[]
40
     */
41
    public function provideValuePathTestData(): array
42
    {
43
        return [
44
            [
45
                'pathExpression' => 'paragraphs',
46
                'expectedLength' => 1
47
            ],
48
            [
49
                'pathExpression' => 'paragraphs.1-title',
50
                'expectedLength' => 2
51
            ],
52
            [
53
                'pathExpression' => 'slideshows.2-teasers.3-images',
54
                'expectedLength' => 3
55
            ]
56
        ];
57
    }
58
}
59