|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace FigTree\Config\Tests; |
|
4
|
|
|
|
|
5
|
|
|
use DateInterval; |
|
6
|
|
|
use DateTime; |
|
7
|
|
|
use FigTree\Config\{ |
|
8
|
|
|
Contracts\ConfigFactoryInterface, |
|
9
|
|
|
Contracts\ConfigInterface, |
|
10
|
|
|
AbstractConfig, |
|
11
|
|
|
ConfigRepository, |
|
12
|
|
|
}; |
|
13
|
|
|
use FigTree\Config\Tests\Dummies\{ |
|
14
|
|
|
ExtendedConfigFactory, |
|
15
|
|
|
ExtendedConfig, |
|
16
|
|
|
}; |
|
17
|
|
|
|
|
18
|
|
|
class ExtendedConfigTest extends AbstractTestCase |
|
19
|
|
|
{ |
|
20
|
|
|
/** |
|
21
|
|
|
* @small |
|
22
|
|
|
*/ |
|
23
|
|
|
public function testConfigFactory() |
|
24
|
|
|
{ |
|
25
|
|
|
$timestamp = new DateTime(); |
|
26
|
|
|
|
|
27
|
|
|
$factory = new ExtendedConfigFactory($timestamp); |
|
28
|
|
|
|
|
29
|
|
|
$this->assertInstanceOf(ConfigFactoryInterface::class, $factory); |
|
30
|
|
|
$this->assertInstanceOf(ExtendedConfigFactory::class, $factory); |
|
31
|
|
|
|
|
32
|
|
|
$repo = new ConfigRepository($factory); |
|
33
|
|
|
|
|
34
|
|
|
$repo->addDirectory(__DIR__ . '/Data/Config/Extended'); |
|
35
|
|
|
|
|
36
|
|
|
$directories = $repo->getDirectories(); |
|
37
|
|
|
|
|
38
|
|
|
$this->assertIsArray($directories); |
|
39
|
|
|
$this->assertCount(1, $directories); |
|
40
|
|
|
|
|
41
|
|
|
$this->assertEquals($this->path(__DIR__, 'Data', 'Config', 'Extended'), $directories[0]); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
public function testConfig() |
|
45
|
|
|
{ |
|
46
|
|
|
$today = new DateTime(); |
|
47
|
|
|
$yesterday = (clone $today)->sub(new DateInterval('P1D')); |
|
48
|
|
|
$tomorrow = (clone $today)->add(new DateInterval('P1D')); |
|
49
|
|
|
|
|
50
|
|
|
$factory = new ExtendedConfigFactory($today); |
|
51
|
|
|
|
|
52
|
|
|
$repo = new ConfigRepository($factory); |
|
53
|
|
|
|
|
54
|
|
|
$repo->addDirectory(__DIR__ . '/Data/Config/Extended'); |
|
55
|
|
|
|
|
56
|
|
|
$config = $repo->get('file'); |
|
57
|
|
|
|
|
58
|
|
|
$this->assertInstanceOf(ConfigInterface::class, $config); |
|
59
|
|
|
$this->assertInstanceOf(AbstractConfig::class, $config); |
|
60
|
|
|
$this->assertInstanceOf(ExtendedConfig::class, $config); |
|
61
|
|
|
|
|
62
|
|
|
$this->assertArrayHasKey('today', $config); |
|
63
|
|
|
$this->assertArrayHasKey('yesterday', $config); |
|
64
|
|
|
$this->assertArrayHasKey('tomorrow', $config); |
|
65
|
|
|
|
|
66
|
|
|
$this->assertIsString($config['today']); |
|
67
|
|
|
$this->assertEquals($today->format('Y-m-d'), $config['today']); |
|
68
|
|
|
|
|
69
|
|
|
$this->assertIsString($config['yesterday']); |
|
70
|
|
|
$this->assertEquals($yesterday->format('Y-m-d'), $config['yesterday']); |
|
71
|
|
|
|
|
72
|
|
|
$this->assertIsString($config['tomorrow']); |
|
73
|
|
|
$this->assertEquals($tomorrow->format('Y-m-d'), $config['tomorrow']); |
|
74
|
|
|
} |
|
75
|
|
|
} |
|
76
|
|
|
|