Skip to content

Commit 61770f3

Browse files
authored
[9.x] Improve Test for Pluck method in Collection (#43361)
* [9.x] Improve Test for Pluck method in Collection * [9.x] Improve Test for Pluck method in Collection fix style * [9.x] Improve Test for Pluck method in Collection
1 parent d44cd8d commit 61770f3

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

tests/Support/SupportCollectionTest.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2170,6 +2170,44 @@ public function testPluckWithArrayAccessValues($collection)
21702170
$this->assertEquals(['foo', 'bar'], $data->pluck('email')->all());
21712171
}
21722172

2173+
/**
2174+
* @dataProvider collectionClassProvider
2175+
*/
2176+
public function testPluckWithDotNotation($collection)
2177+
{
2178+
$data = new $collection([
2179+
[
2180+
'name' => 'amir',
2181+
'skill' => [
2182+
'backend' => ['php', 'python'],
2183+
],
2184+
],
2185+
[
2186+
'name' => 'taylor',
2187+
'skill' => [
2188+
'backend' => ['php', 'asp', 'java'],
2189+
],
2190+
],
2191+
]);
2192+
2193+
$this->assertEquals([['php', 'python'], ['php', 'asp', 'java']], $data->pluck('skill.backend')->all());
2194+
}
2195+
2196+
/**
2197+
* @dataProvider collectionClassProvider
2198+
*/
2199+
public function testPluckDuplicateKeysExist($collection)
2200+
{
2201+
$data = new collection([
2202+
['brand' => 'Tesla', 'color' => 'red'],
2203+
['brand' => 'Pagani', 'color' => 'white'],
2204+
['brand' => 'Tesla', 'color' => 'black'],
2205+
['brand' => 'Pagani', 'color' => 'orange'],
2206+
]);
2207+
2208+
$this->assertEquals(['Tesla' => 'black', 'Pagani' => 'orange'], $data->pluck('color', 'brand')->all());
2209+
}
2210+
21732211
/**
21742212
* @dataProvider collectionClassProvider
21752213
*/

0 commit comments

Comments
 (0)