Exemplo n.º 1
0
 /**
  * @test
  */
 public function it_should_index_deep()
 {
     $items = [['id' => 1, 'name' => 'foo', 'thing' => ['parent_id' => 10]], ['id' => 2, 'name' => 'bar', 'thing' => ['parent_id' => 11]], ['id' => 3, 'name' => 'baz', 'thing' => ['parent_id' => 10]]];
     $collection = new Map($items);
     $grouped = $collection->indexBy(function ($element) {
         return $element['thing']['parent_id'];
     });
     $expected = [10 => ['id' => 3, 'name' => 'baz', 'thing' => ['parent_id' => 10]], 11 => ['id' => 2, 'name' => 'bar', 'thing' => ['parent_id' => 11]]];
     $this->assertEquals($expected, $grouped->toArray());
 }