Skip to content

Commit 66f6790

Browse files
committed
added tests for join
1 parent b6be793 commit 66f6790

File tree

2 files changed

+87
-70
lines changed

2 files changed

+87
-70
lines changed

tests/Unit/CypherListTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,4 +324,14 @@ public function testJsonSerializeEmpty(): void
324324
{
325325
self::assertEquals('[]', json_encode(new CypherList(), JSON_THROW_ON_ERROR));
326326
}
327+
328+
public function testJoin(): void
329+
{
330+
self::assertEquals('A;B;C', $this->list->join(';'));
331+
}
332+
333+
public function testJoinEmpty(): void
334+
{
335+
self::assertEquals('', (new CypherList())->join('A'));
336+
}
327337
}

tests/Unit/CypherMapTest.php

Lines changed: 77 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -15,134 +15,141 @@
1515
use BadMethodCallException;
1616
use function hexdec;
1717
use Laudis\Neo4j\Types\CypherList;
18+
use Laudis\Neo4j\Types\CypherMap;
1819
use OutOfBoundsException;
1920
use PHPUnit\Framework\TestCase;
2021
use stdClass;
2122

22-
final class CypherListTest extends TestCase
23+
final class CypherMapTest extends TestCase
2324
{
24-
private CypherList $list;
25+
private CypherMap $map;
2526

2627
public function setUp(): void
2728
{
2829
parent::setUp();
2930

30-
$this->list = new CypherList(['A', 'B', 'C']);
31+
$this->map = new CypherMap(['A' => 'x', 'B' => 'y', 'C' => 'z']);
3132
}
3233

3334
public function testFromIterableEqual(): void
3435
{
35-
$fromIterable = CypherList::fromIterable($this->list);
36+
$fromIterable = CypherMap::fromIterable($this->map);
3637

37-
self::assertNotSame($this->list, $fromIterable);
38-
self::assertEquals($this->list, $fromIterable);
38+
self::assertNotSame($this->map, $fromIterable);
39+
self::assertEquals($this->map, $fromIterable);
3940
}
4041

4142
public function testFromIterableArray(): void
4243
{
43-
$fromIterable = CypherList::fromIterable(['A', 'B', 'C']);
44+
$fromIterable = CypherMap::fromIterable(['A' => 'x', 'B' => 'y', 'C' => 'z']);
4445

45-
self::assertNotSame($this->list, $fromIterable);
46-
self::assertEquals($this->list, $fromIterable);
46+
self::assertNotSame($this->map, $fromIterable);
47+
self::assertEquals($this->map, $fromIterable);
4748
}
4849

4950
public function testFromIterable(): void
5051
{
51-
$fromIterable = CypherList::fromIterable(new ArrayIterator(['A', 'B', 'C']));
52+
$fromIterable = CypherMap::fromIterable(new ArrayIterator(['A' => 'x', 'B' => 'y', 'C' => 'z']));
5253

53-
self::assertNotSame($this->list, $fromIterable);
54-
self::assertEquals($this->list, $fromIterable);
54+
self::assertNotSame($this->map, $fromIterable);
55+
self::assertEquals($this->map, $fromIterable);
5556
}
5657

5758
public function testCount(): void
5859
{
59-
self::assertCount(3, $this->list);
60+
self::assertCount(3, $this->map);
6061
}
6162

6263
public function testCountEmpty(): void
6364
{
64-
self::assertCount(0, new CypherList());
65+
self::assertCount(0, new CypherMap());
6566
}
6667

6768
public function testCopy(): void
6869
{
69-
$copy = $this->list->copy();
70+
$copy = $this->map->copy();
7071

71-
self::assertNotSame($this->list, $copy);
72-
self::assertEquals($this->list, $copy);
72+
self::assertNotSame($this->map, $copy);
73+
self::assertEquals($this->map, $copy);
7374
}
7475

7576
public function testCopyDepth(): void
7677
{
77-
$list = new CypherList([new stdClass()]);
78+
$list = new CypherMap(['A' => new stdClass()]);
7879
$copy = $list->copy();
7980

8081
self::assertNotSame($list, $copy);
8182
self::assertEquals($list, $copy);
82-
self::assertSame($list[0], $copy[0]);
83+
self::assertSame($list['A'], $copy['A']);
8384
}
8485

8586
public function testIsEmpty(): void
8687
{
87-
self::assertFalse($this->list->isEmpty());
88+
self::assertFalse($this->map->isEmpty());
8889
}
8990

9091
public function testIsEmptyEmpty(): void
9192
{
92-
self::assertTrue((new CypherList())->isEmpty());
93+
self::assertTrue((new CypherMap())->isEmpty());
9394
}
9495

9596
public function testToArray(): void
9697
{
97-
self::assertEquals(['A', 'B', 'C'], $this->list->toArray());
98+
self::assertEquals(['A' => 'x', 'B' => 'y', 'C' => 'z'], $this->map->toArray());
9899
}
99100

100101
public function testMerge(): void
101102
{
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);
103110
}
104111

105112
public function testHasKey(): void
106113
{
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'));
112119
}
113120

114121
public function testFilterPermissive(): void
115122
{
116-
$filter = $this->list->filter(static fn () => true);
123+
$filter = $this->map->filter(static fn () => true);
117124

118-
self::assertEquals($this->list, $filter);
119-
self::assertNotSame($this->list, $filter);
125+
self::assertEquals($this->map, $filter);
126+
self::assertNotSame($this->map, $filter);
120127
}
121128

