|
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
|
|
|
|