Completed
Push — develop ( f34a65...a0b033 )
by Abdelrahman
02:30
created

testFindAllWithSkipDefaultCriteria()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 13
c 0
b 0
f 0
rs 9.4285
cc 1
eloc 8
nc 1
nop 0
1
<?php
2
3
class EloquentRepositoryCriteriaIntegrationTests extends AbstractEloquentTests
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
4
{
5
    public function testFindAllByClassNameCriterion()
6
    {
7
        $userRepository = $this->userRepository();
8
        $userRepository->pushCriterion(FirstTestCriterion::class);
9
        $result = $userRepository->findAll();
10
11
        $this->assertCount(1, $result);
12
        $this->assertContainsOnlyInstancesOf(\Rinvex\Tests\Stubs\EloquentUser::class, $result);
13
        $this->assertEquals($result->first()->id, 1);
14
    }
15
16
    public function testFindAllByObjectCriterion()
17
    {
18
        $userRepository = $this->userRepository();
19
        $userRepository->pushCriterion(new FirstTestCriterion());
20
        $result = $userRepository->findAll();
21
22
        $this->assertCount(1, $result);
23
        $this->assertContainsOnlyInstancesOf(\Rinvex\Tests\Stubs\EloquentUser::class, $result);
24
        $this->assertEquals($result->first()->id, 1);
25
    }
26
27
    public function testFindAllByClosureCriterion()
28
    {
29
        $userRepository = $this->userRepository();
30
        $userRepository->pushCriterion(function ($query, $repository) {
0 ignored issues
show
Unused Code introduced by
The parameter $repository is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
31
            return $query->where('id', 2);
32
        });
33
        $result = $userRepository->findAll();
34
35
        $this->assertCount(1, $result);
36
        $this->assertContainsOnlyInstancesOf(\Rinvex\Tests\Stubs\EloquentUser::class, $result);
37
        $this->assertEquals($result->first()->id, 2);
38
    }
39
40
    public function testFindAllWithDefaultCriteria()
41
    {
42
        $userRepository = $this->userRepository();
43
        $userRepository->pushCriterion(function ($query, $repository) {
0 ignored issues
show
Unused Code introduced by
The parameter $repository is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
44
            return $query->orWhere('id', 1);
45
        })->setDefaultCriteria([new SecondTestCriterion()]);
46
47
        $result = $userRepository->findAll();
48
49
        $this->assertCount(2, $result);
50
        $this->assertContainsOnlyInstancesOf(\Rinvex\Tests\Stubs\EloquentUser::class, $result);
51
    }
52
53
    public function testFindAllWithSkipCriteria()
54
    {
55
        $userRepository = $this->userRepository();
56
57
        $userRepository->pushCriteria([
58
            new FirstTestCriterion(),
59
            new SecondTestCriterion(),
60
        ]);
61
62
        $result = $userRepository->skipCriteria()->findAll();
63
64
        $this->assertCount(2, $result);
65
        $this->assertContainsOnlyInstancesOf(\Rinvex\Tests\Stubs\EloquentUser::class, $result);
66
    }
67
68
    public function testFindAllAfterRemoveSkipCriteria()
69
    {
70
        $userRepository = $this->userRepository();
71
72
        $userRepository->pushCriteria([
73
            new FirstTestCriterion(),
74
        ]);
75
76
        $result = $userRepository->skipCriteria()->findAll();
77
78
        $this->assertCount(2, $result);
79
        $this->assertContainsOnlyInstancesOf(\Rinvex\Tests\Stubs\EloquentUser::class, $result);
80
81
        $result = $userRepository->skipCriteria(false)->findAll();
82
        $this->assertCount(1, $result);
83
        $this->assertContainsOnlyInstancesOf(\Rinvex\Tests\Stubs\EloquentUser::class, $result);
84
    }
85
86
    public function testFindAllWithSkipDefaultCriteria()
87
    {
88
        $userRepository = $this->userRepository();
89
90
        $userRepository->pushCriteria([
91
            new FirstTestCriterion(),
92
        ])->setDefaultCriteria([new SecondTestCriterion()]);
93
94
        $result = $userRepository->skipDefaultCriteria()->findAll();
95
96
        $this->assertCount(1, $result);
97
        $this->assertContainsOnlyInstancesOf(\Rinvex\Tests\Stubs\EloquentUser::class, $result);
98
    }
99
}
100