コード例 #1
0
ファイル: RxTest.php プロジェクト: robmachado/collections
 /**
  * Tests grouping by a deep key
  *
  * @return void
  */
 public function testGroupByDeepKey()
 {
     $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 Dictionary($items);
     $grouped = $collection->groupBy('thing.parent_id');
     $expected = [10 => [['id' => 1, 'name' => 'foo', 'thing' => ['parent_id' => 10]], ['id' => 3, 'name' => 'baz', 'thing' => ['parent_id' => 10]]], 11 => [['id' => 2, 'name' => 'bar', 'thing' => ['parent_id' => 11]]]];
     $this->assertEquals($expected, $grouped->toArray());
 }