ORMMatchableRepositoryTest   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 15
c 1
b 0
f 1
dl 0
loc 40
rs 10
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A can_match_one_with_callable() 0 12 1
A createRepository() 0 3 1
A can_match_with_callable() 0 13 1
1
<?php
2
3
namespace Zenstruck\Porpaginas\Tests\Doctrine\Repository;
4
5
use Doctrine\ORM\QueryBuilder;
6
use Zenstruck\Porpaginas\Tests\Doctrine\Fixtures\ORMEntity;
7
use Zenstruck\Porpaginas\Tests\Doctrine\Fixtures\ORMEntityRepository;
8
9
/**
10
 * @author Kevin Bond <[email protected]>
11
 */
12
final class ORMMatchableRepositoryTest extends MatchableRepositoryTest
13
{
14
    /**
15
     * @test
16
     */
17
    public function can_match_one_with_callable(): void
18
    {
19
        $this->persistEntities(4);
20
21
        $object = $this->createRepository()->matchOne(function(QueryBuilder $qb, string $alias) {
22
            $qb->where("{$alias}.value = :value")
23
                ->setParameter('value', 'value 2')
24
            ;
25
        });
26
27
        $this->assertInstanceOf(ORMEntity::class, $object);
28
        $this->assertSame('value 2', $object->value);
29
    }
30
31
    /**
32
     * @test
33
     */
34
    public function can_match_with_callable(): void
35
    {
36
        $this->persistEntities(4);
37
38
        $objects = $this->createRepository()->match(function(QueryBuilder $qb, string $alias) {
39
            $qb->where("{$alias}.id > :value")
40
                ->setParameter('value', 2)
41
            ;
42
        });
43
44
        $this->assertCount(2, $objects);
45
        $this->assertSame('value 3', \iterator_to_array($objects)[0]->value);
46
        $this->assertSame('value 4', \iterator_to_array($objects)[1]->value);
47
    }
48
49
    protected function createRepository(): ORMEntityRepository
50
    {
51
        return new ORMEntityRepository($this->em);
0 ignored issues
show
Bug introduced by
It seems like $this->em can also be of type null; however, parameter $em of Zenstruck\Porpaginas\Tes...pository::__construct() does only seem to accept Doctrine\ORM\EntityManagerInterface, maybe add an additional type check? ( Ignorable by Annotation )

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

51
        return new ORMEntityRepository(/** @scrutinizer ignore-type */ $this->em);
Loading history...
52
    }
53
}
54