예제 #1
0
 public function testPGroup()
 {
     $apple = new Thing('Apple', 'fruit', 'green', 'food');
     $bear = new Thing('Bear', 'animal', 'brown', 'creature');
     $carrot = new Thing('Carrot', 'vegetable', 'brown', 'food');
     $list = ['a' => $apple, 'b' => $bear, 'c' => $carrot];
     $expect = ['fruit' => ['a' => $apple], 'animal' => ['b' => $bear], 'vegetable' => ['c' => $carrot]];
     $this->assertEquals($expect, Objects::pgroup($list, 'typeProperty'));
     $expect = ['food' => ['fruit' => ['a' => $apple], 'vegetable' => ['c' => $carrot]], 'creature' => ['animal' => ['b' => $bear]]];
     $this->assertEquals($expect, Objects::pgroup($list, 'groupProperty', 'typeProperty'));
     $expect = ['food' => ['a' => $apple, 'c' => $carrot], 'creature' => ['b' => $bear]];
     $this->assertEquals($expect, Objects::pgroup($list, 'groupProperty'));
 }