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
|
|
|
|
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.