Skip to content
This repository was archived by the owner on Oct 26, 2024. It is now read-only.

Commit 1fc4859

Browse files
author
Marc Aschmann
committed
Increased coverage and finished implementing imports/default node handling
1 parent c472c16 commit 1fc4859

File tree

6 files changed

+62
-11
lines changed

6 files changed

+62
-11
lines changed

Config/AbstractConfig.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,10 @@ public function readConfig($file)
7777
$config = $this->extractDefault($config);
7878
$this->mergeDefault();
7979

80-
return $config;
80+
return array_replace_recursive(
81+
$this->default,
82+
$config
83+
);
8184
}
8285

8386
/**
@@ -128,10 +131,10 @@ private function extractImports(array $config)
128131
$this->imports,
129132
$this->readFile($import['resource'])
130133
);
131-
132-
unset($config['resource'][$key]);
133134
}
134135
}
136+
137+
unset($config['imports']);
135138
}
136139

137140
return $config;

Tests/Config/ConfigDefaultTest.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,14 @@
2222
class ConfigDefaultTest extends BaseConfigTest
2323
{
2424
/**
25-
* @covers \Asm\Config\ConfigAbstract::readConfig
26-
* @covers \Asm\Config\ConfigAbstract::setConfig
25+
* @covers \Asm\Config\AbstractConfig::readConfig
26+
* @covers \Asm\Config\AbstractConfig::setConfig
2727
*/
2828
public function testFactory()
2929
{
3030
$config = Config::factory(
3131
[
3232
'file' => $this->getTestYaml(),
33-
'filecheck' => false,
3433
],
3534
'ConfigDefault'
3635
);
@@ -44,7 +43,7 @@ public function testFactory()
4443
* @depends testFactory
4544
* @param ConfigDefault $config
4645
*/
47-
/*public function testImport($config)
46+
public function testImport(ConfigDefault $config)
4847
{
4948
$this->assertEquals(
5049
[
@@ -53,5 +52,5 @@ public function testFactory()
5352
],
5453
$config->get('testkey_5')
5554
);
56-
}*/
55+
}
5756
}

Tests/Config/ConfigEnvTest.php

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,26 @@ class ConfigEnvTest extends BaseConfigTest
2828
* @return \Asm\Config\ConfigInterface
2929
*/
3030
public function testFactoryProd()
31+
{
32+
// merged environments config
33+
$config = Config::factory(
34+
[
35+
'file' => $this->getTestYaml(),
36+
],
37+
'ConfigEnv'
38+
);
39+
40+
$this->assertInstanceOf('Asm\Config\ConfigEnv', $config);
41+
42+
return $config;
43+
}
44+
45+
/**
46+
* @covers \Asm\Config\ConfigEnv::mergeEnvironments
47+
* @covers \Asm\Config\ConfigEnv::__construct
48+
* @return \Asm\Config\ConfigInterface
49+
*/
50+
public function testFactoryProdWithoutFilecheck()
3151
{
3252
// merged environments config
3353
$config = Config::factory(
@@ -52,8 +72,7 @@ public function testFactoryEnv()
5272
{
5373
$config = Config::factory(
5474
[
55-
'file' => TestData::getYamlConfigFile(),
56-
'filecheck' => false,
75+
'file' => $this->getTestYaml(),
5776
'defaultEnv' => 'prod',
5877
'env' => 'dev',
5978
],
@@ -73,4 +92,32 @@ public function testConfigMerge(ConfigEnv $config)
7392
{
7493
$this->assertEquals(25, $config->get('testkey_2', 0));
7594
}
95+
96+
97+
/**
98+
* @depends testFactoryEnv
99+
* @param ConfigEnv $config
100+
*/
101+
public function testConfigInclude(ConfigEnv $config)
102+
{
103+
$this->assertEquals(
104+
[
105+
'default' => 'yaddayadda',
106+
'my_test' => 'is testing hard'
107+
],
108+
$config->get('testkey_5')
109+
);
110+
}
111+
112+
/**
113+
* @depends testFactoryEnv
114+
* @param ConfigEnv $config
115+
*/
116+
public function testConfigDefaultNode(ConfigEnv $config)
117+
{
118+
$this->assertEquals(
119+
'default test',
120+
$config->get('testkey_4')
121+
);
122+
}
76123
}

Tests/Config/ConfigTimerTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ class ConfigTimerTest extends BaseConfigTest
2525
* @covers \Asm\Config\ConfigTimer::handleTimers
2626
* @covers \Asm\Config\ConfigTimer::handleHolidays
2727
* @covers \Asm\Config\ConfigTimer::handleGeneralHolidays
28+
* @covers \Asm\Test\BaseConfigTest::getTimerYaml
2829
* @return ConfigTimer $config
2930
* @throws \ErrorException
3031
*/
@@ -33,7 +34,6 @@ public function testFactory()
3334
$config = Config::factory(
3435
[
3536
'file' => $this->getTimerYaml(),
36-
'filecheck' => false,
3737
],
3838
'ConfigTimer'
3939
);

Tests/Timer/TimerTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ public function testIsTimerActive(Timer $timer)
7575
* @covers \Asm\Timer\Timer::isHoliday
7676
* @covers \Asm\Timer\Timer::getHoliday
7777
* @covers \Asm\Timer\Timer::checkHoliday
78+
* @covers \Asm\Timer\Timer::convertDate
7879
* @param Timer $timer
7980
*/
8081
public function testIsHoliday(Timer $timer)

phpunit.xml.dist

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
<exclude>
2424
<directory>./Tests</directory>
2525
<directory>./vendor</directory>
26+
<file>./example.php</file>
2627
</exclude>
2728
</whitelist>
2829
</filter>

0 commit comments

Comments
 (0)