122129
public function testFilterBlock(): void
123130
{
124-
$filter = $this->list->filter(static fn () => false);
131+
$filter = $this->map->filter(static fn () => false);
125132

126-
self::assertEquals(new CypherList(), $filter);
133+
self::assertEquals(new CypherMap(), $filter);
127134
}
128135

129136
public function testFilterSelective(): void
130137
{
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'));
132139

133-
self::assertEquals(new CypherList(['B', 'C']), $filter);
140+
self::assertEquals(new CypherMap(['A' => 'x']), $filter);
134141
}
135142

136143
public function testMap(): void
137144
{
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);
139146

140-
self::assertEquals(new CypherList(['0:A', '1:B', '2:C']), $filter);
147+
self::assertEquals(new CypherList(['A:x', 'B:y', 'C:z']), $filter);
141148
}
142149

143150
public function testReduce(): void
144151
{
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) {
146153
return ($initial ?? 0) + $key * hexdec($value);
147154
}, 5);
148155

@@ -151,59 +158,59 @@ public function testReduce(): void
151158

152159
public function testFind(): void
153160
{
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'));
158165
}
159166

160167
public function testReversed(): void
161168
{
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());
165172
}
166173

167174
public function testSliceSingle(): void
168175
{
169-
$sliced = $this->list->slice(1, 1);
176+
$sliced = $this->map->slice(1, 1);
170177
self::assertEquals(new CypherList(['B']), $sliced);
171178
}
172179

173180
public function testSliceDouble(): void
174181
{
175-
$sliced = $this->list->slice(1, 2);
182+
$sliced = $this->map->slice(1, 2);
176183
self::assertEquals(new CypherList(['B', 'C']), $sliced);
177184
}
178185

179186
public function testSliceAll(): void
180187
{
181-
$sliced = $this->list->slice(0, 3);
188+
$sliced = $this->map->slice(0, 3);
182189
self::assertEquals(new CypherList(['A', 'B', 'C']), $sliced);
183190
}
184191

185192
public function testSliceTooMuch(): void
186193
{
187-
$sliced = $this->list->slice(0, 5);
194+
$sliced = $this->map->slice(0, 5);
188195
self::assertEquals(new CypherList(['A', 'B', 'C']), $sliced);
189196
}
190197

191198
public function testSliceEmpty(): void
192199
{
193-
$sliced = $this->list->slice(0, 0);
200+
$sliced = $this->map->slice(0, 0);
194201
self::assertEquals(new CypherList(), $sliced);
195202
}
196203

197204
public function testGetValid(): void
198205
{
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));
202209
}
203210

204211
public function testFirst(): void
205212
{
206-
self::assertEquals('A', $this->list->first());
213+
self::assertEquals('A', $this->map->first());
207214
}
208215

209216
public function testFirstInvalid(): void
@@ -215,7 +222,7 @@ public function testFirstInvalid(): void
215222

216223
public function testLast(): void
217224
{
218-
self::assertEquals('C', $this->list->last());
225+
self::assertEquals('C', $this->map->last());
219226
}
220227

221228
public function testLastInvalid(): void
@@ -229,20 +236,20 @@ public function testGetInvalid(): void
229236
{
230237
$this->expectException(OutOfBoundsException::class);
231238
$this->expectExceptionMessage('Cannot get item in sequence at position: 3');
232-
$this->list->get(3);
239+
$this->map->get(3);
233240
}
234241

235242
public function testGetNegative(): void
236243
{
237244
$this->expectException(OutOfBoundsException::class);
238245
$this->expectExceptionMessage('Cannot get item in sequence at position: -1');
239-
$this->list->get(-1);
246+
$this->map->get(-1);
240247
}
241248

242249
public function testIteration(): void
243250
{
244251
$counter = 0;
245-
foreach ($this->list as $key => $item) {
252+
foreach ($this->map as $key => $item) {
246253
++$counter;
247254
self::assertEquals(['A', 'B', 'C'][$key], $item);
248255
}
@@ -264,49 +271,49 @@ public function testOffsetSet(): void
264271
$this->expectException(BadMethodCallException::class);
265272
$this->expectExceptionMessage('Laudis\Neo4j\Types\CypherList is immutable');
266273

267-
$this->list[0] = 'a';
274+
$this->map[0] = 'a';
268275
}
269276

270277
public function testOffsetUnset(): void
271278
{
272279
$this->expectException(BadMethodCallException::class);
273280
$this->expectExceptionMessage('Laudis\Neo4j\Types\CypherList is immutable');
274281

275-
unset($this->list[0]);
282+
unset($this->map[0]);
276283
}
277284

278285
public function testOffsetGetValid(): void
279286
{
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]);
283290
}
284291

285292
public function testOffsetGetInvalid(): void
286293
{
287294
$this->expectException(OutOfBoundsException::class);
288295
$this->expectExceptionMessage('Offset: "3" does not exists in object of instance: Laudis\Neo4j\Types\CypherList');
289-
$this->list[3];
296+
$this->map[3];
290297
}
291298

292299
public function testOffsetGetNegative(): void
293300
{
294301
$this->expectException(OutOfBoundsException::class);
295302
$this->expectExceptionMessage('Offset: "-1" does not exists in object of instance: Laudis\Neo4j\Types\CypherList');
296-
$this->list[-1];
303+
$this->map[-1];
297304
}
298305

299306
public function testIssetValid(): void
300307
{
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]));
304311
}
305312

306313
public function testIssetInValid(): void
307314
{
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]));
310317
}
311318

312319
public function testIssetValidNull(): void

0 commit comments

Comments
 (0)