1
1
<?php
2
2
/**
3
- * Copyright © Magento, Inc. All rights reserved.
4
- * See COPYING.txt for license details .
3
+ * Copyright 2024 Adobe
4
+ * All Rights Reserved .
5
5
*/
6
6
declare (strict_types=1 );
7
7
@@ -31,17 +31,25 @@ protected function setUp(): void
31
31
'US ' => [
32
32
'pattern_1 ' => ['pattern ' => '^[0-9]{5}\-[0-9]{4}$ ' ],
33
33
'pattern_2 ' => ['pattern ' => '^[0-9]{5}$ ' ]
34
+ ],
35
+ 'NL ' => [
36
+ 'pattern_1 ' => ['pattern ' => '^[1-9][0-9]{3}\s?[a-zA-Z]{2}$ ' ],
37
+ 'pattern_2 ' => ['pattern ' => '^[1-9][0-9]{3}$ ' ]
34
38
]
35
39
];
36
40
$ this ->postcodesConfigMock ->expects ($ this ->once ())->method ('getPostCodes ' )->willReturn ($ postCodes );
37
41
$ this ->model = new Validator ($ this ->postcodesConfigMock );
38
42
}
39
43
40
- public function testValidatePositive ()
44
+ /**
45
+ * @param string $postCode
46
+ * @param string $countryId
47
+ * @return void
48
+ * @dataProvider getCountryPostcodes
49
+ */
50
+ public function testValidatePositive (string $ postCode , string $ countryId ): void
41
51
{
42
- $ postcode = '12345-6789 ' ;
43
- $ countryId = 'US ' ;
44
- $ this ->assertTrue ($ this ->model ->validate ($ postcode , $ countryId ));
52
+ $ this ->assertTrue ($ this ->model ->validate ($ postCode , $ countryId ));
45
53
}
46
54
47
55
public function testValidateNegative ()
@@ -59,4 +67,25 @@ public function testValidateThrowExceptionIfCountryDoesNotExist()
59
67
$ countryId = 'QQ ' ;
60
68
$ this ->assertFalse ($ this ->model ->validate ($ postcode , $ countryId ));
61
69
}
70
+
71
+ /**
72
+ * @return \string[][]
73
+ */
74
+ public static function getCountryPostcodes (): array
75
+ {
76
+ return [
77
+ [
78
+ 'postCode ' => '12345-6789 ' ,
79
+ 'countryId ' => 'US '
80
+ ],
81
+ [
82
+ 'postCode ' => '1234 ' ,
83
+ 'countryId ' => 'NL '
84
+ ],
85
+ [
86
+ 'postCode ' => '1234AB ' ,
87
+ 'countryId ' => 'NL '
88
+ ]
89
+ ];
90
+ }
62
91
}
0 commit comments