From 2997ac8a5aa58dbcd87201a74b2a5c01c5532daf Mon Sep 17 00:00:00 2001 From: Joeri van Veen Date: Thu, 8 Aug 2024 11:30:57 +0200 Subject: [PATCH] fix(splitstreet): ensure box separator for be address (#496) * fix(splitstreet): ensure box separator for be address * refactor: remove unused use classes --- src/Helper/ValidateStreet.php | 2 +- test/Model/Consignment/ConsignmentSplitStreetTest.php | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/Helper/ValidateStreet.php b/src/Helper/ValidateStreet.php index 8376e01d..9fef3f7a 100644 --- a/src/Helper/ValidateStreet.php +++ b/src/Helper/ValidateStreet.php @@ -25,7 +25,7 @@ class ValidateStreet ')?$~i'; const SPLIT_STREET_REGEX_BE = - '~(?P)(?P.*?)\s(?P(?P[0-9\-]{0,7}[0-9])(?P[A-z]{0,4})\s?(?P' . self::REGEX_BE_BOX_SEPARATORS . '|\,\s+)*\s?(?P[0-9A-z]{0,7}[0-9])?\s?(?:(?P[A-z]{1,4}$)|))?$~J'; + '~(?P)(?P)(?P.*?)\s(?P(?P[0-9\-]{0,7}[0-9])(?P[A-z]{0,4})\s?(?P' . self::REGEX_BE_BOX_SEPARATORS . '|\,\s+)*\s?(?P[0-9A-z]{0,7}[0-9])?\s?(?:(?P[A-z]{1,4}$)|))?$~J'; const REGEX_BE_BOX_SEPARATORS = SplitStreet::BOX_BTE . '|' . SplitStreet::BOX_EN . '|' . SplitStreet::BOX_FR . '|' . SplitStreet::BOX_NL . '|' . SplitStreet::BOX_DE . '|' . SplitStreet::BOX_SLASH . '|' . SplitStreet::BOX_DASH . '|' . SplitStreet::BOX_B . '.+'; /** * @param string $fullStreet diff --git a/test/Model/Consignment/ConsignmentSplitStreetTest.php b/test/Model/Consignment/ConsignmentSplitStreetTest.php index 1e10d7c2..6344fe2f 100644 --- a/test/Model/Consignment/ConsignmentSplitStreetTest.php +++ b/test/Model/Consignment/ConsignmentSplitStreetTest.php @@ -4,6 +4,7 @@ namespace MyParcelNL\Sdk\Test\Model\Consignment; +use MyParcelNL\Sdk\src\Helper\ValidateStreet; use MyParcelNL\Sdk\src\Model\Carrier\CarrierBpost; use MyParcelNL\Sdk\src\Model\Carrier\CarrierPostNL; use MyParcelNL\Sdk\src\Model\Consignment\AbstractConsignment; @@ -547,5 +548,11 @@ public function testSplitStreet(array $testData): void ], $consignment ); + + if (AbstractConsignment::CC_BE === $testData[self::COUNTRY]) { + $matches = []; + preg_match(ValidateStreet::SPLIT_STREET_REGEX_BE, $testData[self::FULL_STREET], $matches); + self::assertEquals(true, array_key_exists('box_separator', $matches)); + } } }