|
1
|
|
|
<?php |
|
2
|
|
|
|
|
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 testFind() |
|
28
|
|
|
{ |
|
29
|
|
|
$userRepository = $this->userRepository(); |
|
30
|
|
|
$result = $userRepository->find(1); |
|
31
|
|
|
$this->assertInstanceOf(\Rinvex\Tests\Stubs\EloquentUser::class, $result); |
|
32
|
|
|
$this->assertEquals(1, $result->id); |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
public function testFindBy() |
|
36
|
|
|
{ |
|
37
|
|
|
$userRepository = $this->userRepository(); |
|
38
|
|
|
$result = $userRepository->findBy('name', 'evsign'); |
|
39
|
|
|
$this->assertInstanceOf(\Rinvex\Tests\Stubs\EloquentUser::class, $result); |
|
40
|
|
|
$this->assertEquals('evsign', $result->name); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
public function testFindFirst() |
|
44
|
|
|
{ |
|
45
|
|
|
$userRepository = $this->userRepository(); |
|
46
|
|
|
$result = $userRepository->findFirst(); |
|
47
|
|
|
$this->assertInstanceOf(\Rinvex\Tests\Stubs\EloquentUser::class, $result); |
|
48
|
|
|
$this->assertEquals(1, $result->id); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
public function testFindWhere() |
|
52
|
|
|
{ |
|
53
|
|
|
$userRepository = $this->userRepository(); |
|
54
|
|
|
$result = $userRepository->findWhere(['name', '=', 'omranic']); |
|
55
|
|
|
$this->assertCount(1, $result); |
|
56
|
|
|
$this->assertInstanceOf(\Illuminate\Database\Eloquent\Collection::class, $result); |
|
57
|
|
|
$this->assertContainsOnlyInstancesOf(\Rinvex\Tests\Stubs\EloquentUser::class, $result); |
|
58
|
|
|
$this->assertEquals('omranic', $result->first()->name); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
public function testFindWhereIn() |
|
62
|
|
|
{ |
|
63
|
|
|
$userRepository = $this->userRepository(); |
|
64
|
|
|
$result = $userRepository->findWhereIn(['name', ['omranic', 'evsign']]); |
|
65
|
|
|
$this->assertCount(2, $result); |
|
66
|
|
|
$this->assertInstanceOf(\Illuminate\Database\Eloquent\Collection::class, $result); |
|
67
|
|
|
$this->assertContainsOnlyInstancesOf(\Rinvex\Tests\Stubs\EloquentUser::class, $result); |
|
68
|
|
|
$this->assertEquals(['evsign', 'omranic'], $result->pluck('name')->toArray()); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
public function testCount() |
|
72
|
|
|
{ |
|
73
|
|
|
$userRepository = $this->userRepository(); |
|
74
|
|
|
$result = $userRepository->count(); |
|
75
|
|
|
$this->assertEquals(4, $result); |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
public function testMin() |
|
79
|
|
|
{ |
|
80
|
|
|
$userRepository = $this->userRepository(); |
|
81
|
|
|
$result = $userRepository->min('age'); |
|
82
|
|
|
$this->assertEquals(24, $result); |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
public function testMax() |
|
86
|
|
|
{ |
|
87
|
|
|
$userRepository = $this->userRepository(); |
|
88
|
|
|
$result = $userRepository->max('age'); |
|
89
|
|
|
$this->assertEquals(28, $result); |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
public function testAvg() |
|
93
|
|
|
{ |
|
94
|
|
|
$userRepository = $this->userRepository(); |
|
95
|
|
|
$result = $userRepository->avg('age'); |
|
96
|
|
|
$this->assertEquals(25.75, $result); |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
public function testSum() |
|
100
|
|
|
{ |
|
101
|
|
|
$userRepository = $this->userRepository(); |
|
102
|
|
|
$result = $userRepository->sum('age'); |
|
103
|
|
|
$this->assertEquals(103, $result); |
|
104
|
|
|
} |
|
105
|
|
|
} |
|
106
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.