7
7
8
8
abstract class AbstractFunctionalTest extends TestCase
9
9
{
10
- protected abstract function createStore (array $ data = array ());
10
+ protected $ defaults ;
11
+
12
+ protected abstract function createStore (array $ data = null );
13
+
14
+ protected function getStore (array $ data = null )
15
+ {
16
+ $ store = $ this ->createStore ($ data );
17
+ if ($ this ->defaults ) {
18
+ $ store ->setDefaults ($ this ->defaults );
19
+ }
20
+ return $ store ;
21
+ }
11
22
12
23
public function tearDown (): void
13
24
{
14
25
m::close ();
26
+ $ this ->defaults = [];
15
27
}
16
28
17
29
protected function assertStoreEquals ($ store , $ expected , $ message = '' )
18
30
{
19
31
$ this ->assertEquals ($ expected , $ store ->all (), $ message );
20
32
$ store ->save ();
21
- $ store = $ this ->createStore ();
33
+ $ store = $ this ->getStore ();
22
34
$ this ->assertEquals ($ expected , $ store ->all (), $ message );
23
35
}
24
36
25
37
protected function assertStoreKeyEquals ($ store , $ key , $ expected , $ message = '' )
26
38
{
27
39
$ this ->assertEquals ($ expected , $ store ->get ($ key ), $ message );
28
40
$ store ->save ();
29
- $ store = $ this ->createStore ();
41
+ $ store = $ this ->getStore ();
30
42
$ this ->assertEquals ($ expected , $ store ->get ($ key ), $ message );
31
43
}
32
44
33
45
/** @test */
34
46
public function store_is_initially_empty ()
35
47
{
36
- $ store = $ this ->createStore ();
48
+ $ store = $ this ->getStore ();
37
49
$ this ->assertEquals (array (), $ store ->all ());
38
50
}
39
51
40
52
/** @test */
41
53
public function written_changes_are_saved ()
42
54
{
43
- $ store = $ this ->createStore ();
55
+ $ store = $ this ->getStore ();
44
56
$ store ->set ('foo ' , 'bar ' );
45
57
$ this ->assertStoreKeyEquals ($ store , 'foo ' , 'bar ' );
46
58
}
47
59
48
60
/** @test */
49
61
public function nested_keys_are_nested ()
50
62
{
51
- $ store = $ this ->createStore ();
63
+ $ store = $ this ->getStore ();
52
64
$ store ->set ('foo.bar ' , 'baz ' );
53
65
$ this ->assertStoreEquals ($ store , array ('foo ' => array ('bar ' => 'baz ' )));
54
66
}
55
67
56
68
/** @test */
57
69
public function cannot_set_nested_key_on_non_array_member ()
58
70
{
59
- $ store = $ this ->createStore ();
71
+ $ store = $ this ->getStore ();
60
72
$ store ->set ('foo ' , 'bar ' );
61
73
$ this ->expectException ('UnexpectedValueException ' );
62
74
$ this ->expectExceptionMessage ('Non-array segment encountered ' );
@@ -66,7 +78,7 @@ public function cannot_set_nested_key_on_non_array_member()
66
78
/** @test */
67
79
public function can_forget_key ()
68
80
{
69
- $ store = $ this ->createStore ();
81
+ $ store = $ this ->getStore ();
70
82
$ store ->set ('foo ' , 'bar ' );
71
83
$ store ->set ('bar ' , 'baz ' );
72
84
$ this ->assertStoreEquals ($ store , array ('foo ' => 'bar ' , 'bar ' => 'baz ' ));
@@ -78,7 +90,7 @@ public function can_forget_key()
78
90
/** @test */
79
91
public function can_forget_nested_key ()
80
92
{
81
- $ store = $ this ->createStore ();
93
+ $ store = $ this ->getStore ();
82
94
$ store ->set ('foo.bar ' , 'baz ' );
83
95
$ store ->set ('foo.baz ' , 'bar ' );
84
96
$ store ->set ('bar.foo ' , 'baz ' );
@@ -119,9 +131,18 @@ public function can_forget_nested_key()
119
131
/** @test */
120
132
public function can_forget_all ()
121
133
{
122
- $ store = $ this ->createStore (array ('foo ' => 'bar ' ));
134
+ $ store = $ this ->getStore (array ('foo ' => 'bar ' ));
123
135
$ this ->assertStoreEquals ($ store , array ('foo ' => 'bar ' ));
124
136
$ store ->forgetAll ();
125
137
$ this ->assertStoreEquals ($ store , array ());
126
138
}
139
+
140
+ /** @test */
141
+ public function defaults_are_respected ()
142
+ {
143
+ $ this ->defaults = ['foo ' => 'default ' , 'bar ' => 'default ' ];
144
+ $ store = $ this ->getStore (array ('foo ' => 'bar ' ));
145
+ $ this ->assertStoreEquals ($ store , ['foo ' => 'bar ' ]);
146
+ $ this ->assertStoreKeyEquals ($ store , ['foo ' , 'bar ' ], ['foo ' => 'bar ' , 'bar ' => 'default ' ]);
147
+ }
127
148
}
0 commit comments