|
1
|
|
|
<?php declare(strict_types=1); |
|
2
|
|
|
/** |
|
3
|
|
|
* This file is part of the daikon-cqrs/config 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\Test\Config; |
|
10
|
|
|
|
|
11
|
|
|
use Daikon\Config\ConfigPath; |
|
12
|
|
|
use Daikon\Interop\AssertionFailedException; |
|
13
|
|
|
use PHPUnit\Framework\TestCase; |
|
14
|
|
|
|
|
15
|
|
|
final class ConfigPathTest extends TestCase |
|
16
|
|
|
{ |
|
17
|
1 |
|
public function testGetScope(): void |
|
18
|
|
|
{ |
|
19
|
1 |
|
$configPath = ConfigPath::fromString('settings.core.app_version'); |
|
20
|
1 |
|
$this->assertEquals('settings', $configPath->getScope()); |
|
21
|
1 |
|
$configPath = ConfigPath::fromString('settings'); |
|
22
|
1 |
|
$this->assertEquals('settings', $configPath->getScope()); |
|
23
|
1 |
|
} |
|
24
|
|
|
|
|
25
|
1 |
|
public function testGetParts(): void |
|
26
|
|
|
{ |
|
27
|
1 |
|
$configPath = ConfigPath::fromString('settings.core.app_version'); |
|
28
|
1 |
|
$this->assertEquals(['core', 'app_version'], $configPath->getParts()); |
|
29
|
1 |
|
$configPath = ConfigPath::fromString('settings'); |
|
30
|
1 |
|
$this->assertEquals([], $configPath->getParts()); |
|
31
|
1 |
|
} |
|
32
|
|
|
|
|
33
|
1 |
|
public function testGetLength(): void |
|
34
|
|
|
{ |
|
35
|
1 |
|
$configPath = ConfigPath::fromString('settings.core.app_version'); |
|
36
|
1 |
|
$this->assertEquals(2, $configPath->getLength()); |
|
37
|
1 |
|
} |
|
38
|
|
|
|
|
39
|
1 |
|
public function testHasParts(): void |
|
40
|
|
|
{ |
|
41
|
1 |
|
$configPath = ConfigPath::fromString('settings.core.app_version'); |
|
42
|
1 |
|
$this->assertTrue($configPath->hasParts()); |
|
43
|
1 |
|
$configPath = ConfigPath::fromString('settings'); |
|
44
|
1 |
|
$this->assertFalse($configPath->hasParts()); |
|
45
|
1 |
|
} |
|
46
|
|
|
|
|
47
|
1 |
|
public function testToString(): void |
|
48
|
|
|
{ |
|
49
|
1 |
|
$configPath = ConfigPath::fromString('settings.core.app_version'); |
|
50
|
1 |
|
$this->assertEquals('settings.core.app_version', (string)$configPath); |
|
51
|
1 |
|
} |
|
52
|
|
|
|
|
53
|
1 |
|
public function testWithEmptyPath(): void |
|
54
|
|
|
{ |
|
55
|
1 |
|
$this->expectException(AssertionFailedException::class); |
|
56
|
1 |
|
ConfigPath::fromString(''); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
1 |
|
public function testInvalidPathWithLeadingSeparator(): void |
|
60
|
|
|
{ |
|
61
|
1 |
|
$this->expectException(AssertionFailedException::class); |
|
62
|
1 |
|
ConfigPath::fromString('.settings.core.app_version'); |
|
63
|
|
|
} |
|
64
|
|
|
} |
|
65
|
|
|
|