1
|
|
|
<?php |
2
|
|
|
declare(strict_types=1); |
3
|
|
|
|
4
|
|
|
namespace InvoiceNinjaModuleTest\Service; |
5
|
|
|
|
6
|
|
|
use InvoiceNinjaModule\Exception\NotFoundException; |
7
|
|
|
use InvoiceNinjaModule\Model\Interfaces\BaseInterface; |
8
|
|
|
use InvoiceNinjaModule\Model\Interfaces\TaxRateInterface; |
9
|
|
|
use InvoiceNinjaModule\Service\Interfaces\ObjectServiceInterface; |
10
|
|
|
use InvoiceNinjaModule\Service\Interfaces\TaxRateManagerInterface; |
11
|
|
|
use InvoiceNinjaModule\Service\TaxRateManager; |
12
|
|
|
use PHPUnit\Framework\TestCase; |
13
|
|
|
|
14
|
|
|
class TaxRateManagerTest extends TestCase |
15
|
|
|
{ |
16
|
|
|
/** @var TaxRateManagerInterface */ |
17
|
|
|
private $taxRateManager; |
18
|
|
|
/** @var \PHPUnit_Framework_MockObject_MockObject */ |
19
|
|
|
private $objectManagerMock; |
20
|
|
|
|
21
|
|
|
protected function setUp() : void |
22
|
|
|
{ |
23
|
|
|
parent::setUp(); |
24
|
|
|
|
25
|
|
|
$this->objectManagerMock = $this->createMock(ObjectServiceInterface::class); |
26
|
|
|
$this->taxRateManager = new TaxRateManager($this->objectManagerMock); |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
public function testCreate() : void |
30
|
|
|
{ |
31
|
|
|
self::assertInstanceOf(TaxRateManagerInterface::class, $this->taxRateManager); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
public function testCreateProduct() : void |
35
|
|
|
{ |
36
|
|
|
$taxRateMock = $this->createMock(TaxRateInterface::class); |
37
|
|
|
|
38
|
|
|
$this->objectManagerMock->expects(self::once()) |
39
|
|
|
->method('createObject') |
40
|
|
|
->with( |
41
|
|
|
self::isInstanceOf(TaxRateInterface::class), |
42
|
|
|
self::stringContains('/tax_rates') |
43
|
|
|
) |
44
|
|
|
->willReturn($taxRateMock); |
45
|
|
|
|
46
|
|
|
$this->taxRateManager = new TaxRateManager($this->objectManagerMock); |
47
|
|
|
|
48
|
|
|
self::assertInstanceOf(TaxRateInterface::class, $this->taxRateManager->createTaxRate($taxRateMock)); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
public function testDelete() : void |
52
|
|
|
{ |
53
|
|
|
$taxRateMock = $this->createMock(TaxRateInterface::class); |
54
|
|
|
|
55
|
|
|
$this->objectManagerMock->expects(self::once()) |
56
|
|
|
->method('deleteObject') |
57
|
|
|
->with( |
58
|
|
|
self::isInstanceOf(TaxRateInterface::class), |
59
|
|
|
self::stringContains('/tax_rates') |
60
|
|
|
) |
61
|
|
|
->willReturn($taxRateMock); |
62
|
|
|
|
63
|
|
|
$this->taxRateManager = new TaxRateManager($this->objectManagerMock); |
64
|
|
|
|
65
|
|
|
self::assertInstanceOf(TaxRateInterface::class, $this->taxRateManager->delete($taxRateMock)); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
|
69
|
|
|
public function testGetProductById() : void |
70
|
|
|
{ |
71
|
|
|
$taxRateMock = $this->createMock(TaxRateInterface::class); |
72
|
|
|
|
73
|
|
|
$this->objectManagerMock->expects(self::once()) |
74
|
|
|
->method('getObjectById') |
75
|
|
|
->with( |
76
|
|
|
self::isInstanceOf(TaxRateInterface::class), |
77
|
|
|
self::isType('integer'), |
78
|
|
|
self::stringContains('/tax_rates') |
79
|
|
|
) |
80
|
|
|
->willReturn($taxRateMock); |
81
|
|
|
|
82
|
|
|
$this->taxRateManager = new TaxRateManager($this->objectManagerMock); |
83
|
|
|
|
84
|
|
|
self::assertInstanceOf(TaxRateInterface::class, $this->taxRateManager->getTaxRateById(777)); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* @expectedException \InvoiceNinjaModule\Exception\NotFoundException |
89
|
|
|
*/ |
90
|
|
|
public function testGetProductByIdException() : void |
91
|
|
|
{ |
92
|
|
|
$this->objectManagerMock->expects(self::once()) |
93
|
|
|
->method('getObjectById') |
94
|
|
|
->with( |
95
|
|
|
self::isInstanceOf(TaxRateInterface::class), |
96
|
|
|
self::isType('integer'), |
97
|
|
|
self::stringContains('/tax_rates') |
98
|
|
|
) |
99
|
|
|
->willThrowException(new NotFoundException()); |
100
|
|
|
|
101
|
|
|
self::assertInstanceOf(TaxRateInterface::class, $this->taxRateManager->getTaxRateById(777)); |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
public function testUpdate() : void |
105
|
|
|
{ |
106
|
|
|
$taxRateMock = $this->createMock(TaxRateInterface::class); |
107
|
|
|
|
108
|
|
|
$this->objectManagerMock->expects(self::once()) |
109
|
|
|
->method('updateObject') |
110
|
|
|
->with( |
111
|
|
|
self::isInstanceOf(TaxRateInterface::class), |
112
|
|
|
self::stringContains('/tax_rates') |
113
|
|
|
) |
114
|
|
|
->willReturn($taxRateMock); |
115
|
|
|
|
116
|
|
|
$this->taxRateManager = new TaxRateManager($this->objectManagerMock); |
117
|
|
|
|
118
|
|
|
self::assertInstanceOf(TaxRateInterface::class, $this->taxRateManager->update($taxRateMock)); |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
public function testRestore() : void |
122
|
|
|
{ |
123
|
|
|
$taxRateMock = $this->createMock(TaxRateInterface::class); |
124
|
|
|
|
125
|
|
|
$this->objectManagerMock->expects(self::once()) |
126
|
|
|
->method('restoreObject') |
127
|
|
|
->with( |
128
|
|
|
self::isInstanceOf(TaxRateInterface::class), |
129
|
|
|
self::stringContains('/tax_rates') |
130
|
|
|
) |
131
|
|
|
->willReturn($taxRateMock); |
132
|
|
|
|
133
|
|
|
$this->taxRateManager = new TaxRateManager($this->objectManagerMock); |
134
|
|
|
|
135
|
|
|
self::assertInstanceOf(TaxRateInterface::class, $this->taxRateManager->restore($taxRateMock)); |
136
|
|
|
} |
137
|
|
|
|
138
|
|
|
public function testArchive() : void |
139
|
|
|
{ |
140
|
|
|
$taxRateMock = $this->createMock(TaxRateInterface::class); |
141
|
|
|
|
142
|
|
|
$this->objectManagerMock->expects(self::once()) |
143
|
|
|
->method('archiveObject') |
144
|
|
|
->with( |
145
|
|
|
self::isInstanceOf(TaxRateInterface::class), |
146
|
|
|
self::stringContains('/tax_rates') |
147
|
|
|
) |
148
|
|
|
->willReturn($taxRateMock); |
149
|
|
|
|
150
|
|
|
$this->taxRateManager = new TaxRateManager($this->objectManagerMock); |
151
|
|
|
|
152
|
|
|
self::assertInstanceOf(TaxRateInterface::class, $this->taxRateManager->archive($taxRateMock)); |
153
|
|
|
} |
154
|
|
|
|
155
|
|
|
public function testGetAllProductsEmpty() : void |
156
|
|
|
{ |
157
|
|
|
$this->objectManagerMock->expects(self::once()) |
158
|
|
|
->method('getAllObjects') |
159
|
|
|
->with( |
160
|
|
|
self::isInstanceOf(TaxRateInterface::class), |
161
|
|
|
self::stringContains('/tax_rates'), |
162
|
|
|
self::isType('integer'), |
163
|
|
|
self::isType('integer') |
164
|
|
|
) |
165
|
|
|
->willReturn([]); |
166
|
|
|
|
167
|
|
|
$this->taxRateManager = new TaxRateManager($this->objectManagerMock); |
168
|
|
|
|
169
|
|
|
self::assertInternalType('array', $this->taxRateManager->getAllTaxRates()); |
170
|
|
|
} |
171
|
|
|
|
172
|
|
|
public function testGetAllProducts() : void |
173
|
|
|
{ |
174
|
|
|
$taxRateMock = $this->createMock(TaxRateInterface::class); |
175
|
|
|
|
176
|
|
|
$this->objectManagerMock->expects(self::once()) |
177
|
|
|
->method('getAllObjects') |
178
|
|
|
->with( |
179
|
|
|
self::isInstanceOf(TaxRateInterface::class), |
180
|
|
|
self::stringContains('/tax_rates'), |
181
|
|
|
self::isType('integer'), |
182
|
|
|
self::isType('integer') |
183
|
|
|
) |
184
|
|
|
->willReturn([ 'test' => $taxRateMock ]); |
185
|
|
|
|
186
|
|
|
$this->taxRateManager = new TaxRateManager($this->objectManagerMock); |
187
|
|
|
|
188
|
|
|
self::assertInternalType('array', $this->taxRateManager->getAllTaxRates()); |
189
|
|
|
} |
190
|
|
|
|
191
|
|
|
/** |
192
|
|
|
* @expectedException \InvoiceNinjaModule\Exception\InvalidResultException |
193
|
|
|
*/ |
194
|
|
|
public function testGetAllProductsOtherResult() : void |
195
|
|
|
{ |
196
|
|
|
$taxRateMock = $this->createMock(BaseInterface::class); |
197
|
|
|
|
198
|
|
|
$this->objectManagerMock->expects(self::once()) |
199
|
|
|
->method('getAllObjects') |
200
|
|
|
->with( |
201
|
|
|
self::isInstanceOf(TaxRateInterface::class), |
202
|
|
|
self::stringContains('/tax_rates'), |
203
|
|
|
self::isType('integer'), |
204
|
|
|
self::isType('integer') |
205
|
|
|
) |
206
|
|
|
->willReturn([ 'test' => $taxRateMock ]); |
207
|
|
|
|
208
|
|
|
$this->taxRateManager = new TaxRateManager($this->objectManagerMock); |
209
|
|
|
|
210
|
|
|
self::assertInternalType('array', $this->taxRateManager->getAllTaxRates()); |
211
|
|
|
} |
212
|
|
|
} |
213
|
|
|
|