Issues (40)

tests/Doctrine/ORMQueryResultFieldsTest.php (1 issue)

Labels
Severity
1
<?php
2
3
namespace Zenstruck\Porpaginas\Tests\Doctrine;
4
5
use Zenstruck\Porpaginas\Doctrine\ORMQueryResult;
6
use Zenstruck\Porpaginas\Result;
7
use Zenstruck\Porpaginas\Tests\Doctrine\Fixtures\ORMEntity;
8
use Zenstruck\Porpaginas\Tests\ResultTest;
9
10
class ORMQueryResultFieldsTest extends ResultTest
11
{
12
    use HasEntityManager;
13
14
    /**
15
     * @test
16
     */
17
    public function can_iterate(): void
18
    {
19
        $result = $this->createResultWithItems(2);
20
21
        $this->assertCount(2, $result);
22
        $this->assertSame([
23
            [
24
                'id' => 1,
25
                'my_value' => 'value 1',
26
            ],
27
            [
28
                'id' => 2,
29
                'my_value' => 'value 2',
30
            ],
31
        ], \iterator_to_array($result));
32
    }
33
34
    /**
35
     * @test
36
     */
37
    public function can_batch_iterate(): void
38
    {
39
        $result = $this->createResultWithItems(2)->batchProcessor();
40
41
        $this->assertCount(2, $result);
42
        $this->assertSame([
43
            [
44
                'id' => 1,
45
                'my_value' => 'value 1',
46
            ],
47
            [
48
                'id' => 2,
49
                'my_value' => 'value 2',
50
            ],
51
        ], \iterator_to_array($result));
52
    }
53
54
    protected function createResultWithItems(int $count): Result
55
    {
56
        $this->persistEntities($count);
57
58
        $query = $this->em->createQuery(\sprintf('SELECT e.id, e.value AS my_value FROM %s e', ORMEntity::class));
0 ignored issues
show
The method createQuery() does not exist on null. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

58
        /** @scrutinizer ignore-call */ 
59
        $query = $this->em->createQuery(\sprintf('SELECT e.id, e.value AS my_value FROM %s e', ORMEntity::class));

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
59
60
        return new ORMQueryResult($query, true, false);
61
    }
62
63
    protected function getExpectedValueAtPosition(int $position)
64
    {
65
        return [
66
            'id' => $position,
67
            'my_value' => 'value '.$position,
68
        ];
69
    }
70
}
71