File: IterableTester.php

package info (click to toggle)
doctrine 3.3.3%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 11,236 kB
  • sloc: php: 105,633; xml: 1,312; makefile: 35; sh: 14
file content (38 lines) | stat: -rw-r--r-- 990 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
<?php

declare(strict_types=1);

namespace Doctrine\Tests;

use Doctrine\ORM\AbstractQuery;
use Doctrine\ORM\Query;
use PHPUnit\Framework\Assert;

use function is_array;
use function iterator_to_array;

final class IterableTester
{
    public static function assertResultsAreTheSame(Query $query): void
    {
        $result   = $query->getResult();
        $iterable = $query->toIterable();

        Assert::assertSame($result, self::iterableToArray($iterable));

        $result   = $query->getResult(AbstractQuery::HYDRATE_ARRAY);
        $iterable = $query->toIterable([], AbstractQuery::HYDRATE_ARRAY);

        Assert::assertSame($result, self::iterableToArray($iterable));
    }

    /**
     * Copy the iterable into an array. If the iterable is already an array, return it.
     *
     * @return mixed[]
     */
    public static function iterableToArray(iterable $iterable): array
    {
        return is_array($iterable) ? $iterable : iterator_to_array($iterable, true);
    }
}