Skip to content

Commit f874f25

Browse files
Add test for dot method in LazyCollection
This commit adds test coverage for the dot method, verifying it correctly flattens multi-dimensional arrays with dot notation in keys for: - Nested associative arrays - Empty nested arrays - Arrays with numeric keys
1 parent d38378e commit f874f25

File tree

1 file changed

+43
-17
lines changed

1 file changed

+43
-17
lines changed

tests/Support/SupportLazyCollectionTest.php

Lines changed: 43 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -373,15 +373,6 @@ public function testCollapseWithKeys()
373373
$collapsed = $collection->collapseWithKeys();
374374

375375
$this->assertEquals(['a' => 1, 'b' => 2], $collapsed->all());
376-
377-
$collection = new LazyCollection([
378-
[],
379-
['a' => 1],
380-
new LazyCollection([]),
381-
]);
382-
$collapsed = $collection->collapseWithKeys();
383-
384-
$this->assertEquals(['a' => 1], $collapsed->all());
385376
}
386377

387378
public function testContainsOneItem()
@@ -402,23 +393,58 @@ public function testDoesntContain()
402393

403394
$this->assertTrue($collection->doesntContain(10));
404395
$this->assertFalse($collection->doesntContain(3));
405-
406396
$this->assertTrue($collection->doesntContain('value', '>', 10));
407-
$this->assertFalse($collection->doesntContain('value', '<', 10));
408-
409397
$this->assertTrue($collection->doesntContain(function ($value) {
410398
return $value > 10;
411399
}));
412-
$this->assertFalse($collection->doesntContain(function ($value) {
413-
return $value < 10;
414-
}));
415400

416401
$users = new LazyCollection([
417-
['name' => 'Taylor', 'role' => 'developer'],
418-
['name' => 'Jeffrey', 'role' => 'designer'],
402+
[
403+
'name' => 'Taylor',
404+
'role' => 'developer',
405+
],
406+
[
407+
'name' => 'Jeffrey',
408+
'role' => 'designer',
409+
],
419410
]);
420411

421412
$this->assertTrue($users->doesntContain('name', 'Adam'));
422413
$this->assertFalse($users->doesntContain('name', 'Taylor'));
423414
}
415+
416+
public function testDot()
417+
{
418+
$collection = new LazyCollection([
419+
'foo' => [
420+
'bar' => 'baz',
421+
],
422+
'user' => [
423+
'name' => 'Taylor',
424+
'profile' => [
425+
'age' => 30,
426+
],
427+
],
428+
'users' => [
429+
0 => [
430+
'name' => 'Taylor',
431+
],
432+
1 => [
433+
'name' => 'Jeffrey',
434+
],
435+
],
436+
]);
437+
438+
$dotted = $collection->dot();
439+
440+
$expected = [
441+
'foo.bar' => 'baz',
442+
'user.name' => 'Taylor',
443+
'user.profile.age' => 30,
444+
'users.0.name' => 'Taylor',
445+
'users.1.name' => 'Jeffrey',
446+
];
447+
448+
$this->assertEquals($expected, $dotted->all());
449+
}
424450
}

0 commit comments

Comments
 (0)