1 | <?php |
||
23 | class OrangePaymentSlipDataTest extends \PHPUnit_Framework_TestCase |
||
24 | { |
||
25 | /** |
||
26 | * The object under test |
||
27 | * |
||
28 | * @var OrangePaymentSlipData |
||
29 | */ |
||
30 | protected $slipData; |
||
31 | |||
32 | /** |
||
33 | * Setup the object under test |
||
34 | * |
||
35 | * @return void |
||
36 | */ |
||
37 | protected function setUp() |
||
41 | |||
42 | /** |
||
43 | * Tests the getWithReferenceNumber and setWithReferenceNumber methods |
||
44 | * |
||
45 | * @return void |
||
46 | * @covers ::setWithReferenceNumber |
||
47 | * @covers ::getWithReferenceNumber |
||
48 | * @covers ::isBool |
||
49 | * @covers ::setReferenceNumber |
||
50 | * @covers ::getReferenceNumber |
||
51 | */ |
||
52 | public function testSetWithReferenceNumber() |
||
73 | |||
74 | /** |
||
75 | * Tests the setReferenceNumber method when disabled |
||
76 | * |
||
77 | * @return void |
||
78 | * @expectedException \SwissPaymentSlip\SwissPaymentSlip\Exception\DisabledDataException |
||
79 | * @expectedExceptionMessage You are accessing the disabled reference number. You need to re-enable it first. |
||
80 | * @covers ::setReferenceNumber |
||
81 | */ |
||
82 | public function testSetReferenceNumberWhenDisabled() |
||
87 | |||
88 | /** |
||
89 | * Tests the getReferenceNumber method when disabled |
||
90 | * |
||
91 | * @return void |
||
92 | * @expectedException \SwissPaymentSlip\SwissPaymentSlip\Exception\DisabledDataException |
||
93 | * @expectedExceptionMessage You are accessing the disabled reference number. You need to re-enable it first. |
||
94 | * @covers ::getReferenceNumber |
||
95 | */ |
||
96 | public function testGetReferenceNumberWhenDisabled() |
||
101 | |||
102 | /** |
||
103 | * Tests the setWithReferenceNumber method with an invalid parameter |
||
104 | * |
||
105 | * @return void |
||
106 | * @expectedException \InvalidArgumentException |
||
107 | * @expectedExceptionMessage $withReferenceNumber is not a boolean. |
||
108 | * @covers ::setWithReferenceNumber |
||
109 | * @covers ::isBool |
||
110 | */ |
||
111 | public function testSetWithReferenceNumberInvalidParameter() |
||
115 | |||
116 | /** |
||
117 | * Tests the getWithBankingCustomerId and setWithBankingCustomerId methods |
||
118 | * |
||
119 | * @return void |
||
120 | * @covers ::setWithBankingCustomerId |
||
121 | * @covers ::getWithBankingCustomerId |
||
122 | * @covers ::isBool |
||
123 | * @covers ::setBankingCustomerId |
||
124 | * @covers ::getBankingCustomerId |
||
125 | */ |
||
126 | public function testSetWithBankingCustomerId() |
||
147 | |||
148 | /** |
||
149 | * Tests the setBankingCustomerId method when disabled |
||
150 | * |
||
151 | * @return void |
||
152 | * @expectedException \SwissPaymentSlip\SwissPaymentSlip\Exception\DisabledDataException |
||
153 | * @expectedExceptionMessage You are accessing the disabled banking customer ID. You need to re-enable it first. |
||
154 | * @covers ::setBankingCustomerId |
||
155 | */ |
||
156 | public function testSetBankingCustomerIdNumberWhenDisabled() |
||
161 | |||
162 | /** |
||
163 | * Tests the getBankingCustomerId method when disabled |
||
164 | * |
||
165 | * @return void |
||
166 | * @expectedException \SwissPaymentSlip\SwissPaymentSlip\Exception\DisabledDataException |
||
167 | * @expectedExceptionMessage You are accessing the disabled banking customer ID. You need to re-enable it first. |
||
168 | * @covers ::getBankingCustomerId |
||
169 | */ |
||
170 | public function testGetBankingCustomerIdNumberWhenDisabled() |
||
175 | |||
176 | /** |
||
177 | * Tests the setWithBankingCustomerId method with an invalid parameter |
||
178 | * |
||
179 | * @return void |
||
180 | * @expectedException \InvalidArgumentException |
||
181 | * @expectedExceptionMessage $withBankingCustomerId is not a boolean. |
||
182 | * @covers ::setWithBankingCustomerId |
||
183 | * @covers ::isBool |
||
184 | */ |
||
185 | public function testSetWithBankingCustomerIdInvalidParameter() |
||
189 | |||
190 | /** |
||
191 | * Tests the getCompleteReferenceNumber method |
||
192 | * Throws exception because of banking customer ID with reference number is longer than max allowed (26) |
||
193 | * |
||
194 | * @return void |
||
195 | * @covers ::setReferenceNumber |
||
196 | */ |
||
197 | public function testSetReferenceNumberLengthExceptionA() |
||
202 | |||
203 | /** |
||
204 | * Tests the getCompleteReferenceNumber method |
||
205 | * Throws exception because of banking customer ID with reference number is longer than max allowed (26) |
||
206 | * |
||
207 | * @return void |
||
208 | * @covers ::setReferenceNumber |
||
209 | */ |
||
210 | public function testSetReferenceNumberLengthExceptionB() |
||
211 | { |
||
212 | $this->setExpectedException(PaymentSlipException::class); |
||
213 | $this->slipData->setBankingCustomerId('1234567890', 10); |
||
214 | $this->slipData->setReferenceNumber('75200334559000123'); |
||
215 | } |
||
216 | |||
217 | /** |
||
218 | * Tests the setBankingCustomerId method |
||
219 | * Throws exception because of banking customer ID is longer than max (10) |
||
220 | * |
||
221 | * @return void |
||
222 | * @covers ::setBankingCustomerId |
||
223 | */ |
||
224 | public function testsetBankingCustomerIdLengthExceptionA() |
||
229 | |||
230 | /** |
||
231 | * Tests the setBankingCustomerId method |
||
232 | * Throws exception because of banking customer ID is longer than expected by default (6) |
||
233 | * |
||
234 | * @return void |
||
235 | * @covers ::setBankingCustomerId |
||
236 | */ |
||
237 | public function testsetBankingCustomerIdLengthExceptionB() |
||
242 | |||
243 | /** |
||
244 | * Tests the setBankingCustomerId method |
||
245 | * Throws exception because of banking customer ID with reference number is longer than max allowed (26) |
||
246 | * |
||
247 | * @return void |
||
248 | * @covers ::setBankingCustomerId |
||
249 | */ |
||
250 | public function testsetBankingCustomerIdLengthExceptionC() |
||
251 | { |
||
252 | $this->setExpectedException(PaymentSlipException::class); |
||
253 | $this->slipData->setReferenceNumber('75200334559000123'); |
||
254 | $this->slipData->setBankingCustomerId('1234567890', 10); |
||
255 | } |
||
256 | |||
257 | /** |
||
258 | * Tests the getCompleteReferenceNumber method |
||
259 | * |
||
260 | * @return void |
||
261 | * @covers ::getCompleteReferenceNumber |
||
262 | * @covers ::appendCheckDigit |
||
263 | * @covers ::breakStringIntoBlocks |
||
264 | * @covers ::modulo10 |
||
265 | */ |
||
266 | public function testGetCompleteReferenceNumber() |
||
267 | { |
||
268 | // Test with reference number & banking customer ID |
||
269 | $this->slipData->setReferenceNumber('7520033455900012'); |
||
270 | |||
271 | $this->slipData->setBankingCustomerId('215703'); |
||
272 | |||
273 | // Formatted and filled with zeros |
||
274 | $this->assertEquals( |
||
275 | '21 57030 00075 20033 45590 00126', |
||
276 | $this->slipData->getCompleteReferenceNumber() |
||
277 | ); |
||
278 | // Not formatted but filled with zeros |
||
279 | $this->assertEquals( |
||
280 | '215703000075200334559000126', |
||
281 | $this->slipData->getCompleteReferenceNumber(false) |
||
282 | ); |
||
283 | // Formatted but not filled with zeros |
||
284 | $this->assertEquals( |
||
285 | '21 57030 00075 20033 45590 00126', |
||
286 | $this->slipData->getCompleteReferenceNumber(true, false) |
||
287 | ); |
||
288 | // Neither formatted nor filled with zeros |
||
289 | $this->assertEquals( |
||
290 | '215703000075200334559000126', |
||
291 | $this->slipData->getCompleteReferenceNumber(false, false) |
||
292 | ); |
||
293 | |||
294 | // With long banking customer ID with expected 0 filling |
||
295 | $this->slipData->setBankingCustomerId('123456789', 10); |
||
296 | |||
297 | // Formatted and filled with zeros |
||
298 | $this->assertEquals( |
||
299 | '01 23456 78975 20033 45590 00128', |
||
300 | $this->slipData->getCompleteReferenceNumber() |
||
301 | ); |
||
302 | // Not formatted but filled with zeros |
||
303 | $this->assertEquals( |
||
304 | '012345678975200334559000128', |
||
305 | $this->slipData->getCompleteReferenceNumber(false) |
||
306 | ); |
||
307 | |||
308 | // Formatted but not filled with zeros |
||
309 | $this->assertEquals( |
||
310 | '01 23456 78975 20033 45590 00128', |
||
311 | $this->slipData->getCompleteReferenceNumber(true, false) |
||
312 | ); |
||
313 | // Neither formatted nor filled with zeros |
||
314 | $this->assertEquals( |
||
315 | '012345678975200334559000128', |
||
316 | $this->slipData->getCompleteReferenceNumber(false, false) |
||
317 | ); |
||
318 | |||
319 | // With long banking customer ID without expected 0 filling |
||
320 | $this->slipData->setBankingCustomerId('1234567', 7); |
||
321 | |||
322 | // Formatted and filled with zeros |
||
323 | $this->assertEquals( |
||
324 | '12 34567 00075 20033 45590 00128', |
||
325 | $this->slipData->getCompleteReferenceNumber() |
||
326 | ); |
||
327 | // Not formatted but filled with zeros |
||
328 | $this->assertEquals( |
||
329 | '123456700075200334559000128', |
||
330 | $this->slipData->getCompleteReferenceNumber(false) |
||
331 | ); |
||
332 | |||
333 | // Formatted but not filled with zeros |
||
334 | $this->assertEquals( |
||
335 | '12 34567 00075 20033 45590 00128', |
||
336 | $this->slipData->getCompleteReferenceNumber(true, false) |
||
337 | ); |
||
338 | // Neither formatted nor filled with zeros |
||
339 | $this->assertEquals( |
||
340 | '123456700075200334559000128', |
||
341 | $this->slipData->getCompleteReferenceNumber(false, false) |
||
342 | ); |
||
343 | |||
344 | // Test with reference number but without banking customer ID |
||
345 | $this->slipData->setWithBankingCustomerId(false); |
||
346 | |||
347 | // Formatted and filled with zeros |
||
348 | $this->assertEquals( |
||
349 | '00 00000 00075 20033 45590 00129', |
||
350 | $this->slipData->getCompleteReferenceNumber() |
||
351 | ); |
||
352 | // Not formatted but filled with zeros |
||
353 | $this->assertEquals( |
||
354 | '000000000075200334559000129', |
||
355 | $this->slipData->getCompleteReferenceNumber(false) |
||
356 | ); |
||
357 | // Formatted but not filled with zeros |
||
358 | $this->assertEquals( |
||
359 | '75 20033 45590 00129', |
||
360 | $this->slipData->getCompleteReferenceNumber(true, false) |
||
361 | ); |
||
362 | // Neither formatted nor filled with zeros |
||
363 | $this->assertEquals( |
||
364 | '75200334559000129', |
||
365 | $this->slipData->getCompleteReferenceNumber(false, false) |
||
366 | ); |
||
367 | } |
||
368 | |||
369 | /** |
||
370 | * Tests the getCompleteReferenceNumber method with the reference number disabled |
||
371 | * |
||
372 | * @return void |
||
373 | * @expectedException \SwissPaymentSlip\SwissPaymentSlip\Exception\DisabledDataException |
||
374 | * @expectedExceptionMessage You are accessing the disabled reference number. You need to re-enable it first. |
||
375 | * @covers ::getCompleteReferenceNumber |
||
376 | * @covers ::getReferenceNumber |
||
377 | */ |
||
378 | public function testGetCompleteReferenceNumberWithReferenceNrDisabled() |
||
383 | |||
384 | /** |
||
385 | * Tests the getCodeLine method |
||
386 | * |
||
387 | * @return void |
||
388 | * @covers ::getCodeLine |
||
389 | * @covers ::modulo10 |
||
390 | * @covers ::getAccountDigits |
||
391 | */ |
||
392 | public function testGetCodeLine() |
||
393 | { |
||
394 | $this->slipData->setAccountNumber('01-145-6'); |
||
395 | $this->slipData->setAmount(2830.50); |
||
396 | $this->slipData->setReferenceNumber('7520033455900012'); |
||
397 | $this->slipData->setBankingCustomerId('215703'); |
||
398 | |||
399 | // Filled with zeros |
||
400 | $this->assertEquals( |
||
401 | '0100002830509>215703000075200334559000126+ 010001456>', |
||
402 | $this->slipData->getCodeLine() |
||
403 | ); |
||
404 | // Not filled with zeros |
||
405 | $this->assertEquals( |
||
406 | '0100002830509>215703000075200334559000126+ 010001456>', |
||
407 | $this->slipData->getCodeLine(false) |
||
408 | ); |
||
409 | |||
410 | $this->slipData->setReferenceNumber('123456789'); |
||
411 | $this->slipData->setBankingCustomerId('1234'); |
||
412 | |||
413 | // Filled with zeros |
||
414 | $this->assertEquals( |
||
415 | '0100002830509>001234000000000001234567892+ 010001456>', |
||
416 | $this->slipData->getCodeLine() |
||
417 | ); |
||
418 | // Not filled with zeros |
||
419 | $this->assertEquals( |
||
420 | '0100002830509>001234000000000001234567892+ 010001456>', |
||
421 | $this->slipData->getCodeLine(false) |
||
422 | ); |
||
423 | |||
424 | // With long banking customer ID with expected 0 filling |
||
425 | $this->slipData->setBankingCustomerId('123456789', 10); |
||
426 | |||
427 | // Filled with zeros |
||
428 | $this->assertEquals( |
||
429 | '0100002830509>012345678900000001234567891+ 010001456>', |
||
430 | $this->slipData->getCodeLine() |
||
431 | ); |
||
432 | // Not filled with zeros |
||
433 | $this->assertEquals( |
||
434 | '0100002830509>012345678900000001234567891+ 010001456>', |
||
435 | $this->slipData->getCodeLine(false) |
||
436 | ); |
||
437 | |||
438 | // With long banking customer ID without expected 0 filling |
||
439 | $this->slipData->setBankingCustomerId('1234567', 7); |
||
440 | |||
441 | // Filled with zeros |
||
442 | $this->assertEquals( |
||
443 | '0100002830509>123456700000000001234567891+ 010001456>', |
||
444 | $this->slipData->getCodeLine() |
||
445 | ); |
||
446 | // Not filled with zeros |
||
447 | $this->assertEquals( |
||
448 | '0100002830509>123456700000000001234567891+ 010001456>', |
||
449 | $this->slipData->getCodeLine(false) |
||
450 | ); |
||
451 | |||
452 | $this->slipData->setWithBankingCustomerId(false); |
||
453 | |||
454 | // Filled with zeros |
||
455 | $this->assertEquals( |
||
456 | '0100002830509>000000000000000001234567894+ 010001456>', |
||
457 | $this->slipData->getCodeLine() |
||
458 | ); |
||
459 | // Not filled with zeros |
||
460 | $this->assertEquals( |
||
461 | '0100002830509>1234567894+ 010001456>', |
||
462 | $this->slipData->getCodeLine(false) |
||
463 | ); |
||
464 | |||
465 | $this->slipData->setAmount(0.0); |
||
466 | |||
467 | // Filled with zeros |
||
468 | $this->assertEquals( |
||
469 | '0100000000005>000000000000000001234567894+ 010001456>', |
||
470 | $this->slipData->getCodeLine() |
||
471 | ); |
||
472 | // Not filled with zeros |
||
473 | $this->assertEquals( |
||
474 | '0100000000005>1234567894+ 010001456>', |
||
475 | $this->slipData->getCodeLine(false) |
||
476 | ); |
||
477 | |||
478 | $this->slipData->setWithAmount(false); |
||
479 | |||
480 | // Filled with zeros |
||
481 | $this->assertEquals( |
||
482 | '042>000000000000000001234567894+ 010001456>', |
||
483 | $this->slipData->getCodeLine() |
||
484 | ); |
||
485 | // Not filled with zeros |
||
486 | $this->assertEquals( |
||
487 | '042>1234567894+ 010001456>', |
||
488 | $this->slipData->getCodeLine(false) |
||
489 | ); |
||
490 | } |
||
491 | |||
492 | /** |
||
493 | * Tests the setNotForPayment method |
||
494 | * |
||
495 | * @return void |
||
496 | * @covers ::setNotForPayment |
||
497 | * @covers ::appendCheckDigit |
||
498 | * @covers ::getCompleteReferenceNumber |
||
499 | * @covers ::getCodeLine |
||
500 | * @covers ::getAccountDigits |
||
501 | */ |
||
502 | public function testSetNotForPayment() |
||
514 | |||
515 | /** |
||
516 | * Tests the setNotForPayment method when fields are disabled |
||
517 | * |
||
518 | * @return void |
||
519 | * @covers ::setNotForPayment |
||
520 | */ |
||
521 | public function testSetNotForPaymentDisabledFields() |
||
528 | } |
||
529 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: