Completed
Branch develop (049341)
by Freddie
02:29
created

RepositoryTest   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 67
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 26
dl 0
loc 67
rs 10
c 0
b 0
f 0
wmc 5

5 Methods

Rating   Name   Duplication   Size   Complexity  
A testItInitializeWithGateway() 0 7 1
A testItUseGateway() 0 19 1
A testItUseInterface() 0 5 1
A testItInitializeGatewayUsingSetter() 0 8 1
A testItGetUndefinedGatewayThrowException() 0 6 1
1
<?php
2
3
namespace FlexPHP\Repositories\Tests\Unit;
4
5
use FlexPHP\Repositories\Exception\UndefinedGatewayRepositoryException;
6
use FlexPHP\Repositories\RepositoryInterface;
7
use FlexPHP\Repositories\Tests\Mocks\GatewayMock;
8
use FlexPHP\Repositories\Tests\Mocks\RepositoryMock;
9
use FlexPHP\Repositories\Tests\TestCase;
10
11
class RepositoryTest extends TestCase
12
{
13
    public function testItUseInterface()
14
    {
15
        $repository = new RepositoryMock();
16
17
        $this->assertInstanceOf(RepositoryInterface::class, $repository);
18
    }
19
20
    /**
21
     * @throws UndefinedGatewayRepositoryException
22
     */
23
    public function testItInitializeWithGateway()
24
    {
25
        $gateway = new GatewayMock();
26
27
        $repository = new RepositoryMock($gateway);
28
29
        $this->assertSame($gateway, $repository->getGateway());
30
    }
31
32
    /**
33
     * @throws UndefinedGatewayRepositoryException
34
     */
35
    public function testItInitializeGatewayUsingSetter()
36
    {
37
        $gateway = new GatewayMock();
38
39
        $repository = new RepositoryMock();
40
41
        $this->assertSame($repository, $repository->setGateway($gateway));
42
        $this->assertSame($gateway, $repository->getGateway());
43
    }
44
45
    /**
46
     * @throws UndefinedGatewayRepositoryException
47
     */
48
    public function testItUseGateway()
49
    {
50
        $gateway = new GatewayMock();
51
52
        $repository = new RepositoryMock();
53
        $repository->setGateway($gateway);
54
55
        $id = 1;
56
        $item = ['foo'];
57
        $notExist = 999;
58
59
        $this->assertSame($id, $repository->push($item));
60
        $this->assertSame($item, $repository->get($id));
61
        $this->assertSame(true, $repository->shift($id, $item));
62
        $this->assertSame(true, $repository->pop($id));
63
64
        $this->assertSame(null, $repository->get($notExist));
65
        $this->assertSame(false, $repository->shift($notExist, []));
66
        $this->assertSame(false, $repository->pop($notExist));
67
    }
68
69
    /**
70
     * @throws UndefinedGatewayRepositoryException
71
     */
72
    public function testItGetUndefinedGatewayThrowException()
73
    {
74
        $this->expectException(UndefinedGatewayRepositoryException::class);
75
76
        $repository = new RepositoryMock();
77
        $repository->getGateway();
78
    }
79
}
80