Pinq\Tests\Integration\Traversable\Complex\ArrayTraversalTest::testGroupByWithArrayKey PHP Метод

testGroupByWithArrayKey() публичный Метод

public testGroupByWithArrayKey ( Pinq\ITraversable $traversable, array $data )
$traversable Pinq\ITraversable
$data array
    public function testGroupByWithArrayKey(\Pinq\ITraversable $traversable, array $data)
    {
        $ageGroupData = $traversable->groupBy(function ($i) {
            return ['sex' => $i['sex'], 'ageGroup' => floor($i['age'] / 10) * 10];
        })->orderByAscending(function (\Pinq\ITraversable $group, $key) {
            return $key['ageGroup'];
        })->thenByAscending(function (\Pinq\ITraversable $group, $key) {
            return $key['sex'];
        })->select(function (\Pinq\ITraversable $group, $key) {
            $ageGroup = $key['ageGroup'] . '+';
            $sex = $key['sex'];
            return sprintf('%s(%s){%s}', $ageGroup, $sex, $group->implode(',', function ($i) {
                return $i['firstName'];
            }));
        })->implode(':');
        $this->assertEquals('20+(Female){Casy}:20+(Male){Alex,Dave}:30+(Female){Zoe,Sandy,Beth}:30+(Male){Daniel}:' . '40+(Male){Hugo}:50+(Male){Daniel}:60+(Male){David}', $ageGroupData);
    }