Completed
Push — develop ( be9c7d...6c1fc8 )
by Abdelrahman
06:53
created

testFindAllUsingMultipleHaving()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 0
1
<?php
2
3
class EloquentRepositoryTests 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 testFindAll()
6
    {
7
        $userRepository = $this->userRepository();
8
        $result         = $userRepository->findAll();
9
        $this->assertCount(4, $result);
10
        $this->assertContainsOnlyInstancesOf(\Rinvex\Tests\Stubs\EloquentUser::class, $result);
11
    }
12
13
    public function testFindAllUsingGroupBy()
14
    {
15
        $userRepository = $this->userRepository();
16
        $result         = $userRepository->groupBy('name')->findAll();
17
        $this->assertCount(3, $result);
18
    }
19
20
    public function testFindAllUsingHaving()
21
    {
22
        $userRepository = $this->userRepository();
23
        $result         = $userRepository->groupBy('name')->having('age', '>', 24)->findAll();
24
        $this->assertCount(3, $result);
25
    }
26
27
    public function testFindAllUsingHavingAndOrHaving()
28
    {
29
        $userRepository = $this->userRepository();
30
        $result         = $userRepository->groupBy('name')->having('age', '>', 24)->orHaving('name', 'like', '%o%')->findAll();
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 127 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
31
        $this->assertCount(3, $result);
32
    }
33
34
    public function testFindAllUsingMultipleHaving()
35
    {
36
        $userRepository = $this->userRepository();
37
        $result         = $userRepository->groupBy('name')->having('age', '>', 24)->having('age', '<', 26)->findAll();
38
        $this->assertCount(1, $result);
39
    }
40
41
    public function testFind()
42
    {
43
        $userRepository = $this->userRepository();
44
        $result         = $userRepository->find(1);
45
        $this->assertInstanceOf(\Rinvex\Tests\Stubs\EloquentUser::class, $result);
46
        $this->assertEquals(1, $result->id);
47
    }
48
49
    public function testFindBy()
50
    {
51
        $userRepository = $this->userRepository();
52
        $result         = $userRepository->findBy('name', 'evsign');
53
        $this->assertInstanceOf(\Rinvex\Tests\Stubs\EloquentUser::class, $result);
54
        $this->assertEquals('evsign', $result->name);
55
    }
56
57
    public function testFindFirst()
58
    {
59
        $userRepository = $this->userRepository();
60
        $result         = $userRepository->findFirst();
61
        $this->assertInstanceOf(\Rinvex\Tests\Stubs\EloquentUser::class, $result);
62
        $this->assertEquals(1, $result->id);
63
    }
64
65
    public function testFindWhere()
66
    {
67
        $userRepository = $this->userRepository();
68
        $result         = $userRepository->findWhere(['name', '=', 'omranic']);
69
        $this->assertCount(1, $result);
70
        $this->assertInstanceOf(\Illuminate\Database\Eloquent\Collection::class, $result);
71
        $this->assertContainsOnlyInstancesOf(\Rinvex\Tests\Stubs\EloquentUser::class, $result);
72
        $this->assertEquals('omranic', $result->first()->name);
73
    }
74
75
    public function testFindWhereIn()
76
    {
77
        $userRepository = $this->userRepository();
78
        $result         = $userRepository->findWhereIn(['name', ['omranic', 'evsign']]);
79
        $this->assertCount(2, $result);
80
        $this->assertInstanceOf(\Illuminate\Database\Eloquent\Collection::class, $result);
81
        $this->assertContainsOnlyInstancesOf(\Rinvex\Tests\Stubs\EloquentUser::class, $result);
82
        $this->assertEquals(['evsign', 'omranic'], $result->pluck('name')->toArray());
83
    }
84
85
    public function testCount()
86
    {
87
        $userRepository = $this->userRepository();
88
        $result         = $userRepository->count();
89
        $this->assertEquals(4, $result);
90
    }
91
92
    public function testMin()
93
    {
94
        $userRepository = $this->userRepository();
95
        $result         = $userRepository->min('age');
96
        $this->assertEquals(24, $result);
97
    }
98
99
    public function testMax()
100
    {
101
        $userRepository = $this->userRepository();
102
        $result         = $userRepository->max('age');
103
        $this->assertEquals(28, $result);
104
    }
105
106
    public function testAvg()
107
    {
108
        $userRepository = $this->userRepository();
109
        $result         = $userRepository->avg('age');
110
        $this->assertEquals(25.75, $result);
111
    }
112
113
    public function testSum()
114
    {
115
        $userRepository = $this->userRepository();
116
        $result         = $userRepository->sum('age');
117
        $this->assertEquals(103, $result);
118
    }
119
}
120