Example #1
0
 public function testMGroup()
 {
     $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::mgroup($list, 'type'));
     $expect = ['food' => ['fruit' => ['a' => $apple], 'vegetable' => ['c' => $carrot]], 'creature' => ['animal' => ['b' => $bear]]];
     $this->assertEquals($expect, Objects::mgroup($list, 'group', 'type'));
     $expect = ['food' => ['a' => $apple, 'c' => $carrot], 'creature' => ['b' => $bear]];
     $this->assertEquals($expect, Objects::mgroup($list, 'group'));
 }