From 453c59079c9befcd38db066a7fdcae1ef7743a86 Mon Sep 17 00:00:00 2001 From: Joeri van Veen Date: Mon, 25 Mar 2024 15:16:04 +0100 Subject: [PATCH] feat: add international bbp (#476) --- src/Model/Account/CarrierOptions.php | 13 ++++ test/Model/Account/CarrierOptionsTest.php | 76 +++++++++++++++++++++++ 2 files changed, 89 insertions(+) create mode 100644 test/Model/Account/CarrierOptionsTest.php diff --git a/src/Model/Account/CarrierOptions.php b/src/Model/Account/CarrierOptions.php index 4669a4b9..1ce95fda 100644 --- a/src/Model/Account/CarrierOptions.php +++ b/src/Model/Account/CarrierOptions.php @@ -29,6 +29,10 @@ class CarrierOptions extends BaseModel * @var bool */ private $optional; + /** + * @var string + */ + private $type; /** * @param array $options @@ -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; } /** @@ -59,6 +64,14 @@ public function getLabel(): string return $this->label; } + /** + * @return string + */ + public function getType(): string + { + return $this->type; + } + /** * @return bool */ diff --git a/test/Model/Account/CarrierOptionsTest.php b/test/Model/Account/CarrierOptionsTest.php new file mode 100644 index 00000000..e77fb2d2 --- /dev/null +++ b/test/Model/Account/CarrierOptionsTest.php @@ -0,0 +1,76 @@ +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; + } + } +}