|
1
|
|
|
<?php declare(strict_types=1); |
|
2
|
|
|
/* |
|
3
|
|
|
* This file is part of FlexPHP. |
|
4
|
|
|
* |
|
5
|
|
|
* (c) Freddie Gar <[email protected]> |
|
6
|
|
|
* |
|
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
8
|
|
|
* file that was distributed with this source code. |
|
9
|
|
|
*/ |
|
10
|
|
|
namespace FlexPHP\Repositories\Tests\Unit; |
|
11
|
|
|
|
|
12
|
|
|
use FlexPHP\Repositories\Exception\UndefinedGatewayRepositoryException; |
|
13
|
|
|
use FlexPHP\Repositories\RepositoryInterface; |
|
14
|
|
|
use FlexPHP\Repositories\Tests\Mocks\GatewayMock; |
|
15
|
|
|
use FlexPHP\Repositories\Tests\Mocks\RepositoryMock; |
|
16
|
|
|
use FlexPHP\Repositories\Tests\TestCase; |
|
17
|
|
|
|
|
18
|
|
|
class RepositoryTest extends TestCase |
|
19
|
|
|
{ |
|
20
|
|
|
public function testItUseInterface(): void |
|
21
|
|
|
{ |
|
22
|
|
|
$repository = new RepositoryMock(); |
|
23
|
|
|
|
|
24
|
|
|
$this->assertInstanceOf(RepositoryInterface::class, $repository); |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* @throws UndefinedGatewayRepositoryException |
|
29
|
|
|
*/ |
|
30
|
|
|
public function testItInitializeWithGateway(): void |
|
31
|
|
|
{ |
|
32
|
|
|
$gateway = new GatewayMock(); |
|
33
|
|
|
|
|
34
|
|
|
$repository = new RepositoryMock($gateway); |
|
35
|
|
|
|
|
36
|
|
|
$this->assertSame($gateway, $repository->getGateway()); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* @throws UndefinedGatewayRepositoryException |
|
41
|
|
|
*/ |
|
42
|
|
|
public function testItInitializeGatewayUsingSetter(): void |
|
43
|
|
|
{ |
|
44
|
|
|
$gateway = new GatewayMock(); |
|
45
|
|
|
|
|
46
|
|
|
$repository = new RepositoryMock(); |
|
47
|
|
|
$repository->setGateway($gateway); |
|
48
|
|
|
|
|
49
|
|
|
$this->assertSame($gateway, $repository->getGateway()); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* @throws UndefinedGatewayRepositoryException |
|
54
|
|
|
*/ |
|
55
|
|
|
public function testItUseGateway(): void |
|
56
|
|
|
{ |
|
57
|
|
|
$gateway = new GatewayMock(); |
|
58
|
|
|
|
|
59
|
|
|
$repository = new RepositoryMock(); |
|
60
|
|
|
$repository->setGateway($gateway); |
|
61
|
|
|
|
|
62
|
|
|
$identifier = 1; |
|
63
|
|
|
$item = ['foo']; |
|
64
|
|
|
$notExist = 999; |
|
65
|
|
|
|
|
66
|
|
|
$this->assertSame($identifier, $repository->push($item)); |
|
67
|
|
|
$this->assertSame($item, $repository->get($identifier)); |
|
68
|
|
|
$this->assertSame(true, $repository->shift($identifier, $item)); |
|
69
|
|
|
$this->assertSame(true, $repository->pop($identifier)); |
|
70
|
|
|
|
|
71
|
|
|
$this->assertSame(null, $repository->get($notExist)); |
|
72
|
|
|
$this->assertSame(false, $repository->shift($notExist, [])); |
|
73
|
|
|
$this->assertSame(false, $repository->pop($notExist)); |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
/** |
|
77
|
|
|
* @throws UndefinedGatewayRepositoryException |
|
78
|
|
|
*/ |
|
79
|
|
|
public function testItGetUndefinedGatewayThrowException(): void |
|
80
|
|
|
{ |
|
81
|
|
|
$this->expectException(UndefinedGatewayRepositoryException::class); |
|
82
|
|
|
|
|
83
|
|
|
$repository = new RepositoryMock(); |
|
84
|
|
|
$repository->getGateway(); |
|
85
|
|
|
} |
|
86
|
|
|
} |
|
87
|
|
|
|