Skip to content

Commit

Permalink
feat: add carrier ups
Browse files Browse the repository at this point in the history
  • Loading branch information
wthijmen committed Nov 13, 2023
1 parent 5d13b20 commit c5590d6
Show file tree
Hide file tree
Showing 5 changed files with 168 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/Model/Carrier/CarrierFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ class CarrierFactory
CarrierPostNL::class,
CarrierDHLForYou::class,
CarrierDHLParcelConnect::class,
CarrierDHLEuroplus::class
CarrierDHLEuroplus::class,
CarrierUPS::class
];

/**
Expand Down
35 changes: 35 additions & 0 deletions src/Model/Carrier/CarrierUPS.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

declare(strict_types=1);

namespace MyParcelNL\Sdk\src\Model\Carrier;

use MyParcelNL\Sdk\src\Model\Consignment\UPSConsignment;

class CarrierUPS extends AbstractCarrier
{
public const CONSIGNMENT = UPSConsignment::class;
public const HUMAN = 'UPS';
public const ID = 8;
public const NAME = 'ups';

/**
* @var class-string
*/
protected $consignmentClass = self::CONSIGNMENT;

/**
* @var string
*/
protected $human = self::HUMAN;

/**
* @var int
*/
protected $id = self::ID;

/**
* @var string
*/
protected $name = self::NAME;
}
57 changes: 57 additions & 0 deletions src/Model/Consignment/UPSConsignment.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php

declare(strict_types=1);

namespace MyParcelNL\Sdk\src\Model\Consignment;

use MyParcelNL\Sdk\src\Model\Carrier\CarrierUPS;
use MyParcelNL\Sdk\src\Validator\Consignment\UPSConsignmentValidator;

class UPSConsignment extends AbstractConsignment
{
public const DEFAULT_WEIGHT = 3000;

/**
* @internal
* @var int
*/
public $physical_properties = ['weight' => self::DEFAULT_WEIGHT];

/**
* @var string
*/
protected $carrierClass = CarrierUPS::class;

/**
* @var string
*/
protected $validatorClass = UPSConsignmentValidator::class;

/**
* @return string
*/
public function getLocalCountryCode(): string
{
return self::CC_NL;
}

/**
* @return array|string[]
*/
public function getAllowedPackageTypes(): array
{
return [
self::PACKAGE_TYPE_PACKAGE,
];
}

/**
* @return array|string[]
*/
public function getAllowedDeliveryTypes(): array
{
return [
self::DELIVERY_TYPE_STANDARD,
];
}
}
23 changes: 23 additions & 0 deletions src/Validator/Consignment/UPSConsignmentValidator.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

Check notice on line 1 in src/Validator/Consignment/UPSConsignmentValidator.php

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

src/Validator/Consignment/UPSConsignmentValidator.php#L1

Missing required strict_types declaration

namespace MyParcelNL\Sdk\src\Validator\Consignment;

use MyParcelNL\Sdk\src\Rule\Consignment\DeliveryDateRule;
use MyParcelNL\Sdk\src\Rule\Consignment\MinimumWeightRule;
use MyParcelNL\Sdk\src\Rule\Consignment\ShipmentOptionsRule;
use MyParcelNL\Sdk\src\Validator\AbstractValidator;

class UPSConsignmentValidator extends AbstractValidator
{
/**
* @return \MyParcelNL\Sdk\src\Rule\Rule[]
*/
protected function getRules(): array
{
return [
new DeliveryDateRule(),
new MinimumWeightRule(),
new ShipmentOptionsRule(),
];
}
}
51 changes: 51 additions & 0 deletions test/Model/Consignment/UPSConsignmentTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php

declare(strict_types=1);

namespace MyParcelNL\Sdk\Test\Model\Consignment;

use MyParcelNL\Sdk\src\Model\Carrier\CarrierUPS;
use MyParcelNL\Sdk\Test\Bootstrap\ConsignmentTestCase;

class UPSConsignmentTest extends ConsignmentTestCase
{
/**
* @return array
* @throws \Exception
*/
public function provideUPSConsignmentsData(): array
{
return $this->createConsignmentProviderDataset([
]);
}

/**
* @param array $testData
*
* @throws \Exception
* @throws \Exception
* @dataProvider provideUPSConsignmentsData
*/
public function testUPSForYouConsignments(array $testData): void
{
$this->doConsignmentTest($testData);
}

/**
* @return array|string[]
* @throws \Exception
*/
protected function getDefaultConsignmentData(): array
{
return array_replace(
parent::getDefaultConsignmentData(),
[
self::CARRIER_ID => CarrierUPS::ID,
self::FULL_STREET => 'Meander 631',
self::POSTAL_CODE => '6825ME',
self::CITY => 'Arnhem',
self::PHONE => '123456',
]
);
}
}

0 comments on commit c5590d6

Please sign in to comment.