ORMEntityRepositoryTest   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 112
Duplicated Lines 0 %

Importance

Changes 3
Bugs 0 Features 3
Metric Value
wmc 8
eloc 36
c 3
b 0
f 3
dl 0
loc 112
rs 10

8 Methods

Rating   Name   Duplication   Size   Complexity  
A can_find() 0 10 1
A calls_are_passed_to_inner_repository() 0 10 1
A can_find_one_by() 0 10 1
A can_iterate_and_count() 0 8 1
A can_find_all() 0 7 1
A can_create_batch_processor() 0 8 1
A can_find_by() 0 7 1
A can_find_one_by_with_order() 0 10 1
1
<?php
2
3
namespace Zenstruck\Porpaginas\Tests\Doctrine\Repository;
4
5
use PHPUnit\Framework\TestCase;
6
use Zenstruck\Porpaginas\Tests\Doctrine\Fixtures\ORMEntity;
7
use Zenstruck\Porpaginas\Tests\Doctrine\Fixtures\ORMEntityRepository;
8
use Zenstruck\Porpaginas\Tests\Doctrine\HasEntityManager;
9
10
/**
11
 * @author Kevin Bond <[email protected]>
12
 */
13
final class ORMEntityRepositoryTest extends TestCase
14
{
15
    use HasEntityManager;
16
17
    /**
18
     * @test
19
     */
20
    public function can_iterate_and_count(): void
21
    {
22
        $this->persistEntities(4);
23
24
        $repository = 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

24
        $repository = new ORMEntityRepository(/** @scrutinizer ignore-type */ $this->em);
Loading history...
25
26
        $this->assertCount(4, \iterator_to_array($repository));
27
        $this->assertCount(4, $repository);
28
    }
29
30
    /**
31
     * @test
32
     */
33
    public function can_create_batch_processor(): void
34
    {
35
        $this->persistEntities(4);
36
37
        $processor = (new ORMEntityRepository($this->em))->batchProcessor();
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

37
        $processor = (new ORMEntityRepository(/** @scrutinizer ignore-type */ $this->em))->batchProcessor();
Loading history...
38
39
        $this->assertCount(4, \iterator_to_array($processor));
40
        $this->assertCount(4, $processor);
41
    }
42
43
    /**
44
     * @test
45
     */
46
    public function calls_are_passed_to_inner_repository(): void
47
    {
48
        $this->persistEntities(4);
49
50
        $repository = 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

50
        $repository = new ORMEntityRepository(/** @scrutinizer ignore-type */ $this->em);
Loading history...
51
52
        $entity = $repository->findOneByValue('value 2');
0 ignored issues
show
Bug introduced by
The method findOneByValue() does not exist on Zenstruck\Porpaginas\Tes...res\ORMEntityRepository. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

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

52
        /** @scrutinizer ignore-call */ 
53
        $entity = $repository->findOneByValue('value 2');
Loading history...
53
54
        $this->assertInstanceOf(ORMEntity::class, $entity);
55
        $this->assertSame('value 2', $entity->value);
56
    }
57
58
    /**
59
     * @test
60
     */
61
    public function can_find(): void
62
    {
63
        $this->persistEntities(4);
64
65
        $repository = 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

65
        $repository = new ORMEntityRepository(/** @scrutinizer ignore-type */ $this->em);
Loading history...
66
67
        $entity = $repository->find(1);
68
69
        $this->assertInstanceOf(ORMEntity::class, $entity);
70
        $this->assertSame('value 1', $entity->value);
71
    }
72
73
    /**
74
     * @test
75
     */
76
    public function can_find_all(): void
77
    {
78
        $this->persistEntities(4);
79
80
        $repository = 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

80
        $repository = new ORMEntityRepository(/** @scrutinizer ignore-type */ $this->em);
Loading history...
81
82
        $this->assertCount(4, $repository->findAll());
83
    }
84
85
    /**
86
     * @test
87
     */
88
    public function can_find_one_by(): void
89
    {
90
        $this->persistEntities(4);
91
92
        $repository = 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

92
        $repository = new ORMEntityRepository(/** @scrutinizer ignore-type */ $this->em);
Loading history...
93
94
        $entity = $repository->findOneBy(['value' => 'value 2']);
95
96
        $this->assertInstanceOf(ORMEntity::class, $entity);
97
        $this->assertSame('value 2', $entity->value);
98
    }
99
100
    /**
101
     * @test
102
     */
103
    public function can_find_one_by_with_order(): void
104
    {
105
        $this->persistEntities(4);
106
107
        $repository = 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

107
        $repository = new ORMEntityRepository(/** @scrutinizer ignore-type */ $this->em);
Loading history...
108
109
        $entity = $repository->findOneBy([], ['id' => 'DESC']);
110
111
        $this->assertInstanceOf(ORMEntity::class, $entity);
112
        $this->assertSame('value 4', $entity->value);
113
    }
114
115
    /**
116
     * @test
117
     */
118
    public function can_find_by(): void
119
    {
120
        $this->persistEntities(4);
121
122
        $repository = 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

122
        $repository = new ORMEntityRepository(/** @scrutinizer ignore-type */ $this->em);
Loading history...
123
124
        $this->assertCount(1, $repository->findBy(['value' => 'value 2']));
125
    }
126
}
127