From 5af158c02d5284e4764a967179f377ec87fb6ab3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Novotn=C3=BD?= Date: Wed, 15 Jul 2020 14:58:35 +0200 Subject: [PATCH] Fix street house_number --- CHANGELOG.md | 7 ++- src/Model/Values/Branch.php | 23 ++++++++-- tests/Unit/BranchTest.php | 89 ++++++++++++++++++++++++++++++++++++- 3 files changed, 112 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c4d41d3..2d5ad0c 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,7 +6,12 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). -## [Unreleased](https://github.com/inspirum/balikobot-php/compare/v3.2.0...master) +## [Unreleased](https://github.com/inspirum/balikobot-php/compare/v3.2.1...master) + + +## [v3.2.1 (2020-07-15)](https://github.com/inspirum/balikobot-php/compare/v3.2.0...v3.2.1) +### Fixes +- Fixed branch street house/orientation number for **CP** shipper ## [v3.2.0 (2020-06-07)](https://github.com/inspirum/balikobot-php/compare/v3.1.0...v3.2.0) diff --git a/src/Model/Values/Branch.php b/src/Model/Values/Branch.php index acdd233..51ac86c 100644 --- a/src/Model/Values/Branch.php +++ b/src/Model/Values/Branch.php @@ -160,14 +160,14 @@ class Branch private $openingFriday; /** - * @var string|null null + * @var string|null */ - private $openingSaturday = null; + private $openingSaturday; /** - * @var string|null null + * @var string|null */ - private $openingSunday = null; + private $openingSunday; /** * Branch constructor @@ -580,6 +580,21 @@ public static function newInstanceFromData(string $shipper, ?string $service, ar $data['country'] = $data['country'] ?? 'CZ'; } + if (isset($data['street']) && (isset($data['house_number']) || isset($data['orientation_number']))) { + $houseNumber = (int) ($data['house_number'] ?? 0); + $orientationNumber = (int) ($data['orientation_number'] ?? 0); + $streetNumber = trim( + sprintf( + '%s/%s', + $houseNumber > 0 ? $houseNumber : '', + $orientationNumber > 0 ? $orientationNumber : '' + ), + '/' + ); + + $data['street'] = trim(sprintf('%s %s', $data['street'] ?: ($data['city'] ?? ''), $streetNumber)); + } + return new self( $shipper, $service, diff --git a/tests/Unit/BranchTest.php b/tests/Unit/BranchTest.php index 878f8c9..078cbb7 100644 --- a/tests/Unit/BranchTest.php +++ b/tests/Unit/BranchTest.php @@ -14,7 +14,7 @@ public function testStaticConstructor() 'type' => 'type', 'name' => 'name', 'city' => 'city', - 'street' => 'street', + 'street' => 'street 27/8', 'zip' => 'zip', 'country' => 'country', 'city_part' => 'city_part', @@ -47,7 +47,7 @@ public function testStaticConstructor() $this->assertEquals('type', $branch->getType()); $this->assertEquals('name', $branch->getName()); $this->assertEquals('city', $branch->getCity()); - $this->assertEquals('street', $branch->getStreet()); + $this->assertEquals('street 27/8', $branch->getStreet()); $this->assertEquals('zip', $branch->getZip()); $this->assertEquals('country', $branch->getCountry()); $this->assertEquals('city_part', $branch->getCityPart()); @@ -164,6 +164,91 @@ public function testStaticConstructorFallbackName() $this->assertEquals('address', $branch->getStreet()); } + public function testStaticConstructorStreetNumber() + { + $branch = Branch::newInstanceFromData('cp', 'NP', [ + 'zip' => 'zip', + 'street' => 'street', + 'house_number' => '8', + 'orientation_number' => '896', + ]); + + $this->assertEquals('street 8/896', $branch->getStreet()); + + $branch = Branch::newInstanceFromData('cp', 'NP', [ + 'zip' => 'zip', + 'street' => 'street', + 'house_number' => '8', + 'orientation_number' => '0', + ]); + + $this->assertEquals('street 8', $branch->getStreet()); + + $branch = Branch::newInstanceFromData('cp', 'NP', [ + 'zip' => 'zip', + 'street' => 'street', + 'orientation_number' => '897', + ]); + + $this->assertEquals('street 897', $branch->getStreet()); + + $branch = Branch::newInstanceFromData('cp', 'NP', [ + 'zip' => 'zip', + 'street' => 'street', + 'house_number' => '2', + ]); + + $this->assertEquals('street 2', $branch->getStreet()); + + $branch = Branch::newInstanceFromData('cp', 'NP', [ + 'zip' => 'zip', + 'street' => 'street 1', + 'house_number' => '2', + 'orientation_number' => '3', + ]); + + $this->assertEquals('street 1 2/3', $branch->getStreet()); + + $branch = Branch::newInstanceFromData('cp', 'NP', [ + 'zip' => 'zip', + 'address' => 'address', + 'house_number' => '2', + 'orientation_number' => '3', + ]); + + $this->assertEquals('address', $branch->getStreet()); + + $branch = Branch::newInstanceFromData('cp', 'NP', [ + 'zip' => 'zip', + 'street' => '', + 'house_number' => '3', + 'orientation_number' => '4', + ]); + + $this->assertEquals('3/4', $branch->getStreet()); + + $branch = Branch::newInstanceFromData('cp', 'NP', [ + 'zip' => 'zip', + 'city' => 'Vrbovec', + 'street' => '', + 'house_number' => '146', + 'orientation_number' => '0', + ]); + + $this->assertEquals('Vrbovec 146', $branch->getStreet()); + + $branch = Branch::newInstanceFromData('cp', 'NP', [ + 'zip' => 'zip', + 'city' => 'Vrbovec', + 'street' => '', + 'address' => 'address', + 'house_number' => '147', + 'orientation_number' => '0', + ]); + + $this->assertEquals('Vrbovec 147', $branch->getStreet()); + } + public function testBranchIdResolver() { $branch = Branch::newInstanceFromData('cp', 'NP', [