1 | <?php |
||
3 | class EloquentRepositoryTests extends \AbstractEloquentTests |
||
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(); |
||
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 |