Completed
Pull Request — develop (#89)
by Ionut
02:19
created

EloquentRepositoryTests   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 68
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 4
dl 0
loc 68
rs 10
c 0
b 0
f 0

8 Methods

Rating   Name   Duplication   Size   Complexity  
A testFindAll() 0 7 1
A testFindAllUsingGroupBy() 0 6 1
A testFindAllUsingHaving() 0 6 1
A testFind() 0 7 1
A testFindBy() 0 7 1
A testFindFirst() 0 7 1
A testFindWhere() 0 9 1
A testFindWhereIn() 0 9 1
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 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