Skip to content

Commit

Permalink
Fix street house_number
Browse files Browse the repository at this point in the history
  • Loading branch information
tomas-novotny committed Jul 15, 2020
1 parent 6720610 commit 5af158c
Show file tree
Hide file tree
Showing 3 changed files with 112 additions and 7 deletions.
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
23 changes: 19 additions & 4 deletions src/Model/Values/Branch.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down
89 changes: 87 additions & 2 deletions tests/Unit/BranchTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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', [
Expand Down

0 comments on commit 5af158c

Please sign in to comment.