1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace ApplicationTest\Service; |
6
|
|
|
|
7
|
|
|
use Application\Service\Bvr; |
8
|
|
|
use PHPUnit\Framework\TestCase; |
9
|
|
|
|
10
|
|
|
class BvrTest extends TestCase |
11
|
|
|
{ |
12
|
|
|
/** |
13
|
|
|
* @dataProvider providerGetReferenceNumber |
14
|
|
|
*/ |
15
|
|
|
public function testGetReferenceNumber(string $bankAccount, string $referenceNumber, string $expected): void |
16
|
|
|
{ |
17
|
|
|
$actual = Bvr::getReferenceNumber($bankAccount, $referenceNumber); |
18
|
|
|
self::assertSame($expected, $actual); |
19
|
|
|
} |
20
|
|
|
|
21
|
|
|
public function providerGetReferenceNumber() |
22
|
|
|
{ |
23
|
|
|
return [ |
24
|
|
|
['123456', '', '123456000000000000000000006'], |
25
|
|
|
['123456', '789', '123456000000000000000007891'], |
26
|
|
|
]; |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
public function testGetReferenceNumberMustThrowIfTooLongBankAccount(): void |
30
|
|
|
{ |
31
|
|
|
$this->expectExceptionMessage('Invalid bank account. It must be exactly 6 digits, but got: `1234567`'); |
32
|
|
|
Bvr::getReferenceNumber('1234567', '123'); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
public function testGetReferenceNumberMustThrowIfTooLongReferenceNumber(): void |
36
|
|
|
{ |
37
|
|
|
$this->expectExceptionMessage('Invalid custom ID. It must be 20 or less digits, but got: `000000000000000000000`'); |
38
|
|
|
Bvr::getReferenceNumber('123456', str_repeat('0', 21)); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
public function testGetReferenceNumberMustThrowIfInvalidReferenceNumber(): void |
42
|
|
|
{ |
43
|
|
|
$this->expectExceptionMessage('Invalid custom ID. It must be 20 or less digits, but got: `1.5`'); |
44
|
|
|
Bvr::getReferenceNumber('123456', '1.5'); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @dataProvider providerModulo10 |
49
|
|
|
*/ |
50
|
|
|
public function testModulo10(string $number, int $expected): void |
51
|
|
|
{ |
52
|
|
|
$actual = Bvr::modulo10($number); |
53
|
|
|
self::assertSame($expected, $actual); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
public function providerModulo10() |
57
|
|
|
{ |
58
|
|
|
return [ |
59
|
|
|
['', 0], |
60
|
|
|
['0', 0], |
61
|
|
|
['04', 2], |
62
|
|
|
['010000394975', 3], |
63
|
|
|
['313947143000901', 8], |
64
|
|
|
['80082600000000000000000201', 6], |
65
|
|
|
['80082600000000000000000001', 2], |
66
|
|
|
['80082600000000000000000002', 8], |
67
|
|
|
['80082600000000000000000003', 3], |
68
|
|
|
['80082600000000000000000004', 9], |
69
|
|
|
['80082600000000000000000005', 7], |
70
|
|
|
['80082600000000000000000006', 5], |
71
|
|
|
['80082600000000000000000007', 0], |
72
|
|
|
['80082600000000000000000008', 1], |
73
|
|
|
['80082600000000000000000009', 6], |
74
|
|
|
['80082600000000000000000010', 8], |
75
|
|
|
]; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* @dataProvider providerGetEncodingLine |
80
|
|
|
*/ |
81
|
|
|
public function testGetEncodingLine(string $bankAccount, string $referenceNumber, string $postalAccount, ?string $amount, string $expected): void |
82
|
|
|
{ |
83
|
|
|
$actual = Bvr::getEncodingLine($bankAccount, $referenceNumber, $postalAccount, $amount); |
84
|
|
|
self::assertSame($expected, $actual); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
public function providerGetEncodingLine() |
88
|
|
|
{ |
89
|
|
|
return [ |
90
|
|
|
['800826', '00000000000000000201', '01-4567-0', null, '042>800826000000000000000002016+ 010045670>'], |
91
|
|
|
['000000', '', '1-2-3', null, '042>000000000000000000000000000+ 010000023>'], |
92
|
|
|
['000000', '123', '01-4567-0', '1.45', '0100000001453>000000000000000000000001236+ 010045670>'], |
93
|
|
|
]; |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
public function testGetEncodingLineMustThrowIfTooLongReference(): void |
97
|
|
|
{ |
98
|
|
|
$this->expectExceptionMessage('Invalid custom ID. It must be 20 or less digits, but got: `000000000000000000000000000`'); |
99
|
|
|
Bvr::getEncodingLine('123456', str_repeat('0', 27), '01-4567-0'); |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
public function testGetEncodingLineMustThrowIfInvalidReference(): void |
103
|
|
|
{ |
104
|
|
|
$this->expectExceptionMessage('Invalid custom ID. It must be 20 or less digits, but got: `0.0`'); |
105
|
|
|
Bvr::getEncodingLine('123456', '0.0', '01-4567-0'); |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
public function testGetEncodingLineMustThrowIfInvalidPostAccount(): void |
109
|
|
|
{ |
110
|
|
|
$this->expectExceptionMessage('Invalid post account number'); |
111
|
|
|
Bvr::getEncodingLine('123456', '0', '0145670'); |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
public function testGetEncodingLineMustThrowIfTooLongPostAccount(): void |
115
|
|
|
{ |
116
|
|
|
$this->expectExceptionMessage('The post account number is too long'); |
117
|
|
|
Bvr::getEncodingLine('123456', '0', '0123-456789-0'); |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
public function testGetEncodingLineMustThrowIfInvalidAmount(): void |
121
|
|
|
{ |
122
|
|
|
$this->expectExceptionMessage('Invalid amount. Must be numeric, but got: `foo`'); |
123
|
|
|
Bvr::getEncodingLine('123456', '0', '01-4567-0', 'foo'); |
124
|
|
|
} |
125
|
|
|
} |
126
|
|
|
|