| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | declare(strict_types=1); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | namespace EcodevTests\Felix\Service; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | use Ecodev\Felix\Service\Bvr; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | use PHPUnit\Framework\TestCase; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  | final 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 static function providerGetReferenceNumber(): iterable | 
            
                                                                                                            
                            
            
                                    
            
            
                | 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 static function providerModulo10(): iterable | 
            
                                                                                                            
                            
            
                                    
            
            
                | 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 providerExtractCustomId | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |     public function testExtractCustomId(string $referenceNumber, string $expected): void | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  |         $actual = Bvr::extractCustomId($referenceNumber); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |         self::assertSame($expected, $actual); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  |     public static function providerExtractCustomId(): iterable | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  |         return [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  |             ['800826000000000000000002016', '00000000000000000201'], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  |             ['000000000000000000000000000', '00000000000000000000'], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  |             ['000000000000000000000001236', '00000000000000000123'], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  |         ]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 95 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 96 |  |  |     public function testExtractCustomIdMustThrowIfInvalidReferenceNumber(): void | 
            
                                                                        
                            
            
                                    
            
            
                | 97 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 98 |  |  |         $this->expectExceptionMessage('Invalid reference number. It must be exactly 27 digits, but got: `foo`'); | 
            
                                                                        
                            
            
                                    
            
            
                | 99 |  |  |         Bvr::extractCustomId('foo'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 |  |  |     public function testExtractCustomIdMustThrowIfInvalidVerificationDigit(): void | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 |  |  |         $this->expectExceptionMessage('Invalid reference number. The verification digit does not match. Expected `0`, but got `6`'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 |  |  |         Bvr::extractCustomId('800826000000000000000002010'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 106 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 107 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 108 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 109 |  |  |      * @dataProvider providerQrIban | 
            
                                                                                                            
                            
            
                                    
            
            
                | 110 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 111 |  |  |     public function testQrIban(string $iban, bool $expected): void | 
            
                                                                                                            
                            
            
                                    
            
            
                | 112 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 113 |  |  |         $actual = Bvr::isQrIban($iban); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 114 |  |  |         self::assertSame($expected, $actual); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 115 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 116 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 117 |  |  |     public static function providerQrIban(): iterable | 
            
                                                                                                            
                            
            
                                    
            
            
                | 118 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 119 |  |  |         return [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 120 |  |  |             ['30-12465-5', false], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 121 |  |  |             ['', false], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 122 |  |  |             ['CH2208390037471510005', false], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 123 |  |  |             ['CH7030123036078110002', true], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 124 |  |  |         ]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 125 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 126 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 127 |  |  |  |