Passed
Push — master ( 6137ca...01151b )
by Kevin
02:21
created

DBALMatchableObjectRepositoryTest   A

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 can_match_with_callable() 0 13 1
A createRepository() 0 3 1
1
<?php
2
3
namespace Zenstruck\Porpaginas\Tests\Doctrine\Repository;
4
5
use Doctrine\DBAL\Query\QueryBuilder;
6
use Zenstruck\Porpaginas\Tests\Doctrine\Fixtures\DBALObject;
7
use Zenstruck\Porpaginas\Tests\Doctrine\Fixtures\DBALObjectRepository;
8
9
/**
10
 * @author Kevin Bond <[email protected]>
11
 */
12
final class DBALMatchableObjectRepositoryTest 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) {
22
            $qb->where('value = :value')
23
                ->setParameter('value', 'value 2')
24
            ;
25
        });
26
27
        $this->assertInstanceOf(DBALObject::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) {
39
            $qb->where('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(): DBALObjectRepository
50
    {
51
        return new DBALObjectRepository($this->em->getConnection());
0 ignored issues
show
Bug introduced by
The method getConnection() 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

51
        return new DBALObjectRepository($this->em->/** @scrutinizer ignore-call */ getConnection());

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...
52
    }
53
}
54