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(2, $result); |
10
|
|
|
$this->assertContainsOnlyInstancesOf(\Rinvex\Tests\Stubs\EloquentUser::class, $result); |
11
|
|
|
} |
12
|
|
|
|
13
|
|
|
public function testFind() |
14
|
|
|
{ |
15
|
|
|
$userRepository = $this->userRepository(); |
16
|
|
|
$result = $userRepository->find(1); |
17
|
|
|
$this->assertInstanceOf(\Rinvex\Tests\Stubs\EloquentUser::class, $result); |
18
|
|
|
$this->assertEquals(1, $result->id); |
19
|
|
|
} |
20
|
|
|
|
21
|
|
|
public function testFindBy() |
22
|
|
|
{ |
23
|
|
|
$userRepository = $this->userRepository(); |
24
|
|
|
$result = $userRepository->findBy('name', 'evsign'); |
25
|
|
|
$this->assertInstanceOf(\Rinvex\Tests\Stubs\EloquentUser::class, $result); |
26
|
|
|
$this->assertEquals('evsign', $result->name); |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
public function testFindFirst() |
30
|
|
|
{ |
31
|
|
|
$userRepository = $this->userRepository(); |
32
|
|
|
$result = $userRepository->findFirst(); |
33
|
|
|
$this->assertInstanceOf(\Rinvex\Tests\Stubs\EloquentUser::class, $result); |
34
|
|
|
$this->assertEquals(1, $result->id); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
public function testFindWhere() |
38
|
|
|
{ |
39
|
|
|
$userRepository = $this->userRepository(); |
40
|
|
|
$result = $userRepository->findWhere(['name', '=', 'omranic']); |
41
|
|
|
$this->assertCount(1, $result); |
42
|
|
|
$this->assertInstanceOf(\Illuminate\Database\Eloquent\Collection::class, $result); |
43
|
|
|
$this->assertContainsOnlyInstancesOf(\Rinvex\Tests\Stubs\EloquentUser::class, $result); |
44
|
|
|
$this->assertEquals('omranic', $result->first()->name); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
public function testFindWhereIn() |
48
|
|
|
{ |
49
|
|
|
$userRepository = $this->userRepository(); |
50
|
|
|
$result = $userRepository->findWhereIn(['name', ['omranic', 'evsign']]); |
51
|
|
|
$this->assertCount(2, $result); |
52
|
|
|
$this->assertInstanceOf(\Illuminate\Database\Eloquent\Collection::class, $result); |
53
|
|
|
$this->assertContainsOnlyInstancesOf(\Rinvex\Tests\Stubs\EloquentUser::class, $result); |
54
|
|
|
$this->assertEquals(['evsign', 'omranic'], $result->pluck('name')->toArray()); |
55
|
|
|
} |
56
|
|
|
} |
57
|
|
|
|
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.