Skip to content

[12.x] Add test for untested methods in LazyCollection #54996

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions tests/Support/SupportLazyCollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -312,4 +312,47 @@ public function testAfter()

$this->assertSame(['name' => 'Mohamed', 'age' => 35], $result);
}

public function testBefore()
{
// Test finding item before value with non-strict comparison
$data = new LazyCollection([1, 2, '3', 4]);
$result = $data->before(2);
$this->assertSame(1, $result);

// Test finding item before value with strict comparison
$result = $data->before(4, true);
$this->assertSame('3', $result);

// Test finding item before the one that matches a callback condition
$users = new LazyCollection([
['name' => 'Taylor', 'age' => 35],
['name' => 'Jeffrey', 'age' => 45],
['name' => 'Mohamed', 'age' => 35],
]);
$result = $users->before(function ($user) {
return $user['name'] === 'Jeffrey';
});
$this->assertSame(['name' => 'Taylor', 'age' => 35], $result);
}

public function testShuffle()
{
$data = new LazyCollection([1, 2, 3, 4, 5]);
$shuffled = $data->shuffle();

$this->assertCount(5, $shuffled);
$this->assertEquals([1, 2, 3, 4, 5], $shuffled->sort()->values()->all());

// Test shuffling associative array maintains key-value pairs
$users = new LazyCollection([
'first' => ['name' => 'Taylor'],
'second' => ['name' => 'Jeffrey'],
]);
$shuffled = $users->shuffle();

$this->assertCount(2, $shuffled);
$this->assertTrue($shuffled->contains('name', 'Taylor'));
$this->assertTrue($shuffled->contains('name', 'Jeffrey'));
}
}
Loading