15
15
use BadMethodCallException ;
16
16
use function hexdec ;
17
17
use Laudis \Neo4j \Types \CypherList ;
18
+ use Laudis \Neo4j \Types \CypherMap ;
18
19
use OutOfBoundsException ;
19
20
use PHPUnit \Framework \TestCase ;
20
21
use stdClass ;
21
22
22
- final class CypherListTest extends TestCase
23
+ final class CypherMapTest extends TestCase
23
24
{
24
- private CypherList $ list ;
25
+ private CypherMap $ map ;
25
26
26
27
public function setUp (): void
27
28
{
28
29
parent ::setUp ();
29
30
30
- $ this ->list = new CypherList (['A ' , 'B ' , 'C ' ]);
31
+ $ this ->map = new CypherMap (['A ' => ' x ' , 'B ' => ' y ' , 'C ' => ' z ' ]);
31
32
}
32
33
33
34
public function testFromIterableEqual (): void
34
35
{
35
- $ fromIterable = CypherList ::fromIterable ($ this ->list );
36
+ $ fromIterable = CypherMap ::fromIterable ($ this ->map );
36
37
37
- self ::assertNotSame ($ this ->list , $ fromIterable );
38
- self ::assertEquals ($ this ->list , $ fromIterable );
38
+ self ::assertNotSame ($ this ->map , $ fromIterable );
39
+ self ::assertEquals ($ this ->map , $ fromIterable );
39
40
}
40
41
41
42
public function testFromIterableArray (): void
42
43
{
43
- $ fromIterable = CypherList ::fromIterable (['A ' , 'B ' , 'C ' ]);
44
+ $ fromIterable = CypherMap ::fromIterable (['A ' => ' x ' , 'B ' => ' y ' , 'C ' => ' z ' ]);
44
45
45
- self ::assertNotSame ($ this ->list , $ fromIterable );
46
- self ::assertEquals ($ this ->list , $ fromIterable );
46
+ self ::assertNotSame ($ this ->map , $ fromIterable );
47
+ self ::assertEquals ($ this ->map , $ fromIterable );
47
48
}
48
49
49
50
public function testFromIterable (): void
50
51
{
51
- $ fromIterable = CypherList ::fromIterable (new ArrayIterator (['A ' , 'B ' , 'C ' ]));
52
+ $ fromIterable = CypherMap ::fromIterable (new ArrayIterator (['A ' => ' x ' , 'B ' => ' y ' , 'C ' => ' z ' ]));
52
53
53
- self ::assertNotSame ($ this ->list , $ fromIterable );
54
- self ::assertEquals ($ this ->list , $ fromIterable );
54
+ self ::assertNotSame ($ this ->map , $ fromIterable );
55
+ self ::assertEquals ($ this ->map , $ fromIterable );
55
56
}
56
57
57
58
public function testCount (): void
58
59
{
59
- self ::assertCount (3 , $ this ->list );
60
+ self ::assertCount (3 , $ this ->map );
60
61
}
61
62
62
63
public function testCountEmpty (): void
63
64
{
64
- self ::assertCount (0 , new CypherList ());
65
+ self ::assertCount (0 , new CypherMap ());
65
66
}
66
67
67
68
public function testCopy (): void
68
69
{
69
- $ copy = $ this ->list ->copy ();
70
+ $ copy = $ this ->map ->copy ();
70
71
71
- self ::assertNotSame ($ this ->list , $ copy );
72
- self ::assertEquals ($ this ->list , $ copy );
72
+ self ::assertNotSame ($ this ->map , $ copy );
73
+ self ::assertEquals ($ this ->map , $ copy );
73
74
}
74
75
75
76
public function testCopyDepth (): void
76
77
{
77
- $ list = new CypherList ([ new stdClass ()]);
78
+ $ list = new CypherMap ([ ' A ' => new stdClass ()]);
78
79
$ copy = $ list ->copy ();
79
80
80
81
self ::assertNotSame ($ list , $ copy );
81
82
self ::assertEquals ($ list , $ copy );
82
- self ::assertSame ($ list [0 ], $ copy [0 ]);
83
+ self ::assertSame ($ list [' A ' ], $ copy [' A ' ]);
83
84
}
84
85
85
86
public function testIsEmpty (): void
86
87
{
87
- self ::assertFalse ($ this ->list ->isEmpty ());
88
+ self ::assertFalse ($ this ->map ->isEmpty ());
88
89
}
89
90
90
91
public function testIsEmptyEmpty (): void
91
92
{
92
- self ::assertTrue ((new CypherList ())->isEmpty ());
93
+ self ::assertTrue ((new CypherMap ())->isEmpty ());
93
94
}
94
95
95
96
public function testToArray (): void
96
97
{
97
- self ::assertEquals (['A ' , 'B ' , 'C ' ], $ this ->list ->toArray ());
98
+ self ::assertEquals (['A ' => ' x ' , 'B ' => ' y ' , 'C ' => ' z ' ], $ this ->map ->toArray ());
98
99
}
99
100
100
101
public function testMerge (): void
101
102
{
102
- self ::assertEquals (new CypherList (['A ' , 'B ' , 'C ' , 'A ' , 'B ' , 'C ' ]), $ this ->list ->merge ($ this ->list ));
103
+ self ::assertEquals (new CypherMap (['A ' => 'x ' , 'B ' => 'y ' , 'C ' => 'z ' ]), $ this ->map ->merge ($ this ->map ));
104
+ }
105
+
106
+ public function testMergeDifferent (): void
107
+ {
108
+ $ merged = $ this ->map ->merge (['B ' => 'yy ' , 'C ' => 'z ' , 'D ' => 'e ' ]);
109
+ self ::assertEquals (new CypherMap (['A ' => 'x ' , 'B ' => 'yy ' , 'C ' => 'z ' , 'D ' => 'e ' ]), $ merged );
103
110
}
104
111
105
112
public function testHasKey (): void
106
113
{
107
- self ::assertFalse ($ this ->list ->hasKey (- 1 ));
108
- self ::assertTrue ($ this ->list ->hasKey (0 ));
109
- self ::assertTrue ($ this ->list ->hasKey (1 ));
110
- self ::assertTrue ($ this ->list ->hasKey (2 ));
111
- self ::assertFalse ($ this ->list ->hasKey (3 ));
114
+ self ::assertTrue ($ this ->map ->hasKey (' A ' ));
115
+ self ::assertTrue ($ this ->map ->hasKey (' B ' ));
116
+ self ::assertTrue ($ this ->map ->hasKey (' C ' ));
117
+ self ::assertFalse ($ this ->map ->hasKey (' E ' ));
118
+ self ::assertFalse ($ this ->map ->hasKey (' a ' ));
112
119
}
113
120
114
121
public function testFilterPermissive (): void
115
122
{
116
- $ filter = $ this ->list ->filter (static fn () => true );
123
+ $ filter = $ this ->map ->filter (static fn () => true );
117
124
118
- self ::assertEquals ($ this ->list , $ filter );
119
- self ::assertNotSame ($ this ->list , $ filter );
125
+ self ::assertEquals ($ this ->map , $ filter );
126
+ self ::assertNotSame ($ this ->map , $ filter );
120
127
}
121
128
122
129
public function testFilterBlock (): void
123
130
{
124
- $ filter = $ this ->list ->filter (static fn () => false );
131
+ $ filter = $ this ->map ->filter (static fn () => false );
125
132
126
- self ::assertEquals (new CypherList (), $ filter );
133
+ self ::assertEquals (new CypherMap (), $ filter );
127
134
}
128
135
129
136
public function testFilterSelective (): void
130
137
{
131
- $ filter = $ this ->list ->filter (static fn (int $ i , string $ x ) => $ x === 'B ' || $ i === 2 );
138
+ $ filter = $ this ->map ->filter (static fn (string $ i , string $ x ) => !( $ i === 'B ' || $ x === ' z ' ) );
132
139
133
- self ::assertEquals (new CypherList (['B ' , ' C ' ]), $ filter );
140
+ self ::assertEquals (new CypherMap (['A ' => ' x ' ]), $ filter );
134
141
}
135
142
136
143
public function testMap (): void
137
144
{
138
- $ filter = $ this ->list ->map (static fn (int $ i , string $ x ) => $ i .': ' .$ x );
145
+ $ filter = $ this ->map ->map (static fn (string $ i , string $ x ) => $ i .': ' .$ x );
139
146
140
- self ::assertEquals (new CypherList (['0:A ' , '1:B ' , '2:C ' ]), $ filter );
147
+ self ::assertEquals (new CypherList (['A:x ' , 'B:y ' , 'C:z ' ]), $ filter );
141
148
}
142
149
143
150
public function testReduce (): void
144
151
{
145
- $ count = $ this ->list ->reduce (static function (?int $ initial , int $ key , string $ value ) {
152
+ $ count = $ this ->map ->reduce (static function (?int $ initial , int $ key , string $ value ) {
146
153
return ($ initial ?? 0 ) + $ key * hexdec ($ value );
147
154
}, 5 );
148
155
@@ -151,59 +158,59 @@ public function testReduce(): void
151
158
152
159
public function testFind (): void
153
160
{
154
- self ::assertFalse ($ this ->list ->find ('X ' ));
155
- self ::assertEquals (0 , $ this ->list ->find ('A ' ));
156
- self ::assertEquals (1 , $ this ->list ->find ('B ' ));
157
- self ::assertEquals (2 , $ this ->list ->find ('C ' ));
161
+ self ::assertFalse ($ this ->map ->find ('X ' ));
162
+ self ::assertEquals (0 , $ this ->map ->find ('A ' ));
163
+ self ::assertEquals (1 , $ this ->map ->find ('B ' ));
164
+ self ::assertEquals (2 , $ this ->map ->find ('C ' ));
158
165
}
159
166
160
167
public function testReversed (): void
161
168
{
162
- self ::assertEquals (new CypherList (['C ' , 'B ' , 'A ' ]), $ this ->list ->reversed ());
163
- self ::assertEquals (new CypherList (['A ' , 'B ' , 'C ' ]), $ this ->list );
164
- self ::assertEquals (new CypherList (['A ' , 'B ' , 'C ' ]), $ this ->list ->reversed ()->reversed ());
169
+ self ::assertEquals (new CypherList (['C ' , 'B ' , 'A ' ]), $ this ->map ->reversed ());
170
+ self ::assertEquals (new CypherList (['A ' , 'B ' , 'C ' ]), $ this ->map );
171
+ self ::assertEquals (new CypherList (['A ' , 'B ' , 'C ' ]), $ this ->map ->reversed ()->reversed ());
165
172
}
166
173
167
174
public function testSliceSingle (): void
168
175
{
169
- $ sliced = $ this ->list ->slice (1 , 1 );
176
+ $ sliced = $ this ->map ->slice (1 , 1 );
170
177
self ::assertEquals (new CypherList (['B ' ]), $ sliced );
171
178
}
172
179
173
180
public function testSliceDouble (): void
174
181
{
175
- $ sliced = $ this ->list ->slice (1 , 2 );
182
+ $ sliced = $ this ->map ->slice (1 , 2 );
176
183
self ::assertEquals (new CypherList (['B ' , 'C ' ]), $ sliced );
177
184
}
178
185
179
186
public function testSliceAll (): void
180
187
{
181
- $ sliced = $ this ->list ->slice (0 , 3 );
188
+ $ sliced = $ this ->map ->slice (0 , 3 );
182
189
self ::assertEquals (new CypherList (['A ' , 'B ' , 'C ' ]), $ sliced );
183
190
}
184
191
185
192
public function testSliceTooMuch (): void
186
193
{
187
- $ sliced = $ this ->list ->slice (0 , 5 );
194
+ $ sliced = $ this ->map ->slice (0 , 5 );
188
195
self ::assertEquals (new CypherList (['A ' , 'B ' , 'C ' ]), $ sliced );
189
196
}
190
197
191
198
public function testSliceEmpty (): void
192
199
{
193
- $ sliced = $ this ->list ->slice (0 , 0 );
200
+ $ sliced = $ this ->map ->slice (0 , 0 );
194
201
self ::assertEquals (new CypherList (), $ sliced );
195
202
}
196
203
197
204
public function testGetValid (): void
198
205
{
199
- self ::assertEquals ('A ' , $ this ->list ->get (0 ));
200
- self ::assertEquals ('B ' , $ this ->list ->get (1 ));
201
- self ::assertEquals ('C ' , $ this ->list ->get (2 ));
206
+ self ::assertEquals ('A ' , $ this ->map ->get (0 ));
207
+ self ::assertEquals ('B ' , $ this ->map ->get (1 ));
208
+ self ::assertEquals ('C ' , $ this ->map ->get (2 ));
202
209
}
203
210
204
211
public function testFirst (): void
205
212
{
206
- self ::assertEquals ('A ' , $ this ->list ->first ());
213
+ self ::assertEquals ('A ' , $ this ->map ->first ());
207
214
}
208
215
209
216
public function testFirstInvalid (): void
@@ -215,7 +222,7 @@ public function testFirstInvalid(): void
215
222
216
223
public function testLast (): void
217
224
{
218
- self ::assertEquals ('C ' , $ this ->list ->last ());
225
+ self ::assertEquals ('C ' , $ this ->map ->last ());
219
226
}
220
227
221
228
public function testLastInvalid (): void
@@ -229,20 +236,20 @@ public function testGetInvalid(): void
229
236
{
230
237
$ this ->expectException (OutOfBoundsException::class);
231
238
$ this ->expectExceptionMessage ('Cannot get item in sequence at position: 3 ' );
232
- $ this ->list ->get (3 );
239
+ $ this ->map ->get (3 );
233
240
}
234
241
235
242
public function testGetNegative (): void
236
243
{
237
244
$ this ->expectException (OutOfBoundsException::class);
238
245
$ this ->expectExceptionMessage ('Cannot get item in sequence at position: -1 ' );
239
- $ this ->list ->get (-1 );
246
+ $ this ->map ->get (-1 );
240
247
}
241
248
242
249
public function testIteration (): void
243
250
{
244
251
$ counter = 0 ;
245
- foreach ($ this ->list as $ key => $ item ) {
252
+ foreach ($ this ->map as $ key => $ item ) {
246
253
++$ counter ;
247
254
self ::assertEquals (['A ' , 'B ' , 'C ' ][$ key ], $ item );
248
255
}
@@ -264,49 +271,49 @@ public function testOffsetSet(): void
264
271
$ this ->expectException (BadMethodCallException::class);
265
272
$ this ->expectExceptionMessage ('Laudis\Neo4j\Types\CypherList is immutable ' );
266
273
267
- $ this ->list [0 ] = 'a ' ;
274
+ $ this ->map [0 ] = 'a ' ;
268
275
}
269
276
270
277
public function testOffsetUnset (): void
271
278
{
272
279
$ this ->expectException (BadMethodCallException::class);
273
280
$ this ->expectExceptionMessage ('Laudis\Neo4j\Types\CypherList is immutable ' );
274
281
275
- unset($ this ->list [0 ]);
282
+ unset($ this ->map [0 ]);
276
283
}
277
284
278
285
public function testOffsetGetValid (): void
279
286
{
280
- self ::assertEquals ('A ' , $ this ->list [0 ]);
281
- self ::assertEquals ('B ' , $ this ->list [1 ]);
282
- self ::assertEquals ('C ' , $ this ->list [2 ]);
287
+ self ::assertEquals ('A ' , $ this ->map [0 ]);
288
+ self ::assertEquals ('B ' , $ this ->map [1 ]);
289
+ self ::assertEquals ('C ' , $ this ->map [2 ]);
283
290
}
284
291
285
292
public function testOffsetGetInvalid (): void
286
293
{
287
294
$ this ->expectException (OutOfBoundsException::class);
288
295
$ this ->expectExceptionMessage ('Offset: "3" does not exists in object of instance: Laudis\Neo4j\Types\CypherList ' );
289
- $ this ->list [3 ];
296
+ $ this ->map [3 ];
290
297
}
291
298
292
299
public function testOffsetGetNegative (): void
293
300
{
294
301
$ this ->expectException (OutOfBoundsException::class);
295
302
$ this ->expectExceptionMessage ('Offset: "-1" does not exists in object of instance: Laudis\Neo4j\Types\CypherList ' );
296
- $ this ->list [-1 ];
303
+ $ this ->map [-1 ];
297
304
}
298
305
299
306
public function testIssetValid (): void
300
307
{
301
- self ::assertTrue (isset ($ this ->list [0 ]));
302
- self ::assertTrue (isset ($ this ->list [1 ]));
303
- self ::assertTrue (isset ($ this ->list [2 ]));
308
+ self ::assertTrue (isset ($ this ->map [0 ]));
309
+ self ::assertTrue (isset ($ this ->map [1 ]));
310
+ self ::assertTrue (isset ($ this ->map [2 ]));
304
311
}
305
312
306
313
public function testIssetInValid (): void
307
314
{
308
- self ::assertFalse (isset ($ this ->list [-1 ]));
309
- self ::assertFalse (isset ($ this ->list [3 ]));
315
+ self ::assertFalse (isset ($ this ->map [-1 ]));
316
+ self ::assertFalse (isset ($ this ->map [3 ]));
310
317
}
311
318
312
319
public function testIssetValidNull (): void
0 commit comments