1+ <?php
2+
3+ /*
4+ * This file is a part of dflydev/dot-access-configuration.
5+ *
6+ * (c) Dragonfly Development Inc.
7+ *
8+ * For the full copyright and license information, please view the LICENSE
9+ * file that was distributed with this source code.
10+ */
11+
12+ namespace Dflydev \Tests \DotAccessConfiguration ;
13+
14+ use Dflydev \DotAccessConfiguration \Configuration ;
15+ use Dflydev \DotAccessConfiguration \ConfigurationInterface ;
16+
17+ class ConfigurationTest extends \PHPUnit_Framework_TestCase
18+ {
19+ protected function getSampleData ()
20+ {
21+ return array (
22+ 'a ' => 'A ' ,
23+ 'b ' => array (
24+ 'b ' => 'B ' ,
25+ 'c ' => array ('C1 ' , 'C2 ' , 'C3 ' ),
26+ 'd ' => array (
27+ 'd1 ' => 'D1 ' ,
28+ 'd2 ' => 'D2 ' ,
29+ 'd3 ' => 'D3 ' ,
30+ ),
31+ ),
32+ 'c ' => array ('c1 ' , 'c2 ' , 'c3 ' ),
33+ );
34+ }
35+
36+ protected function runSampleDataTests (ConfigurationInterface $ configuration )
37+ {
38+ $ this ->assertEquals ('A ' , $ configuration ->get ('a ' ));
39+ $ this ->assertEquals ('B ' , $ configuration ->get ('b.b ' ));
40+ $ this ->assertEquals (array ('C1 ' , 'C2 ' , 'C3 ' ), $ configuration ->get ('b.c ' ));
41+ $ this ->assertEquals ('D3 ' , $ configuration ->get ('b.d.d3 ' ));
42+ $ this ->assertEquals (array ('c1 ' , 'c2 ' , 'c3 ' ), $ configuration ->get ('c ' ));
43+ $ this ->assertEquals (null , $ configuration ->get ('foo ' ), 'Foo should not exist ' );
44+ }
45+
46+ public function testAppend ()
47+ {
48+ $ this ->markTestSkipped ();
49+ }
50+
51+ public function testSet ()
52+ {
53+ $ this ->markTestSkipped ();
54+ }
55+
56+ public function testRemote ()
57+ {
58+ $ this ->markTestSkipped ();
59+ }
60+
61+ public function testGet ()
62+ {
63+ $ configuration = new Configuration ($ this ->getSampleData ());
64+
65+ $ this ->runSampleDataTests ($ configuration );
66+ }
67+
68+ public function testGetConfiguration ()
69+ {
70+ $ wrappedConfiguration = new Configuration (array (
71+ 'wrapped ' => array (
72+ 'sampleData ' => $ this ->getSampleData ()
73+ ),
74+ ));
75+
76+ $ configuration = $ wrappedConfiguration ->getConfiguration ('wrapped.sampleData ' );
77+
78+ $ this ->runSampleDataTests ($ configuration );
79+
80+ $ this ->setExpectedException ('RuntimeException ' );
81+
82+ $ configuration = $ wrappedConfiguration ->getConfiguration ('wrapped.sampleData.a ' );
83+ }
84+
85+ public function testImport ()
86+ {
87+ $ configuration = new Configuration ();
88+ $ configuration ->import ($ this ->getSampleData ());
89+
90+ $ this ->runSampleDataTests ($ configuration );
91+ }
92+
93+ public function testImportConfiguration ()
94+ {
95+ $ configuration = new Configuration ();
96+ $ configuration ->importConfiguration (new Configuration ($ this ->getSampleData ()));
97+
98+ $ this ->runSampleDataTests ($ configuration );
99+ }
100+
101+ public function testExport ()
102+ {
103+ $ configuration = new Configuration ($ this ->getSampleData ());
104+
105+ $ this ->assertEquals ($ this ->getSampleData (), $ configuration ->export ());
106+ }
107+ }
0 commit comments