forked from tighten/collect
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
70 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -973,11 +973,9 @@ public function testExcept() | |
|
||
$this->assertEquals(['first' => 'Taylor'], $data->except(['last', 'email', 'missing'])->all()); | ||
$this->assertEquals(['first' => 'Taylor'], $data->except('last', 'email', 'missing')->all()); | ||
$this->assertEquals(['first' => 'Taylor'], $data->except(collect(['last' => 'Otwell', 'email' => '[email protected]', 'missing']))->all()); | ||
|
||
$this->assertEquals(['first' => 'Taylor', 'email' => '[email protected]'], $data->except(['last'])->all()); | ||
$this->assertEquals(['first' => 'Taylor', 'email' => '[email protected]'], $data->except('last')->all()); | ||
$this->assertEquals(['first' => 'Taylor', 'email' => '[email protected]'], $data->except(collect(['last' => 'Otwell']))->all()); | ||
} | ||
|
||
public function testPluckWithArrayAndObjectValues() | ||
|
@@ -1601,6 +1599,48 @@ public function testGroupByClosureWhereItemsHaveMultipleGroupsPreservingKeys() | |
$this->assertEquals($expected_result, $result->toArray()); | ||
} | ||
|
||
public function testGroupByMultiLevelAndClosurePreservingKeys() | ||
{ | ||
$data = new Collection([ | ||
10 => ['user' => 1, 'skilllevel' => 1, 'roles' => ['Role_1', 'Role_3']], | ||
20 => ['user' => 2, 'skilllevel' => 1, 'roles' => ['Role_1', 'Role_2']], | ||
30 => ['user' => 3, 'skilllevel' => 2, 'roles' => ['Role_1']], | ||
40 => ['user' => 4, 'skilllevel' => 2, 'roles' => ['Role_2']], | ||
]); | ||
|
||
$result = $data->groupBy([ | ||
'skilllevel', | ||
function ($item) { | ||
return $item['roles']; | ||
}, | ||
], true); | ||
|
||
$expected_result = [ | ||
1 => [ | ||
'Role_1' => [ | ||
10 => ['user' => 1, 'skilllevel' => 1, 'roles' => ['Role_1', 'Role_3']], | ||
20 => ['user' => 2, 'skilllevel' => 1, 'roles' => ['Role_1', 'Role_2']], | ||
], | ||
'Role_3' => [ | ||
10 => ['user' => 1, 'skilllevel' => 1, 'roles' => ['Role_1', 'Role_3']], | ||
], | ||
'Role_2' => [ | ||
20 => ['user' => 2, 'skilllevel' => 1, 'roles' => ['Role_1', 'Role_2']], | ||
], | ||
], | ||
2 => [ | ||
'Role_1' => [ | ||
30 => ['user' => 3, 'skilllevel' => 2, 'roles' => ['Role_1']], | ||
], | ||
'Role_2' => [ | ||
40 => ['user' => 4, 'skilllevel' => 2, 'roles' => ['Role_2']], | ||
], | ||
], | ||
]; | ||
|
||
$this->assertEquals($expected_result, $result->toArray()); | ||
} | ||
|
||
public function testKeyByAttribute() | ||
{ | ||
$data = new Collection([['rating' => 1, 'name' => '1'], ['rating' => 2, 'name' => '2'], ['rating' => 3, 'name' => '3']]); | ||
|
@@ -1928,9 +1968,11 @@ public function testOnly() | |
$this->assertEquals($data->all(), $data->only(null)->all()); | ||
$this->assertEquals(['first' => 'Taylor'], $data->only(['first', 'missing'])->all()); | ||
$this->assertEquals(['first' => 'Taylor'], $data->only('first', 'missing')->all()); | ||
$this->assertEquals(['first' => 'Taylor'], $data->only(collect(['first', 'missing']))->all()); | ||
|
||
$this->assertEquals(['first' => 'Taylor', 'email' => '[email protected]'], $data->only(['first', 'email'])->all()); | ||
$this->assertEquals(['first' => 'Taylor', 'email' => '[email protected]'], $data->only('first', 'email')->all()); | ||
$this->assertEquals(['first' => 'Taylor', 'email' => '[email protected]'], $data->only(collect(['first', 'email']))->all()); | ||
} | ||
|
||
public function testGettingAvgItemsFromCollection() | ||
|
@@ -2422,6 +2464,12 @@ public function testUnlessDefault() | |
|
||
$this->assertSame(['michael', 'tom', 'taylor'], $collection->toArray()); | ||
} | ||
|
||
public function testGetWithNullReturnsNull() | ||
{ | ||
$collection = new Collection([1, 2, 3]); | ||
$this->assertNull($collection->get(null)); | ||
} | ||
} | ||
|
||
class TestSupportCollectionHigherOrderItem | ||
|