Skip to content

Commit 1333230

Browse files
committed
ITT: Collections asserts refactored.
1 parent 8a78ef9 commit 1333230

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

src/Asserts/CollectionAsserts.php

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,25 @@ trait CollectionAsserts
88
{
99
protected function assertCollectionsEqual(Collection $collection1, Collection $collection2, $key)
1010
{
11-
$collection1 = $collection1->pluck($key);
12-
$collection2 = $collection2->pluck($key);
13-
$diff = $collection1->diff($collection2);
11+
$keys1 = $collection1->pluck($key)->toArray();
12+
$keys2 = $collection2->pluck($key)->toArray();
1413

15-
$this->assertEmpty($diff, 'Failed asserting that collections are equal.');
14+
$diff1 = array_diff($keys1, $keys2);
15+
$diff2 = array_diff($keys2, $keys1);
16+
17+
$bothDiffsAreEmpty = (empty($diff1) && empty($diff2));
18+
$this->assertTrue($bothDiffsAreEmpty, 'Failed asserting that collections are equal.');
1619
}
1720

1821
protected function assertCollectionsNotEqual(Collection $collection1, Collection $collection2, $key)
1922
{
20-
$collection1 = $collection1->pluck($key);
21-
$collection2 = $collection2->pluck($key);
22-
$diff = $collection1->diff($collection2);
23+
$keys1 = $collection1->pluck($key)->toArray();
24+
$keys2 = $collection2->pluck($key)->toArray();
25+
26+
$diff1 = array_diff($keys1, $keys2);
27+
$diff2 = array_diff($keys2, $keys1);
2328

24-
$this->assertNotEmpty($diff, 'Failed asserting that collections are not equal.');
29+
$atLeastOneDiffIsNotEmpty = (!empty($diff1) || !empty($diff2));
30+
$this->assertTrue($atLeastOneDiffIsNotEmpty, 'Failed asserting that collections are not equal.');
2531
}
2632
}

0 commit comments

Comments
 (0)