Skip to content

Commit

Permalink
feat: add international bbp (#476)
Browse files Browse the repository at this point in the history
  • Loading branch information
joerivanveen committed Mar 25, 2024
1 parent f59b647 commit 453c590
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/Model/Account/CarrierOptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ class CarrierOptions extends BaseModel
* @var bool
*/
private $optional;
/**
* @var string
*/
private $type;

/**
* @param array $options
Expand All @@ -41,6 +45,7 @@ public function __construct(array $options)
$this->optional = (bool) $options['optional'];
$this->carrier = CarrierFactory::create($options['carrier']['id']);
$this->label = $options['label'] ?? $this->carrier->getHuman();
$this->type = $options['type'] ?? $this->label;
}

/**
Expand All @@ -59,6 +64,14 @@ public function getLabel(): string
return $this->label;
}

/**
* @return string
*/
public function getType(): string
{
return $this->type;
}

/**
* @return bool
*/
Expand Down
76 changes: 76 additions & 0 deletions test/Model/Account/CarrierOptionsTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<?php

declare(strict_types=1);

namespace MyParcelNL\Sdk\Test\Model\Account;

use MyParcelNL\Sdk\src\Model\Account\CarrierOptions;
use MyParcelNL\Sdk\src\Model\Carrier\CarrierDPD;
use MyParcelNL\Sdk\src\Model\Carrier\CarrierPostNL;
use MyParcelNL\Sdk\Test\Bootstrap\TestCase;

class CarrierOptionsTest extends TestCase
{
public function testCarrierOptions(): void
{
foreach ($this->provideTestData() as $testData) {
$carrierOptions = new CarrierOptions($testData['options']);
$expected = $testData['expected'];

self::assertEquals($expected['enabled'], $carrierOptions->isEnabled());
self::assertEquals($expected['optional'], $carrierOptions->isOptional());
self::assertEquals($expected['type'], $carrierOptions->getType());
self::assertEquals($expected['label'], $carrierOptions->getLabel());
self::assertInstanceOf($expected['carrier'], $carrierOptions->getCarrier());
}
}

/**
* @return \Generator
*/
private function provideTestData()
{
$option_collections = [
['options' => [
'enabled' => true,
'optional' => true,
'carrier' => [
'id' => 1,
],
'label' => NULL,
'type' => 'main',
],
'expected' => [
'enabled' => true,
'optional' => true,
'carrier' => CarrierPostNL::class,
'label' => CarrierPostNL::HUMAN,
'type' => 'main',

]
],
['options' => [
'enabled' => false,
'optional' => false,
'carrier' => [
'id' => 4,
],
'label' => 'custom',
'type' => 'custom',
],
'expected' => [
'enabled' => false,
'optional' => false,
'carrier' => CarrierDPD::class,
'label' => 'custom',
'type' => 'custom',

]
],
];

foreach ($option_collections as $options) {
yield $options;
}
}
}

0 comments on commit 453c590

Please sign in to comment.