From 0ffbead5786b8119d71ce7e17fc82c3002803727 Mon Sep 17 00:00:00 2001 From: Edie Lemoine Date: Wed, 25 Sep 2024 12:27:46 +0200 Subject: [PATCH 01/12] refactor!: remove deprecated code BREAKING CHANGE: delete class \MyParcelNL\Pdk\Account\Repository\AbstractAccountRepository BREAKING CHANGE: delete class \MyParcelNL\Pdk\App\Api\PdkActions BREAKING CHANGE: delete class \MyParcelNL\Pdk\App\ShippingMethod\Repository\AbstractPdkShippingMethodRepository BREAKING CHANGE: delete class \MyParcelNL\Pdk\Settings\Repository\AbstractSettingsRepository BREAKING CHANGE: delete const \MyParcelNL\Pdk\Base\Contract\WeightServiceInterface::DIGITAL_STAMP_RANGES BREAKING CHANGE: delete interface \MyParcelNL\Pdk\Account\Contract\AccountRepositoryInterface BREAKING CHANGE: delete interface \MyParcelNL\Pdk\Settings\Contract\SettingsRepositoryInterface BREAKING CHANGE: delete method \MyParcelNL\Pdk\App\Installer\Contract\MigrationServiceInterface::all() BREAKING CHANGE: delete property \MyParcelNL\Pdk\Account\Model\Shop::$carrierOptions BREAKING CHANGE: delete property \MyParcelNL\Pdk\App\Order\Model\PdkOrder::$customsDeclaration BREAKING CHANGE: delete property \MyParcelNL\Pdk\App\Order\Model\PdkOrder::$orderLines BREAKING CHANGE: delete property \MyParcelNL\Pdk\App\Order\Model\PdkOrder::$orderNotes BREAKING CHANGE: delete property \MyParcelNL\Pdk\App\Order\Model\PdkOrder::$recipient BREAKING CHANGE: delete property \MyParcelNL\Pdk\App\ShippingMethod\Model\PdkShippingMethod::$allowPackageTypes BREAKING CHANGE: delete property \MyParcelNL\Pdk\App\ShippingMethod\Model\PdkShippingMethod::$allowPackageTypes BREAKING CHANGE: delete property \MyParcelNL\Pdk\Base\Model\Address::$fullStreet BREAKING CHANGE: delete property \MyParcelNL\Pdk\Base\Model\Address::$streetAdditionalInfo BREAKING CHANGE: delete property \MyParcelNL\Pdk\Carrier\Model\Carrier::$subscriptionId BREAKING CHANGE: delete trait \MyParcelNL\Pdk\Carrier\Concern\HasDeprecatedSubscriptionId BREAKING CHANGE: remove default implementation of getLogFiles in \MyParcelNL\Pdk\Logger\AbstractLogger BREAKING CHANGE: replace \Psr\Log\LoggerInterface with \MyParcelNL\Pdk\Logger\Contract\PdkLoggerInterface --- config/pdk-services.php | 19 -- config/pdk-template.php | 15 +- private/Types/Shared/Concern/UsesCache.php | 1 - .../Types/Shared/Service/PhpSourceParser.php | 1 - .../Contract/AccountRepositoryInterface.php | 15 -- src/Account/Model/Shop.php | 28 --- .../Repository/AbstractAccountRepository.php | 14 -- src/Api/Concern/DecodesAddressFields.php | 44 ++++ src/App/Api/PdkActions.php | 15 -- src/App/Api/PdkEndpoint.php | 13 +- .../Contract/MigrationServiceInterface.php | 10 +- .../Installer/Service/InstallerService.php | 25 +- .../Installer/Service/MigrationService.php | 13 +- src/App/Order/Model/PdkOrder.php | 19 +- .../Model/PdkShippingMethod.php | 4 - .../AbstractPdkShippingMethodRepository.php | 17 -- src/Base/Contract/WeightServiceInterface.php | 38 +-- src/Base/Model/Address.php | 60 +---- .../Concern/HasDeprecatedSubscriptionId.php | 17 -- src/Carrier/Model/Carrier.php | 8 - src/Frontend/View/AbstractSettingsView.php | 1 - src/Fulfilment/Model/Order.php | 6 +- src/Fulfilment/Model/OrderLine.php | 16 ++ src/Fulfilment/Model/Shipment.php | 4 +- src/Fulfilment/Model/ShipmentOptions.php | 5 +- src/Fulfilment/Repository/OrderRepository.php | 2 +- src/Fulfilment/Response/GetOrdersResponse.php | 29 ++- .../Response/PostOrdersResponse.php | 25 +- src/Logger/AbstractLogger.php | 10 - .../Contract/SettingsRepositoryInterface.php | 11 - .../Repository/AbstractSettingsRepository.php | 11 - .../Response/GetShipmentsResponse.php | 17 +- .../Bootstrap/MockLegacyMigrationService.php | 22 -- tests/Bootstrap/MockLogger.php | 3 - tests/Bootstrap/MockPdkConfig.php | 7 +- tests/Integration/Context/AbstractContext.php | 4 +- .../Service/InstallerServiceLegacyTest.php | 235 ------------------ .../Service/InstallerServiceTest.php | 4 +- .../Unit/App/Webhook/Hook/ShopWebhookTest.php | 6 +- tests/Unit/Base/Concern/HasAttributesTest.php | 5 +- tests/Unit/Base/Model/AddressTest.php | 67 ----- .../Unit/Base/Model/ModelDeprecationTest.php | 4 +- tests/Unit/Base/PdkEndpointTest.php | 4 +- tests/Unit/Base/Support/UtilsTest.php | 1 - tests/Unit/Fulfilment/Model/OrderTest.php | 161 +++++------- tests/Uses/UsesMockEachLogger.php | 4 +- ...heck__data_set_carrier_dhl_for_you__1.json | 4 +- ...t_age_check__data_set_single_order__1.json | 4 +- ..._data_set_various_delivery_options__1.json | 12 +- ...ance__data_set_carrier_dhl_for_you__1.json | 4 +- ...t_insurance__data_set_single_order__1.json | 4 +- ..._data_set_various_delivery_options__1.json | 12 +- ...rmat__data_set_carrier_dhl_for_you__1.json | 4 +- ...arge_format__data_set_single_order__1.json | 4 +- ..._data_set_various_delivery_options__1.json | 12 +- ...ient__data_set_carrier_dhl_for_you__1.json | 4 +- ...y_recipient__data_set_single_order__1.json | 4 +- ..._data_set_various_delivery_options__1.json | 12 +- ...turn__data_set_carrier_dhl_for_you__1.json | 4 +- ...port_return__data_set_single_order__1.json | 4 +- ..._data_set_various_delivery_options__1.json | 12 +- ...ture__data_set_carrier_dhl_for_you__1.json | 4 +- ...t_signature__data_set_single_order__1.json | 4 +- ..._data_set_various_delivery_options__1.json | 12 +- ...rts_return_with_data_set_insurance__1.json | 12 +- ...th_data_set_no_return_capabilities__1.json | 12 +- ...return_with_data_set_simple_orders__1.json | 24 +- ...der_with_data_set_order_to_germany__1.json | 96 +++++++ ..._data_set_order_to_pickup_location__1.json | 106 ++++++++ ...ta_set_order_with_delivery_options__1.json | 96 +++++++ ...k_order_with_data_set_simple_order__1.json | 96 +++++++ ...e_order_containing_many_attributes__1.json | 25 +- ...ith_data_set_one_order_with_pickup__1.json | 25 +- ...order_collection_from_queried_data__1.json | 2 +- ...t_order_containing_many_attributes__1.json | 25 +- ...ta_with_data_set_order_with_pickup__1.json | 25 +- ...tes_order_with_data_set_BE_mailbox__1.json | 12 +- ...der_with_data_set_BE_small_package__1.json | 7 + ..._EU_package_with_correct_insurance__1.json | 23 +- ...data_set_EU_package_with_no_weight__1.json | 23 +- ...a_set_EU_package_without_insurance__1.json | 7 + ...es_order_with_data_set_ROW_package__1.json | 39 +-- ...ge_without_weight,_without_invoice__1.json | 42 +--- ...a_set_Small_packets_not_NL_tracked__1.json | 11 +- ...h_data_set_allows_property_tracked__1.json | 7 + ..._with_data_set_dhlforyou_to_France__1.json | 7 + ..._set_mailbox_with_morning_delivery__1.json | 12 +- ...a_set_mailbox_with_shipmentOptions__1.json | 11 +- ...et_morning_delivery_with_age_check__1.json | 7 +- ...a_set_pickup_without_location_code__1.json | 31 ++- ..._set_pickup_without_pickupLocation__1.json | 7 +- ...non-standard_delivery_without_date__1.json | 7 +- ..._set_postnl_with_same_day_delivery__1.json | 15 +- ...order_with_data_set_weight_of_25kg__1.json | 7 + ...t_weight_of_29kg_with_large_format__1.json | 7 + .../App/Order/Model/PdkOrderLineFactory.php | 31 ++- .../App/Order/Model/PdkProductFactory.php | 46 +++- .../App/Order/Model/UsesCurrency.php | 68 +++++ .../Model/ProductDataContextFactory.php | 14 +- .../Shipment/Model/ShipmentFactory.php | 11 +- 100 files changed, 963 insertions(+), 1193 deletions(-) delete mode 100644 src/Account/Contract/AccountRepositoryInterface.php delete mode 100644 src/Account/Repository/AbstractAccountRepository.php create mode 100644 src/Api/Concern/DecodesAddressFields.php delete mode 100644 src/App/Api/PdkActions.php delete mode 100644 src/App/ShippingMethod/Repository/AbstractPdkShippingMethodRepository.php delete mode 100644 src/Carrier/Concern/HasDeprecatedSubscriptionId.php delete mode 100644 src/Settings/Contract/SettingsRepositoryInterface.php delete mode 100644 src/Settings/Repository/AbstractSettingsRepository.php delete mode 100644 tests/Bootstrap/MockLegacyMigrationService.php delete mode 100644 tests/Unit/App/Installer/Service/InstallerServiceLegacyTest.php delete mode 100644 tests/Unit/Base/Model/AddressTest.php create mode 100644 tests/__snapshots__/OrderTest__it_creates_fulfilment_order_from_pdk_order_with_data_set_order_to_germany__1.json create mode 100644 tests/__snapshots__/OrderTest__it_creates_fulfilment_order_from_pdk_order_with_data_set_order_to_pickup_location__1.json create mode 100644 tests/__snapshots__/OrderTest__it_creates_fulfilment_order_from_pdk_order_with_data_set_order_with_delivery_options__1.json create mode 100644 tests/__snapshots__/OrderTest__it_creates_fulfilment_order_from_pdk_order_with_data_set_simple_order__1.json create mode 100644 tests/__snapshots__/ValidationTest__it_validates_order_with_data_set_BE_small_package__1.json create mode 100644 tests/__snapshots__/ValidationTest__it_validates_order_with_data_set_EU_package_without_insurance__1.json create mode 100644 tests/__snapshots__/ValidationTest__it_validates_order_with_data_set_allows_property_tracked__1.json create mode 100644 tests/__snapshots__/ValidationTest__it_validates_order_with_data_set_dhlforyou_to_France__1.json create mode 100644 tests/__snapshots__/ValidationTest__it_validates_order_with_data_set_weight_of_25kg__1.json create mode 100644 tests/__snapshots__/ValidationTest__it_validates_order_with_data_set_weight_of_29kg_with_large_format__1.json create mode 100644 tests/factories/App/Order/Model/UsesCurrency.php diff --git a/config/pdk-services.php b/config/pdk-services.php index 379f53311..d2ac64f04 100644 --- a/config/pdk-services.php +++ b/config/pdk-services.php @@ -2,12 +2,10 @@ declare(strict_types=1); -use MyParcelNL\Pdk\Account\Contract\AccountRepositoryInterface; use MyParcelNL\Pdk\Account\Contract\AccountSettingsServiceInterface; use MyParcelNL\Pdk\Account\Service\AccountSettingsService; use MyParcelNL\Pdk\Api\Contract\ApiServiceInterface; use MyParcelNL\Pdk\Api\Service\MyParcelApiService; -use MyParcelNL\Pdk\App\Account\Contract\PdkAccountRepositoryInterface; use MyParcelNL\Pdk\App\Api\Contract\PdkActionsServiceInterface; use MyParcelNL\Pdk\App\Api\Service\PdkActionsService; use MyParcelNL\Pdk\App\Cart\Contract\CartCalculationServiceInterface; @@ -52,9 +50,7 @@ use MyParcelNL\Pdk\Notification\Service\NotificationService; use MyParcelNL\Pdk\Platform\PlatformManager; use MyParcelNL\Pdk\Platform\PlatformManagerInterface; -use MyParcelNL\Pdk\Settings\Contract\PdkSettingsRepositoryInterface; use MyParcelNL\Pdk\Settings\Contract\SettingsManagerInterface; -use MyParcelNL\Pdk\Settings\Contract\SettingsRepositoryInterface; use MyParcelNL\Pdk\Settings\SettingsManager; use MyParcelNL\Pdk\Shipment\Contract\DropOffServiceInterface; use MyParcelNL\Pdk\Shipment\Service\DropOffService; @@ -63,7 +59,6 @@ use MyParcelNL\Pdk\Types\Contract\TriStateServiceInterface; use MyParcelNL\Pdk\Types\Service\TriStateService; use function DI\autowire; -use function DI\factory; /** * Pre-defined services. @@ -189,20 +184,6 @@ */ TriStateServiceInterface::class => autowire(TriStateService::class), - /** - * @todo remove in v3.0.0 - */ - PdkAccountRepositoryInterface::class => factory(function () { - return \MyParcelNL\Pdk\Facade\Pdk::get(AccountRepositoryInterface::class); - }), - - /** - * @todo remove in v3.0.0 - */ - PdkSettingsRepositoryInterface::class => factory(function () { - return \MyParcelNL\Pdk\Facade\Pdk::get(SettingsRepositoryInterface::class); - }), - /** * Handles executing pdk actions. */ diff --git a/config/pdk-template.php b/config/pdk-template.php index 4759ec741..12f5cfd2a 100644 --- a/config/pdk-template.php +++ b/config/pdk-template.php @@ -17,9 +17,7 @@ use MyParcelNL\Pdk\Language\Contract\LanguageServiceInterface; use MyParcelNL\Pdk\Logger\Contract\PdkLoggerInterface; use MyParcelNL\Pdk\Settings\Contract\PdkSettingsRepositoryInterface; -use Psr\Log\LoggerInterface; use function DI\autowire; -use function DI\get; use function DI\value; /** @@ -137,18 +135,9 @@ /** * Handles logging. * - * @see \MyParcelNL\Pdk\Logger\AbstractLogger - * @deprecated Will be removed in v3.0.0. Use PdkLoggerInterface instead. + * @see \MyParcelNL\Pdk\Logger\AbstractLogger */ - - LoggerInterface::class => autowire(), - - /** - * Handles logging. - * - * @see \MyParcelNL\Pdk\Logger\AbstractLogger - */ - PdkLoggerInterface::class => get(LoggerInterface::class), + PdkLoggerInterface::class => autowire(), /** * Exposes frontend api url and endpoints. diff --git a/private/Types/Shared/Concern/UsesCache.php b/private/Types/Shared/Concern/UsesCache.php index 82700a5c0..54ea2bce5 100644 --- a/private/Types/Shared/Concern/UsesCache.php +++ b/private/Types/Shared/Concern/UsesCache.php @@ -10,7 +10,6 @@ use MyParcelNL\Pdk\Console\Storage\Contract\ConsoleStorageInterface; use MyParcelNL\Pdk\Facade\Pdk; use MyParcelNL\Sdk\src\Support\Str; -use function sprintf; trait UsesCache { diff --git a/private/Types/Shared/Service/PhpSourceParser.php b/private/Types/Shared/Service/PhpSourceParser.php index 02929f4a3..2d1778942 100644 --- a/private/Types/Shared/Service/PhpSourceParser.php +++ b/private/Types/Shared/Service/PhpSourceParser.php @@ -20,7 +20,6 @@ use ReflectionClass; use ReflectionMethod; use Symfony\Component\PropertyInfo\Extractor\ReflectionExtractor; -use function array_map; final class PhpSourceParser { diff --git a/src/Account/Contract/AccountRepositoryInterface.php b/src/Account/Contract/AccountRepositoryInterface.php deleted file mode 100644 index 0f73197ae..000000000 --- a/src/Account/Contract/AccountRepositoryInterface.php +++ /dev/null @@ -1,15 +0,0 @@ - null, 'accountId' => null, @@ -63,31 +60,6 @@ class Shop extends Model 'carrierConfigurations' => ShopCarrierConfigurationCollection::class, ]; - protected $deprecated = [ - self::DEPRECATED_KEY_CARRIER_OPTIONS => 'carriers', - ]; - - /** - * @param null|array $data - */ - public function __construct(?array $data = null) - { - if (isset($data[self::DEPRECATED_KEY_CARRIER_OPTIONS])) { - $data['carriers'] = array_map( - static function (array $carrierOptions): array { - $rest = Arr::except($carrierOptions, ['carrier']); - - return array_merge($rest, $carrierOptions['carrier'] ?? null); - }, - $data[self::DEPRECATED_KEY_CARRIER_OPTIONS] - ); - - unset($data[self::DEPRECATED_KEY_CARRIER_OPTIONS]); - } - - parent::__construct($data); - } - /** * @return array */ diff --git a/src/Account/Repository/AbstractAccountRepository.php b/src/Account/Repository/AbstractAccountRepository.php deleted file mode 100644 index 191242f57..000000000 --- a/src/Account/Repository/AbstractAccountRepository.php +++ /dev/null @@ -1,14 +0,0 @@ -filter($input) ?? []); + + if (isset($data['street']) || isset($data['number'])) { + $data['address1'] = trim( + implode(' ', [ + $data['street'], + $data['number'], + $data['numberSuffix'] ?? $data['boxNumber'] ?? '', + ]) + ); + + unset($data['street'], $data['number'], $data['numberSuffix'], $data['boxNumber']); + } + + return $data; + } + + /** + * @param null|array $item + * + * @return null|array + */ + protected function filter(?array $item): ?array + { + return array_filter($item ?? []) ?: null; + } +} diff --git a/src/App/Api/PdkActions.php b/src/App/Api/PdkActions.php deleted file mode 100644 index a2f0b4710..000000000 --- a/src/App/Api/PdkActions.php +++ /dev/null @@ -1,15 +0,0 @@ -actions = $actions; + $this->actionsService = $actions; } /** @@ -46,7 +47,7 @@ public function __construct(PdkActions $actions) public function call($input, string $context): Response { try { - return $this->actions + return $this->actionsService ->setContext($context) ->execute($input); } catch (ApiException $e) { diff --git a/src/App/Installer/Contract/MigrationServiceInterface.php b/src/App/Installer/Contract/MigrationServiceInterface.php index e1b6251c0..25bebe27b 100644 --- a/src/App/Installer/Contract/MigrationServiceInterface.php +++ b/src/App/Installer/Contract/MigrationServiceInterface.php @@ -8,12 +8,4 @@ * @method array getUpgradeMigrations() * @method array getInstallationMigrations() */ -interface MigrationServiceInterface -{ - /** - * @return class-string<\MyParcelNL\Pdk\App\Installer\Contract\MigrationInterface>[] - * @deprecated Will be removed in v3.0.0. Implement getUpgradeMigrations() and getInstallationMigrations() instead - * @todo remove in v3.0.0 - */ - public function all(): array; -} +interface MigrationServiceInterface { } diff --git a/src/App/Installer/Service/InstallerService.php b/src/App/Installer/Service/InstallerService.php index 485d8ea0b..012b93917 100644 --- a/src/App/Installer/Service/InstallerService.php +++ b/src/App/Installer/Service/InstallerService.php @@ -179,19 +179,9 @@ private function createMigrationCollection(array $migrations): Collection /** * @return \MyParcelNL\Pdk\Base\Support\Collection<\MyParcelNL\Pdk\App\Installer\Contract\InstallationMigrationInterface> - * @todo v3.0.0 remove legacy support */ private function getInstallationMigrations(): Collection { - if (! method_exists($this->migrationService, 'getInstallationMigrations')) { - Logger::deprecated( - sprintf('Method "%s::all()"', MigrationServiceInterface::class), - 'getUpgradeMigrations and getInstallationMigrations' - ); - - return new Collection(); - } - return $this->createMigrationCollection($this->migrationService->getInstallationMigrations()); } @@ -199,23 +189,10 @@ private function getInstallationMigrations(): Collection * @param null|string $version * * @return \MyParcelNL\Pdk\Base\Support\Collection<\MyParcelNL\Pdk\App\Installer\Contract\UpgradeMigrationInterface> - * @todo v3.0.0 remove legacy support */ private function getUpgradeMigrations(?string $version = null): Collection { - $useLegacy = ! method_exists($this->migrationService, 'getUpgradeMigrations'); - - if ($useLegacy) { - Logger::deprecated( - sprintf('Method "%s::all()"', MigrationServiceInterface::class), - 'getUpgradeMigrations and getInstallationMigrations' - ); - } - - $migrations = $useLegacy - ? $this->migrationService->all() - : $this->migrationService->getUpgradeMigrations(); - + $migrations = $this->migrationService->getUpgradeMigrations(); $collection = $this->createMigrationCollection($migrations); if (! $version) { diff --git a/src/App/Installer/Service/MigrationService.php b/src/App/Installer/Service/MigrationService.php index 79b0724a0..9358f8c3b 100644 --- a/src/App/Installer/Service/MigrationService.php +++ b/src/App/Installer/Service/MigrationService.php @@ -6,15 +6,4 @@ use MyParcelNL\Pdk\App\Installer\Contract\MigrationServiceInterface; -class MigrationService implements MigrationServiceInterface -{ - /** - * @return class-string<\MyParcelNL\Pdk\App\Installer\Contract\MigrationInterface>[] - * @deprecated use getUpgradeMigrations() instead - * @todo remove in v3.0.0 - */ - public function all(): array - { - return []; - } -} +class MigrationService implements MigrationServiceInterface { } diff --git a/src/App/Order/Model/PdkOrder.php b/src/App/Order/Model/PdkOrder.php index 55318eadd..72ca2e5dd 100644 --- a/src/App/Order/Model/PdkOrder.php +++ b/src/App/Order/Model/PdkOrder.php @@ -62,18 +62,15 @@ class PdkOrder extends Model 'deliveryOptions' => DeliveryOptions::class, - 'senderAddress' => null, - 'billingAddress' => null, - 'shippingAddress' => ShippingAddress::class, + 'senderAddress' => null, + 'billingAddress' => null, + 'shippingAddress' => ShippingAddress::class, /** * Order shipments. Applicable when NOT using order mode. */ - 'shipments' => ShipmentCollection::class, + 'shipments' => ShipmentCollection::class, - /** - * @deprecated Do not use, will be generated automatically. Will be removed in v3.0.0 - */ 'customsDeclaration' => null, 'physicalProperties' => PdkPhysicalProperties::class, @@ -135,14 +132,6 @@ class PdkOrder extends Model 'totalPriceAfterVat' => 'int', ]; - // TODO: v3.0.0 stop supporting deprecated attributes - protected $deprecated = [ - 'orderLines' => 'lines', - 'orderNotes' => 'notes', - 'recipient' => 'shippingAddress', - 'sender' => 'senderAddress', - ]; - /** * @var null|\MyParcelNL\Pdk\Validation\Validator\OrderValidator */ diff --git a/src/App/ShippingMethod/Model/PdkShippingMethod.php b/src/App/ShippingMethod/Model/PdkShippingMethod.php index b2291e650..b5683a0b6 100644 --- a/src/App/ShippingMethod/Model/PdkShippingMethod.php +++ b/src/App/ShippingMethod/Model/PdkShippingMethod.php @@ -41,8 +41,4 @@ class PdkShippingMethod extends Model 'minimumDropOffDelay' => 'int', 'shippingAddress' => Address::class, ]; - - protected $deprecated = [ - 'allowPackageTypes' => 'allowedPackageTypes', - ]; } diff --git a/src/App/ShippingMethod/Repository/AbstractPdkShippingMethodRepository.php b/src/App/ShippingMethod/Repository/AbstractPdkShippingMethodRepository.php deleted file mode 100644 index 8cb6d8918..000000000 --- a/src/App/ShippingMethod/Repository/AbstractPdkShippingMethodRepository.php +++ /dev/null @@ -1,17 +0,0 @@ - 0, - 'max' => 20, - 'average' => 15, - ], - [ - 'min' => 20, - 'max' => 50, - 'average' => 35, - ], - [ - 'min' => 50, - 'max' => 100, - 'average' => 75, - ], - [ - 'min' => 100, - 'max' => 350, - 'average' => 225, - ], - [ - 'min' => 350, - 'max' => 2000, - 'average' => 1175, - ], - ]; - public const UNIT_GRAMS = 'g'; - public const UNIT_KILOGRAMS = 'kg'; - public const UNIT_OUNCES = 'oz'; - public const UNIT_POUNDS = 'lbs'; + public const UNIT_GRAMS = 'g'; + public const UNIT_KILOGRAMS = 'kg'; + public const UNIT_OUNCES = 'oz'; + public const UNIT_POUNDS = 'lbs'; /** * @param int $weight diff --git a/src/Base/Model/Address.php b/src/Base/Model/Address.php index bd5932c04..e8aa79282 100644 --- a/src/Base/Model/Address.php +++ b/src/Base/Model/Address.php @@ -18,11 +18,6 @@ */ class Address extends Model { - private const FIELD_STREET = 'street'; - private const FIELD_NUMBER = 'number'; - private const FIELD_NUMBER_SUFFIX = 'numberSuffix'; - private const FIELD_BOX_NUMBER = 'boxNumber'; - protected $attributes = [ 'address1' => null, 'address2' => null, @@ -45,66 +40,13 @@ class Address extends Model 'state' => 'string', ]; - protected $deprecated = [ - 'fullStreet' => 'address1', - 'streetAdditionalInfo' => 'address2', - ]; - - /** - * Deprecated fields that can't be mapped to a new field 1 on 1. - * - * @var string[] - */ - private $additionalDeprecated = [ - self::FIELD_STREET, - self::FIELD_NUMBER, - self::FIELD_NUMBER_SUFFIX, - self::FIELD_BOX_NUMBER, - ]; - /** * @param null|array $data */ public function __construct(?array $data = null) { - $convertedData = $data ? $this->handleDeprecatedFields(Utils::changeArrayKeysCase($data)) : $data; + $convertedData = $data ? Utils::changeArrayKeysCase($data) : $data; parent::__construct($convertedData); } - - /** - * @param null|array $data - * - * @return null|array - */ - private function handleDeprecatedFields(?array $data): ?array - { - // if street, number, and optionally (number_suffix or box_number) are set, combine them into address1 - if (isset($data[self::FIELD_STREET], $data[self::FIELD_NUMBER])) { - $data['address1'] = trim( - implode(' ', [ - $data[self::FIELD_STREET], - $data[self::FIELD_NUMBER], - $data[self::FIELD_NUMBER_SUFFIX] ?? $data[self::FIELD_BOX_NUMBER] ?? '', - ]) - ); - - foreach ($this->additionalDeprecated as $field) { - unset($data[$field]); - } - - $this->logDeprecationWarning( - sprintf( - '%s, %s, and optionally %s or %s', - self::FIELD_STREET, - self::FIELD_NUMBER, - self::FIELD_NUMBER_SUFFIX, - self::FIELD_BOX_NUMBER - ), - 'address1' - ); - } - - return $data; - } } diff --git a/src/Carrier/Concern/HasDeprecatedSubscriptionId.php b/src/Carrier/Concern/HasDeprecatedSubscriptionId.php deleted file mode 100644 index 05a8ffdae..000000000 --- a/src/Carrier/Concern/HasDeprecatedSubscriptionId.php +++ /dev/null @@ -1,17 +0,0 @@ - CarrierCapabilities::class, ]; - /** - * @todo remove in v3.0.0 - */ - protected $deprecated = [ - 'subscriptionId' => 'contractId', - ]; - /** * @param null|array $data */ diff --git a/src/Frontend/View/AbstractSettingsView.php b/src/Frontend/View/AbstractSettingsView.php index e3fc3c769..05b652677 100644 --- a/src/Frontend/View/AbstractSettingsView.php +++ b/src/Frontend/View/AbstractSettingsView.php @@ -16,7 +16,6 @@ use MyParcelNL\Pdk\Settings\Model\Settings; use MyParcelNL\Pdk\Shipment\Model\DeliveryOptions; use MyParcelNL\Sdk\src\Support\Str; -use function array_map; /** * @deprecated use NewAbstractSettingsView instead diff --git a/src/Fulfilment/Model/Order.php b/src/Fulfilment/Model/Order.php index b8f35099c..383bf79c7 100644 --- a/src/Fulfilment/Model/Order.php +++ b/src/Fulfilment/Model/Order.php @@ -112,11 +112,7 @@ public static function fromPdkOrder(?PdkOrder $pdkOrder): self 'referenceIdentifier' => $pdkOrder->referenceIdentifier, 'lines' => $pdkOrder->lines ->map(function (PdkOrderLine $pdkOrderLine) { - return new OrderLine( - [ - 'product' => Product::fromPdkProduct($pdkOrderLine->product), - ] + $pdkOrderLine->toSnakeCaseArray() - ); + return OrderLine::fromPdkOrderLine($pdkOrderLine); }) ->all(), 'notes' => $pdkOrder->notes, diff --git a/src/Fulfilment/Model/OrderLine.php b/src/Fulfilment/Model/OrderLine.php index c98a77d33..d87c6b8cf 100644 --- a/src/Fulfilment/Model/OrderLine.php +++ b/src/Fulfilment/Model/OrderLine.php @@ -5,6 +5,7 @@ namespace MyParcelNL\Pdk\Fulfilment\Model; +use MyParcelNL\Pdk\App\Order\Model\PdkOrderLine; use MyParcelNL\Pdk\Base\Concern\HasPrices; use MyParcelNL\Pdk\Base\Model\Model; @@ -65,4 +66,19 @@ public function __construct(?array $data = null) parent::__construct($data); $this->calculateVatTotals(); } + + /** + * @param \MyParcelNL\Pdk\App\Order\Model\PdkOrderLine $pdkOrderLine + * + * @return self + */ + public static function fromPdkOrderLine(PdkOrderLine $pdkOrderLine): self + { + $data = array_replace( + $pdkOrderLine->toArray(), + ['product' => Product::fromPdkProduct($pdkOrderLine->product)] + ); + + return new static($data); + } } diff --git a/src/Fulfilment/Model/Shipment.php b/src/Fulfilment/Model/Shipment.php index 1a8fff1ca..c1b78f362 100644 --- a/src/Fulfilment/Model/Shipment.php +++ b/src/Fulfilment/Model/Shipment.php @@ -66,10 +66,10 @@ public function __construct(?array $data = null) public static function fromPdkShipment(?PdkShipment $pdkShipment): self { if (! $pdkShipment) { - return new self(); + return new static(); } - return new self([ + return new static([ 'orderId' => $pdkShipment->orderId, 'carrier' => $pdkShipment->carrier->id, 'contractId' => $pdkShipment->carrier->contractId, diff --git a/src/Fulfilment/Model/ShipmentOptions.php b/src/Fulfilment/Model/ShipmentOptions.php index 0c12c546b..8f1660ed1 100644 --- a/src/Fulfilment/Model/ShipmentOptions.php +++ b/src/Fulfilment/Model/ShipmentOptions.php @@ -89,8 +89,9 @@ public static function fromPdkDeliveryOptions(?DeliveryOptions $pdkDeliveryOptio array_replace($calculated->deliveryOptions->shipmentOptions->getAttributes(), [ 'packageType' => $pdkDeliveryOptions->getPackageTypeId(), 'deliveryType' => $pdkDeliveryOptions->getDeliveryTypeId(), - 'deliveryDate' => $pdkDeliveryOptions->date ? $pdkDeliveryOptions->date - ->format(Pdk::get('defaultDateFormat')) : null, + 'deliveryDate' => $pdkDeliveryOptions->date + ? $pdkDeliveryOptions->date->format(Pdk::get('defaultDateFormat')) + : null, ]) ); } diff --git a/src/Fulfilment/Repository/OrderRepository.php b/src/Fulfilment/Repository/OrderRepository.php index d0347d5f2..c0640577e 100644 --- a/src/Fulfilment/Repository/OrderRepository.php +++ b/src/Fulfilment/Repository/OrderRepository.php @@ -44,7 +44,7 @@ public function postOrders(OrderCollection $collection): OrderCollection /** @var \MyParcelNL\Pdk\Fulfilment\Response\PostOrdersResponse $response */ $response = $this->api->doRequest(new PostOrdersRequest($collection), PostOrdersResponse::class); - return $response->getOrderCollection(); + return $response->getOrders(); } /** diff --git a/src/Fulfilment/Response/GetOrdersResponse.php b/src/Fulfilment/Response/GetOrdersResponse.php index d0e584abd..38a9141c5 100644 --- a/src/Fulfilment/Response/GetOrdersResponse.php +++ b/src/Fulfilment/Response/GetOrdersResponse.php @@ -4,11 +4,16 @@ namespace MyParcelNL\Pdk\Fulfilment\Response; +use MyParcelNL\Pdk\Api\Concern\DecodesAddressFields; use MyParcelNL\Pdk\Api\Response\ApiResponseWithBody; +use MyParcelNL\Pdk\Base\Contract\Arrayable; +use MyParcelNL\Pdk\Base\Support\Utils; use MyParcelNL\Pdk\Fulfilment\Collection\OrderCollection; class GetOrdersResponse extends ApiResponseWithBody { + use DecodesAddressFields; + /** * @var \MyParcelNL\Pdk\Fulfilment\Collection\OrderCollection */ @@ -43,7 +48,7 @@ protected function parseResponseBody(): void private function createOrders(array $orders): void { $this->orders = new OrderCollection( - array_map(static function (array $order) { + array_map(function (array $order) { return [ 'uuid' => $order['uuid'], 'shopId' => $order['shop_id'], @@ -57,13 +62,31 @@ private function createOrders(array $orders): void 'price' => $order['price'], 'vat' => $order['vat'], 'priceAfterVat' => $order['price_after_vat'], - 'invoiceAddress' => $order['invoice_address'], + 'invoiceAddress' => $this->decodeAddress($order['invoice_address']), 'lines' => $order['order_lines'] ?? [], - 'shipment' => $order['shipment'] ?? [], + 'shipment' => $this->decodeShipment($order['shipment'] ?? []), 'createdAt' => $order['created_at'], 'updatedAt' => $order['updated_at'], ]; }, $orders) ); } + + /** + * @param array $shipment + * + * @return array + */ + private function decodeShipment(array $shipment): array + { + $data = Utils::changeArrayKeysCase($this->filter($shipment) ?? [], Arrayable::RECURSIVE); + + $additionalData = [ + 'options' => $data['options'] ?? [], + 'recipient' => $this->decodeAddress($data['recipient']), + 'sender' => $this->decodeAddress($data['sender']), + ]; + + return array_replace($data, $additionalData); + } } diff --git a/src/Fulfilment/Response/PostOrdersResponse.php b/src/Fulfilment/Response/PostOrdersResponse.php index b05ae953d..de33ee733 100644 --- a/src/Fulfilment/Response/PostOrdersResponse.php +++ b/src/Fulfilment/Response/PostOrdersResponse.php @@ -4,27 +4,4 @@ namespace MyParcelNL\Pdk\Fulfilment\Response; -use MyParcelNL\Pdk\Api\Response\ApiResponseWithBody; -use MyParcelNL\Pdk\Fulfilment\Collection\OrderCollection; - -class PostOrdersResponse extends ApiResponseWithBody -{ - /** - * @var \MyParcelNL\Pdk\Fulfilment\Collection\OrderCollection - */ - private $orderCollection; - - /** - * @return \MyParcelNL\Pdk\Fulfilment\Collection\OrderCollection - */ - public function getOrderCollection(): OrderCollection - { - return $this->orderCollection; - } - - protected function parseResponseBody(): void - { - $parsedBody = json_decode($this->getBody(), true); - $this->orderCollection = new OrderCollection($parsedBody['data']['orders']); - } -} +class PostOrdersResponse extends GetOrdersResponse { } diff --git a/src/Logger/AbstractLogger.php b/src/Logger/AbstractLogger.php index 5e6117848..4dc32571a 100644 --- a/src/Logger/AbstractLogger.php +++ b/src/Logger/AbstractLogger.php @@ -95,16 +95,6 @@ public function error($message, array $context = []): void $this->createLog(LogLevel::ERROR, $message, $context); } - /** - * @TODO: remove this default in v3.0.0, for now it's here to prevent breaking changes - * @return string[] - * @codeCoverageIgnore - */ - public function getLogFiles(): array - { - return []; - } - /** * @param string $message * @param array $context diff --git a/src/Settings/Contract/SettingsRepositoryInterface.php b/src/Settings/Contract/SettingsRepositoryInterface.php deleted file mode 100644 index ea6a8ae4c..000000000 --- a/src/Settings/Contract/SettingsRepositoryInterface.php +++ /dev/null @@ -1,11 +0,0 @@ - $data['partner_tracktraces'], 'physicalProperties' => $physicalProperties, 'price' => $data['price'], - 'recipient' => $this->filter($data['recipient']), + 'recipient' => $this->decodeAddress($data['recipient']), 'referenceIdentifier' => $data['reference_identifier'], - 'sender' => $this->filter($data['sender']), + 'sender' => $this->decodeAddress($data['sender']), 'shipmentType' => $data['shipment_type'], 'status' => $data['status'], @@ -92,16 +95,6 @@ private function decodeShipment(array $data): Shipment ]); } - /** - * @param null|array $item - * - * @return null|array - */ - private function filter(?array $item): ?array - { - return array_filter($item ?? []) ?: null; - } - /** * @param array $options * diff --git a/tests/Bootstrap/MockLegacyMigrationService.php b/tests/Bootstrap/MockLegacyMigrationService.php deleted file mode 100644 index 48ae7e582..000000000 --- a/tests/Bootstrap/MockLegacyMigrationService.php +++ /dev/null @@ -1,22 +0,0 @@ - get(MockFrontendEndpointService::class), InstallerServiceInterface::class => get(MockInstallerService::class), LanguageServiceInterface::class => get(MockLanguageService::class), - /** - * @todo v3.0.0 use PdkLoggerInterface. Leave it for now to test backwards compatibility. :) - */ - LoggerInterface::class => get(MockLogger::class), MigrationServiceInterface::class => get(MockMigrationService::class), OrderStatusServiceInterface::class => get(MockOrderStatusService::class), PdkAccountRepositoryInterface::class => get(MockPdkAccountRepository::class), PdkActionsServiceInterface::class => get(MockPdkActionsService::class), PdkCartRepositoryInterface::class => get(MockPdkCartRepository::class), PdkInterface::class => get(MockPdk::class), + PdkLoggerInterface::class => get(MockLogger::class), PdkOrderNoteRepositoryInterface::class => get(MockPdkOrderNoteRepository::class), PdkOrderRepositoryInterface::class => get(MockPdkOrderRepository::class), PdkProductRepositoryInterface::class => get(MockPdkProductRepository::class), diff --git a/tests/Integration/Context/AbstractContext.php b/tests/Integration/Context/AbstractContext.php index dd9c242c4..792de95fb 100644 --- a/tests/Integration/Context/AbstractContext.php +++ b/tests/Integration/Context/AbstractContext.php @@ -18,12 +18,12 @@ use MyParcelNL\Pdk\Base\Support\Collection; use MyParcelNL\Pdk\Facade\Pdk; use MyParcelNL\Pdk\Facade\Platform; +use MyParcelNL\Pdk\Logger\Contract\PdkLoggerInterface; use MyParcelNL\Pdk\Tests\Bootstrap\TestBootstrapper; use MyParcelNL\Pdk\Tests\Bootstrap\TestCase; use MyParcelNL\Pdk\Tests\Integration\Context\Concern\ResolvesModels; use MyParcelNL\Pdk\Tests\Integration\Context\Concern\ValidatesValues; use MyParcelNL\Pdk\Tests\Integration\Context\Contract\ContextInterface; -use Psr\Log\LoggerInterface; abstract class AbstractContext extends TestCase implements ContextInterface { @@ -110,7 +110,7 @@ final public static function beforeSuite(BeforeSuiteScope $scope): void protected static function withLogs(string $message): string { /** @var \MyParcelNL\Pdk\Tests\Bootstrap\MockLogger $logger */ - $logger = Pdk::get(LoggerInterface::class); + $logger = Pdk::get(PdkLoggerInterface::class); $logsJson = json_encode($logger->getLogs(), JSON_PRETTY_PRINT); return trim(sprintf('%s Logs: %s', $message, $logsJson)); diff --git a/tests/Unit/App/Installer/Service/InstallerServiceLegacyTest.php b/tests/Unit/App/Installer/Service/InstallerServiceLegacyTest.php deleted file mode 100644 index 1cda5dbd2..000000000 --- a/tests/Unit/App/Installer/Service/InstallerServiceLegacyTest.php +++ /dev/null @@ -1,235 +0,0 @@ - value(Platform::SENDMYPARCEL_NAME), - 'appInfo' => factory(function (): AppInfo { - return new AppInfo([ - 'name' => 'test', - 'version' => '1.3.0', - ]); - }), - - 'defaultSettings' => value([ - CheckoutSettings::ID => [ - // Default value of 'pickupLocationsDefaultView' comes from the Platform . - CheckoutSettings::DELIVERY_OPTIONS_HEADER => 'default', - ], - ]), - - MigrationServiceInterface::class => get(MockLegacyMigrationService::class), - ]) -); - -afterEach(function () { - /** @var \MyParcelNL\Pdk\Tests\Bootstrap\MockSettingsRepository $settingsRepository */ - $settingsRepository = Pdk::get(PdkSettingsRepositoryInterface::class); - - $settingsRepository->reset(); -}); - -function expectSettingsToContainLegacy(array $values): void -{ - /** @var \MyParcelNL\Pdk\Settings\Contract\PdkSettingsRepositoryInterface $settingsRepository */ - $settingsRepository = Pdk::get(PdkSettingsRepositoryInterface::class); - $settings = $settingsRepository->all(); - - expect(Arr::dot($settings->toArray()))->toHaveKeysAndValues($values); -} - -it('[legacy] performs a fresh install of the app, filling default values from platform and config', function () { - /** @var PdkSettingsRepositoryInterface $settingsRepository */ - $settingsRepository = Pdk::get(PdkSettingsRepositoryInterface::class); - $installedVersionKey = Pdk::get('settingKeyInstalledVersion'); - - // Remove the installed version from the settings: - $settingsRepository->store($installedVersionKey, null); - - expect($settingsRepository->get($installedVersionKey))->toBe(null); - - Installer::install(); - - expect($settingsRepository->get($installedVersionKey)) - ->toEqual('1.3.0'); - - expectSettingsToContainLegacy([ - /** From default settings */ - 'checkout.deliveryOptionsHeader' => 'default', - 'checkout.pickupLocationsDefaultView' => 'map', - - /** - * Expect 1.2.0 migration to not have run (as it's only in the upgrade migrations) - * - * @see \MyParcelNL\Pdk\Tests\Bootstrap\MockUpgradeMigration120 - */ - 'order.barcodeInNoteTitle' => null, - ]); -}); - -it('[legacy] upgrades app to new version', function () { - /** @var PdkSettingsRepositoryInterface $settingsRepository */ - $settingsRepository = Pdk::get(PdkSettingsRepositoryInterface::class); - $installedVersionKey = Pdk::get('settingKeyInstalledVersion'); - - // Set the installed version to 1.1.0: - $settingsRepository->store($installedVersionKey, '1.1.0'); - expect($settingsRepository->get($installedVersionKey))->toEqual('1.1.0'); - - Installer::install(); - - expect($settingsRepository->get($installedVersionKey))->toEqual('1.3.0'); - - expectSettingsToContainLegacy([ - /** - * Expect 1.1.0 migration to not have run - * - * @see \MyParcelNL\Pdk\Tests\Bootstrap\MockUpgradeMigration110 - * */ - 'label.description' => null, - - /** - * Expect 1.2.0 migration to have run - * - * @see \MyParcelNL\Pdk\Tests\Bootstrap\MockUpgradeMigration120 - */ - 'order.barcodeInNoteTitle' => 'new-barcode-in-note', - - /** - * Expect 1.3.0 migration to have been run - * - * @see \MyParcelNL\Pdk\Tests\Bootstrap\MockUpgradeMigration130 - */ - 'order.emptyMailboxWeight' => 400, - ]); -}); - -it('[legacy] runs down migrations on uninstall', function () { - /** @var PdkSettingsRepositoryInterface $settingsRepository */ - $settingsRepository = Pdk::get(PdkSettingsRepositoryInterface::class); - $installedVersionKey = Pdk::get('settingKeyInstalledVersion'); - $createSettingsKey = Pdk::get('createSettingsKey'); - - $settingsRepository->store($installedVersionKey, '1.3.0'); - $settingsRepository->store($createSettingsKey('account.apiKey'), '12345'); - - expect($settingsRepository->get($installedVersionKey)) - ->toEqual('1.3.0'); - - Installer::uninstall(); - - expect($settingsRepository->get($installedVersionKey)) - ->toEqual(null); - - expectSettingsToContainLegacy([ - /** - * Expect 1.1.0 migration to have been reversed - * - * @see \MyParcelNL\Pdk\Tests\Bootstrap\MockUpgradeMigration110 - */ - 'label.description' => 'old-description', - - /** - * Expect 1.2.0 migration to have been reversed - * - * @see \MyParcelNL\Pdk\Tests\Bootstrap\MockUpgradeMigration120 - */ - 'order.barcodeInNoteTitle' => 'old-barcode-in-note', - ]); -}); - -it('[legacy] passes through arbitrary arguments', function ($_, array $result) { - /** @var \MyParcelNL\Pdk\Tests\Bootstrap\MockLogger $logger */ - $logger = Pdk::get(LoggerInterface::class); - - expect($logger->getLogs())->toContain($result); -})->with([ - 'install' => [ - 'method' => function () { - Installer::install('appelboom', 12345); - }, - 'result' => [ - 'level' => 'debug', - 'message' => '[PDK]: install arguments', - 'context' => ['appelboom', 12345], - ], - ], - - 'uninstall' => [ - 'method' => function () { - /** @var \MyParcelNL\Pdk\Settings\Contract\PdkSettingsRepositoryInterface $settingsRepository */ - $settingsRepository = Pdk::get(PdkSettingsRepositoryInterface::class); - $installedVersionKey = Pdk::get('settingKeyInstalledVersion'); - - $settingsRepository->store($installedVersionKey, '1.3.0'); - - Installer::uninstall(12, 'peer'); - }, - 'result' => [ - 'level' => 'debug', - 'message' => '[PDK]: uninstall arguments', - 'context' => [12, 'peer'], - ], - ], -]); - -it('[legacy] does not install if version is equal', function () { - /** @var PdkSettingsRepositoryInterface $settingsRepository */ - $settingsRepository = Pdk::get(PdkSettingsRepositoryInterface::class); - $installedVersionKey = Pdk::get('settingKeyInstalledVersion'); - $createSettingsKey = Pdk::get('createSettingsKey'); - - $settingsRepository->store($installedVersionKey, '1.3.0'); - $settingsRepository->store($createSettingsKey('label.description'), 'description'); - - Installer::install(); - - expect($settingsRepository->get($installedVersionKey)) - ->toEqual('1.3.0') - ->and($settingsRepository->get($createSettingsKey('label.description'))) - ->toBe('description'); -}); - -it('[legacy] does not uninstall if is not installed', function () { - /** @var PdkSettingsRepositoryInterface $settingsRepository */ - $settingsRepository = Pdk::get(PdkSettingsRepositoryInterface::class); - $installedVersionKey = Pdk::get('settingKeyInstalledVersion'); - $createSettingsKey = Pdk::get('createSettingsKey'); - - // Set the installed version to null: - $settingsRepository->store($installedVersionKey, null); - $settingsRepository->store($createSettingsKey('label.description'), 'description'); - - Installer::uninstall(); - - expect($settingsRepository->get($installedVersionKey)) - ->toEqual(null) - ->and($settingsRepository->get($createSettingsKey('label.description'))) - ->toBe('description'); -}); diff --git a/tests/Unit/App/Installer/Service/InstallerServiceTest.php b/tests/Unit/App/Installer/Service/InstallerServiceTest.php index 9e55b98b9..2d9ebacaf 100644 --- a/tests/Unit/App/Installer/Service/InstallerServiceTest.php +++ b/tests/Unit/App/Installer/Service/InstallerServiceTest.php @@ -10,10 +10,10 @@ use MyParcelNL\Pdk\Base\Support\Arr; use MyParcelNL\Pdk\Facade\Installer; use MyParcelNL\Pdk\Facade\Pdk; +use MyParcelNL\Pdk\Logger\Contract\PdkLoggerInterface; use MyParcelNL\Pdk\Settings\Contract\PdkSettingsRepositoryInterface; use MyParcelNL\Pdk\Settings\Model\CheckoutSettings; use MyParcelNL\Pdk\Tests\Uses\UsesMockPdkInstance; -use Psr\Log\LoggerInterface; use function DI\factory; use function DI\value; use function MyParcelNL\Pdk\Tests\usesShared; @@ -179,7 +179,7 @@ function expectSettingsToContain(array $values): void it('passes through arbitrary arguments', function ($_, array $result) { /** @var \MyParcelNL\Pdk\Tests\Bootstrap\MockLogger $logger */ - $logger = Pdk::get(LoggerInterface::class); + $logger = Pdk::get(PdkLoggerInterface::class); expect($logger->getLogs())->toContain($result); })->with([ diff --git a/tests/Unit/App/Webhook/Hook/ShopWebhookTest.php b/tests/Unit/App/Webhook/Hook/ShopWebhookTest.php index 2f785f730..1c86933fa 100644 --- a/tests/Unit/App/Webhook/Hook/ShopWebhookTest.php +++ b/tests/Unit/App/Webhook/Hook/ShopWebhookTest.php @@ -10,6 +10,7 @@ use MyParcelNL\Pdk\Base\Contract\CronServiceInterface; use MyParcelNL\Pdk\Base\Support\Collection; use MyParcelNL\Pdk\Facade\Pdk; +use MyParcelNL\Pdk\Logger\Contract\PdkLoggerInterface; use MyParcelNL\Pdk\Tests\Api\Response\ExampleGetOrdersResponse; use MyParcelNL\Pdk\Tests\Bootstrap\MockApi; use MyParcelNL\Pdk\Tests\Bootstrap\TestBootstrapper; @@ -18,7 +19,6 @@ use MyParcelNL\Pdk\Tests\Uses\UsesMockPdkInstance; use MyParcelNL\Pdk\Webhook\Collection\WebhookSubscriptionCollection; use MyParcelNL\Pdk\Webhook\Model\WebhookSubscription; -use Psr\Log\LoggerInterface; use Symfony\Component\HttpFoundation\Request; use function MyParcelNL\Pdk\Tests\usesShared; @@ -34,7 +34,7 @@ /** @var \MyParcelNL\Pdk\Tests\Bootstrap\MockCronService $cronService */ $cronService = Pdk::get(CronServiceInterface::class); /** @var \MyParcelNL\Pdk\Tests\Bootstrap\MockLogger $logger */ - $logger = Pdk::get(LoggerInterface::class); + $logger = Pdk::get(PdkLoggerInterface::class); $repository->storeHashedUrl('https://example.com/hook/1234567890abcdef'); $repository->store(new WebhookSubscriptionCollection([['hook' => $hook, 'url' => $repository->getHashedUrl()]])); @@ -110,7 +110,7 @@ /** @var \MyParcelNL\Pdk\Tests\Bootstrap\MockCronService $cronService */ $cronService = Pdk::get(CronServiceInterface::class); /** @var \MyParcelNL\Pdk\Tests\Bootstrap\MockLogger $logger */ - $logger = Pdk::get(LoggerInterface::class); + $logger = Pdk::get(PdkLoggerInterface::class); $repository->store(new WebhookSubscriptionCollection([['hook' => $hook, 'url' => $repository->getHashedUrl()]])); diff --git a/tests/Unit/Base/Concern/HasAttributesTest.php b/tests/Unit/Base/Concern/HasAttributesTest.php index 33213bbe9..9d27cb831 100644 --- a/tests/Unit/Base/Concern/HasAttributesTest.php +++ b/tests/Unit/Base/Concern/HasAttributesTest.php @@ -9,6 +9,7 @@ use DateTimeImmutable; use MyParcelNL\Pdk\Base\Support\Collection; use MyParcelNL\Pdk\Facade\Pdk; +use MyParcelNL\Pdk\Logger\Contract\PdkLoggerInterface; use MyParcelNL\Pdk\Tests\Mocks\ClassWithGuardedAttributes; use MyParcelNL\Pdk\Tests\Mocks\InvalidCastingModel; use MyParcelNL\Pdk\Tests\Mocks\MockCastingModel; @@ -16,8 +17,6 @@ use MyParcelNL\Pdk\Tests\Mocks\MockMutateModel; use MyParcelNL\Pdk\Tests\Uses\UsesMockPdkInstance; use MyParcelNL\Pdk\Types\Service\TriStateService; -use Psr\Log\LoggerInterface; -use function expect; use function MyParcelNL\Pdk\Tests\usesShared; uses()->group('model'); @@ -107,7 +106,7 @@ it('returns null and logs error on invalid cast', function () { /** @var \MyParcelNL\Pdk\Tests\Bootstrap\MockLogger $logger */ - $logger = Pdk::get(LoggerInterface::class); + $logger = Pdk::get(PdkLoggerInterface::class); $value = new DateTime(); $model = new InvalidCastingModel(['value' => $value]); diff --git a/tests/Unit/Base/Model/AddressTest.php b/tests/Unit/Base/Model/AddressTest.php deleted file mode 100644 index 7b160344c..000000000 --- a/tests/Unit/Base/Model/AddressTest.php +++ /dev/null @@ -1,67 +0,0 @@ -toArray()))->toBe($output); -})->with([ - 'full_street' => [ - 'input' => [ - 'full_street' => 'street 123 b', - ], - 'output' => [ - 'address1' => 'street 123 b', - ], - ], - 'street_additional_info' => [ - 'input' => [ - 'street_additional_info' => '2F', - ], - 'output' => [ - 'address2' => '2F', - ], - ], - - 'street and number' => [ - 'input' => [ - 'street' => 'street', - 'number' => '123', - ], - 'output' => [ - 'address1' => 'street 123', - ], - ], - - 'street, number and number_suffix' => [ - 'input' => [ - 'street' => 'street', - 'number' => '123', - 'number_suffix' => 'b', - ], - 'output' => [ - 'address1' => 'street 123 b', - ], - ], - - 'street, number and box_number' => [ - 'input' => [ - 'street' => 'street', - 'number' => '123', - 'box_number' => 'b', - ], - 'output' => [ - 'address1' => 'street 123 b', - ], - ], -]); diff --git a/tests/Unit/Base/Model/ModelDeprecationTest.php b/tests/Unit/Base/Model/ModelDeprecationTest.php index e53c70850..7d1492ac5 100644 --- a/tests/Unit/Base/Model/ModelDeprecationTest.php +++ b/tests/Unit/Base/Model/ModelDeprecationTest.php @@ -6,9 +6,9 @@ namespace MyParcelNL\Pdk\Base\Model; use MyParcelNL\Pdk\Facade\Pdk; +use MyParcelNL\Pdk\Logger\Contract\PdkLoggerInterface; use MyParcelNL\Pdk\Tests\Mocks\MockCastModel; use MyParcelNL\Pdk\Tests\Uses\UsesEachMockPdkInstance; -use Psr\Log\LoggerInterface; use function MyParcelNL\Pdk\Tests\usesShared; usesShared(new UsesEachMockPdkInstance()); @@ -19,7 +19,7 @@ ]); /** @var \MyParcelNL\Pdk\Tests\Bootstrap\MockLogger $logger */ - $logger = Pdk::get(LoggerInterface::class); + $logger = Pdk::get(PdkLoggerInterface::class); /** * @var string $nextVersion diff --git a/tests/Unit/Base/PdkEndpointTest.php b/tests/Unit/Base/PdkEndpointTest.php index 818b5edaa..2db282048 100644 --- a/tests/Unit/Base/PdkEndpointTest.php +++ b/tests/Unit/Base/PdkEndpointTest.php @@ -30,12 +30,12 @@ use MyParcelNL\Pdk\Base\Factory\PdkFactory; use MyParcelNL\Pdk\Base\Support\Arr; use MyParcelNL\Pdk\Facade\Pdk; +use MyParcelNL\Pdk\Logger\Contract\PdkLoggerInterface; use MyParcelNL\Pdk\Tests\Bootstrap\MockAction; use MyParcelNL\Pdk\Tests\Bootstrap\MockApiExceptionAction; use MyParcelNL\Pdk\Tests\Bootstrap\MockExceptionAction; use MyParcelNL\Pdk\Tests\Bootstrap\MockPdkConfig; use MyParcelNL\Pdk\Tests\Uses\UsesEachMockPdkInstance; -use Psr\Log\LoggerInterface; use Symfony\Component\HttpFoundation\Response; use function DI\get; use function DI\value; @@ -121,7 +121,7 @@ function testEndpoint(string $action, string $context): void /** @var PdkEndpoint $endpoint */ $endpoint = Pdk::get(PdkEndpoint::class); /** @var \MyParcelNL\Pdk\Tests\Bootstrap\MockLogger $logger */ - $logger = Pdk::get(LoggerInterface::class); + $logger = Pdk::get(PdkLoggerInterface::class); $response = $endpoint->call('nonexistent', PdkEndpoint::CONTEXT_BACKEND); diff --git a/tests/Unit/Base/Support/UtilsTest.php b/tests/Unit/Base/Support/UtilsTest.php index f6f4a0a79..1dcd71408 100644 --- a/tests/Unit/Base/Support/UtilsTest.php +++ b/tests/Unit/Base/Support/UtilsTest.php @@ -12,7 +12,6 @@ use MyParcelNL\Pdk\Tests\Mocks\MockClassWithTrait; use ReflectionMethod; use stdClass; -use function expect; it('gets parents of class recursively', function () { expect(Utils::getClassParentsRecursive(new MockClassWithTrait())) diff --git a/tests/Unit/Fulfilment/Model/OrderTest.php b/tests/Unit/Fulfilment/Model/OrderTest.php index 8b6912f83..b7d306fcf 100644 --- a/tests/Unit/Fulfilment/Model/OrderTest.php +++ b/tests/Unit/Fulfilment/Model/OrderTest.php @@ -5,122 +5,75 @@ namespace MyParcelNL\Pdk\Fulfilment\Model; +use MyParcelNL\Pdk\App\Order\Collection\PdkOrderLineCollection; use MyParcelNL\Pdk\App\Order\Model\PdkOrder; +use MyParcelNL\Pdk\App\Order\Model\PdkOrderFactory; +use MyParcelNL\Pdk\App\Order\Model\PdkOrderLine; +use MyParcelNL\Pdk\App\Order\Model\PdkProduct; use MyParcelNL\Pdk\Tests\Uses\UsesMockPdkInstance; +use function MyParcelNL\Pdk\Tests\factory; use function MyParcelNL\Pdk\Tests\usesShared; use function Spatie\Snapshots\assertMatchesJsonSnapshot; usesShared(new UsesMockPdkInstance()); -it('creates fulfilment order from pdk order', function (array $input) { - $pdkOrder = new PdkOrder($input); +it('creates fulfilment order from pdk order', function (PdkOrderFactory $factory) { + $product1 = factory(PdkProduct::class) + ->withEverything() + ->withPrice(100); + $product2 = factory(PdkProduct::class) + ->withEverything() + ->withPrice(200); + $product3 = factory(PdkProduct::class) + ->withEverything() + ->withPrice(300); + + $factory->withLines( + factory(PdkOrderLineCollection::class)->push( + factory(PdkOrderLine::class) + ->withProduct($product1) + ->withQuantity(3) + ->withPrice(3 * 100) + ->withVat((int) (3 * 100 * 0.09)), + + factory(PdkOrderLine::class) + ->withProduct($product2) + ->withPrice(300) + ->withVat((int) (300 * 0.21)), + + factory(PdkOrderLine::class) + ->withProduct($product3) + ->withQuantity(6) + ->withPrice(6 * 300) + ->withVat((int) (6 * 300 * 0.21)) + ) + ); + + $pdkOrder = $factory->make(); $fulfilmentOrder = Order::fromPdkOrder($pdkOrder); + expect($fulfilmentOrder)->toBeInstanceOf(Order::class); assertMatchesJsonSnapshot(json_encode($fulfilmentOrder->toArrayWithoutNull())); })->with([ - 'empty order' => [[]], - 'order without shipments' => [ - 'input' => [ - 'externalIdentifier' => 'ABC123456', - 'orderDate' => '2023-01-01 00:00:00', - 'customsDeclaration' => [ - 'contents' => '00', - 'invoice' => 'ABC123456', - 'items' => [ - [ - 'amount' => 10, - 'classification' => '12345', - 'country' => 'NL', - 'description' => 'A word', - 'itemValue' => [ - 'amount' => 100, - 'currency' => 'EUR', - ], - 'weight' => 100, - ], - ], - 'weight' => 1000, - ], - 'deliveryOptions' => [ - 'carrier' => 'postnl', - 'date' => '2020-01-01', - 'deliveryType' => 'standard', - 'labelAmount' => 1, - 'packageType' => 'package', - 'pickupLocation' => null, - 'shipmentOptions' => [ - 'onlyRecipient' => true, - 'signature' => true, - ], - ], - 'lines' => [ - [ - 'externalIdentifier' => 'ABC123456-1', - 'quantity' => 10, - 'price' => 295, - 'vat' => 62, - 'priceAfterVat' => 357, - 'product' => [ - 'sku' => 'ABC123456', - 'ean' => '1234567890123', - 'name' => 'Product name', - 'weight' => 100, - ], - ], - ], - 'physicalProperties' => [ - 'weight' => 1000, - 'height' => 100, - 'width' => 100, - 'length' => 100, - ], - 'recipient' => [ - 'company' => 'MyParcel', - 'email' => 'test@myparcel.nl', - 'person' => 'Ms. Parcel', - 'phone' => '0612356789', - 'cc' => 'NL', - 'city' => 'Hoofddorp', - 'address1' => 'Antareslaan 31', - 'postalCode' => '2132JE', - 'region' => 'Noord-Holland', - 'state' => 'Noord-Holland', - ], - 'sender' => null, - 'shipments' => [], - 'shipmentPrice' => 695, - 'shipmentVat' => 146, - 'shipmentPriceAfterVat' => 841, - 'orderPrice' => 2950, - 'orderVat' => 620, - 'orderPriceAfterVat' => 3570, - 'totalPrice' => 3645, - 'totalVat' => 766, - 'totalPriceAfterVat' => 4411, - ], - ], - 'order with shipments' => [ - 'input' => [ - 'shipments' => [ - [ - 'deliveryOptions' => [ - 'carrier' => 'postnl', - 'date' => '2020-01-01', - 'deliveryType' => 'standard', - 'labelAmount' => 1, - 'packageType' => 'package', - 'pickupLocation' => null, - 'shipmentOptions' => [ - 'onlyRecipient' => true, - 'signature' => true, - ], - ], - ], - ], - ], - ], -]); + 'simple order' => function () { + return factory(PdkOrder::class); + }, + + 'order with delivery options' => function () { + return factory(PdkOrder::class)->withDeliveryOptionsWithAllOptions(); + }, + + 'order to pickup location' => function () { + return factory(PdkOrder::class)->withDeliveryOptionsWithPickupLocation(); + }, + + 'order to germany' => function () { + return factory(PdkOrder::class)->toGermany(); + }, + + ] +); it('returns empty fulfilment order when no pdk order is passed', function () { $fulfilmentOrder = Order::fromPdkOrder(null); diff --git a/tests/Uses/UsesMockEachLogger.php b/tests/Uses/UsesMockEachLogger.php index 179fac449..c672f1d1c 100644 --- a/tests/Uses/UsesMockEachLogger.php +++ b/tests/Uses/UsesMockEachLogger.php @@ -5,14 +5,14 @@ namespace MyParcelNL\Pdk\Tests\Uses; use MyParcelNL\Pdk\Facade\Pdk; -use Psr\Log\LoggerInterface; +use MyParcelNL\Pdk\Logger\Contract\PdkLoggerInterface; final class UsesMockEachLogger implements BaseMock { public function afterEach(): void { /** @var \MyParcelNL\Pdk\Tests\Bootstrap\MockLogger $logger */ - $logger = Pdk::get(LoggerInterface::class); + $logger = Pdk::get(PdkLoggerInterface::class); $logger->clear(); } diff --git a/tests/__snapshots__/ExportOrderActionTest__it_exports_order_with_data_set_order_mode__data_set_export_age_check__data_set_carrier_dhl_for_you__1.json b/tests/__snapshots__/ExportOrderActionTest__it_exports_order_with_data_set_order_mode__data_set_export_age_check__data_set_carrier_dhl_for_you__1.json index 08b95a845..8c67c5190 100644 --- a/tests/__snapshots__/ExportOrderActionTest__it_exports_order_with_data_set_order_mode__data_set_export_age_check__data_set_carrier_dhl_for_you__1.json +++ b/tests/__snapshots__/ExportOrderActionTest__it_exports_order_with_data_set_order_mode__data_set_export_age_check__data_set_carrier_dhl_for_you__1.json @@ -16,8 +16,8 @@ "order_lines": [ { "quantity": 1, - "price": 0, - "price_after_vat": 0, + "price": 1000, + "price_after_vat": 1000, "product": { "sku": "test", "external_identifier": "PDK-1", diff --git a/tests/__snapshots__/ExportOrderActionTest__it_exports_order_with_data_set_order_mode__data_set_export_age_check__data_set_single_order__1.json b/tests/__snapshots__/ExportOrderActionTest__it_exports_order_with_data_set_order_mode__data_set_export_age_check__data_set_single_order__1.json index e64c349e0..f716be913 100644 --- a/tests/__snapshots__/ExportOrderActionTest__it_exports_order_with_data_set_order_mode__data_set_export_age_check__data_set_single_order__1.json +++ b/tests/__snapshots__/ExportOrderActionTest__it_exports_order_with_data_set_order_mode__data_set_export_age_check__data_set_single_order__1.json @@ -16,8 +16,8 @@ "order_lines": [ { "quantity": 1, - "price": 0, - "price_after_vat": 0, + "price": 1000, + "price_after_vat": 1000, "product": { "sku": "test", "external_identifier": "PDK-1", diff --git a/tests/__snapshots__/ExportOrderActionTest__it_exports_order_with_data_set_order_mode__data_set_export_age_check__data_set_various_delivery_options__1.json b/tests/__snapshots__/ExportOrderActionTest__it_exports_order_with_data_set_order_mode__data_set_export_age_check__data_set_various_delivery_options__1.json index 164490296..e87d6fcdc 100644 --- a/tests/__snapshots__/ExportOrderActionTest__it_exports_order_with_data_set_order_mode__data_set_export_age_check__data_set_various_delivery_options__1.json +++ b/tests/__snapshots__/ExportOrderActionTest__it_exports_order_with_data_set_order_mode__data_set_export_age_check__data_set_various_delivery_options__1.json @@ -16,8 +16,8 @@ "order_lines": [ { "quantity": 5, - "price": 0, - "price_after_vat": 0, + "price": 1000, + "price_after_vat": 1000, "product": { "sku": "test", "external_identifier": "PDK-2", @@ -79,8 +79,8 @@ "order_lines": [ { "quantity": 1, - "price": 0, - "price_after_vat": 0, + "price": 1000, + "price_after_vat": 1000, "product": { "sku": "test", "external_identifier": "PDK-3", @@ -143,8 +143,8 @@ "order_lines": [ { "quantity": 1, - "price": 0, - "price_after_vat": 0, + "price": 1000, + "price_after_vat": 1000, "product": { "sku": "test", "external_identifier": "PDK-4", diff --git a/tests/__snapshots__/ExportOrderActionTest__it_exports_order_with_data_set_order_mode__data_set_export_insurance__data_set_carrier_dhl_for_you__1.json b/tests/__snapshots__/ExportOrderActionTest__it_exports_order_with_data_set_order_mode__data_set_export_insurance__data_set_carrier_dhl_for_you__1.json index 1105f10c5..3fcdcc535 100644 --- a/tests/__snapshots__/ExportOrderActionTest__it_exports_order_with_data_set_order_mode__data_set_export_insurance__data_set_carrier_dhl_for_you__1.json +++ b/tests/__snapshots__/ExportOrderActionTest__it_exports_order_with_data_set_order_mode__data_set_export_insurance__data_set_carrier_dhl_for_you__1.json @@ -16,8 +16,8 @@ "order_lines": [ { "quantity": 1, - "price": 0, - "price_after_vat": 0, + "price": 1000, + "price_after_vat": 1000, "product": { "sku": "test", "external_identifier": "PDK-1", diff --git a/tests/__snapshots__/ExportOrderActionTest__it_exports_order_with_data_set_order_mode__data_set_export_insurance__data_set_single_order__1.json b/tests/__snapshots__/ExportOrderActionTest__it_exports_order_with_data_set_order_mode__data_set_export_insurance__data_set_single_order__1.json index 7a596d1e6..333180869 100644 --- a/tests/__snapshots__/ExportOrderActionTest__it_exports_order_with_data_set_order_mode__data_set_export_insurance__data_set_single_order__1.json +++ b/tests/__snapshots__/ExportOrderActionTest__it_exports_order_with_data_set_order_mode__data_set_export_insurance__data_set_single_order__1.json @@ -16,8 +16,8 @@ "order_lines": [ { "quantity": 1, - "price": 0, - "price_after_vat": 0, + "price": 1000, + "price_after_vat": 1000, "product": { "sku": "test", "external_identifier": "PDK-1", diff --git a/tests/__snapshots__/ExportOrderActionTest__it_exports_order_with_data_set_order_mode__data_set_export_insurance__data_set_various_delivery_options__1.json b/tests/__snapshots__/ExportOrderActionTest__it_exports_order_with_data_set_order_mode__data_set_export_insurance__data_set_various_delivery_options__1.json index 164490296..e87d6fcdc 100644 --- a/tests/__snapshots__/ExportOrderActionTest__it_exports_order_with_data_set_order_mode__data_set_export_insurance__data_set_various_delivery_options__1.json +++ b/tests/__snapshots__/ExportOrderActionTest__it_exports_order_with_data_set_order_mode__data_set_export_insurance__data_set_various_delivery_options__1.json @@ -16,8 +16,8 @@ "order_lines": [ { "quantity": 5, - "price": 0, - "price_after_vat": 0, + "price": 1000, + "price_after_vat": 1000, "product": { "sku": "test", "external_identifier": "PDK-2", @@ -79,8 +79,8 @@ "order_lines": [ { "quantity": 1, - "price": 0, - "price_after_vat": 0, + "price": 1000, + "price_after_vat": 1000, "product": { "sku": "test", "external_identifier": "PDK-3", @@ -143,8 +143,8 @@ "order_lines": [ { "quantity": 1, - "price": 0, - "price_after_vat": 0, + "price": 1000, + "price_after_vat": 1000, "product": { "sku": "test", "external_identifier": "PDK-4", diff --git a/tests/__snapshots__/ExportOrderActionTest__it_exports_order_with_data_set_order_mode__data_set_export_large_format__data_set_carrier_dhl_for_you__1.json b/tests/__snapshots__/ExportOrderActionTest__it_exports_order_with_data_set_order_mode__data_set_export_large_format__data_set_carrier_dhl_for_you__1.json index 1105f10c5..3fcdcc535 100644 --- a/tests/__snapshots__/ExportOrderActionTest__it_exports_order_with_data_set_order_mode__data_set_export_large_format__data_set_carrier_dhl_for_you__1.json +++ b/tests/__snapshots__/ExportOrderActionTest__it_exports_order_with_data_set_order_mode__data_set_export_large_format__data_set_carrier_dhl_for_you__1.json @@ -16,8 +16,8 @@ "order_lines": [ { "quantity": 1, - "price": 0, - "price_after_vat": 0, + "price": 1000, + "price_after_vat": 1000, "product": { "sku": "test", "external_identifier": "PDK-1", diff --git a/tests/__snapshots__/ExportOrderActionTest__it_exports_order_with_data_set_order_mode__data_set_export_large_format__data_set_single_order__1.json b/tests/__snapshots__/ExportOrderActionTest__it_exports_order_with_data_set_order_mode__data_set_export_large_format__data_set_single_order__1.json index 1d556d283..43ec4a50a 100644 --- a/tests/__snapshots__/ExportOrderActionTest__it_exports_order_with_data_set_order_mode__data_set_export_large_format__data_set_single_order__1.json +++ b/tests/__snapshots__/ExportOrderActionTest__it_exports_order_with_data_set_order_mode__data_set_export_large_format__data_set_single_order__1.json @@ -16,8 +16,8 @@ "order_lines": [ { "quantity": 1, - "price": 0, - "price_after_vat": 0, + "price": 1000, + "price_after_vat": 1000, "product": { "sku": "test", "external_identifier": "PDK-1", diff --git a/tests/__snapshots__/ExportOrderActionTest__it_exports_order_with_data_set_order_mode__data_set_export_large_format__data_set_various_delivery_options__1.json b/tests/__snapshots__/ExportOrderActionTest__it_exports_order_with_data_set_order_mode__data_set_export_large_format__data_set_various_delivery_options__1.json index fb6b6d25a..7ef8600c9 100644 --- a/tests/__snapshots__/ExportOrderActionTest__it_exports_order_with_data_set_order_mode__data_set_export_large_format__data_set_various_delivery_options__1.json +++ b/tests/__snapshots__/ExportOrderActionTest__it_exports_order_with_data_set_order_mode__data_set_export_large_format__data_set_various_delivery_options__1.json @@ -16,8 +16,8 @@ "order_lines": [ { "quantity": 5, - "price": 0, - "price_after_vat": 0, + "price": 1000, + "price_after_vat": 1000, "product": { "sku": "test", "external_identifier": "PDK-2", @@ -79,8 +79,8 @@ "order_lines": [ { "quantity": 1, - "price": 0, - "price_after_vat": 0, + "price": 1000, + "price_after_vat": 1000, "product": { "sku": "test", "external_identifier": "PDK-3", @@ -143,8 +143,8 @@ "order_lines": [ { "quantity": 1, - "price": 0, - "price_after_vat": 0, + "price": 1000, + "price_after_vat": 1000, "product": { "sku": "test", "external_identifier": "PDK-4", diff --git a/tests/__snapshots__/ExportOrderActionTest__it_exports_order_with_data_set_order_mode__data_set_export_only_recipient__data_set_carrier_dhl_for_you__1.json b/tests/__snapshots__/ExportOrderActionTest__it_exports_order_with_data_set_order_mode__data_set_export_only_recipient__data_set_carrier_dhl_for_you__1.json index 7c67e2485..3f2fa4a01 100644 --- a/tests/__snapshots__/ExportOrderActionTest__it_exports_order_with_data_set_order_mode__data_set_export_only_recipient__data_set_carrier_dhl_for_you__1.json +++ b/tests/__snapshots__/ExportOrderActionTest__it_exports_order_with_data_set_order_mode__data_set_export_only_recipient__data_set_carrier_dhl_for_you__1.json @@ -16,8 +16,8 @@ "order_lines": [ { "quantity": 1, - "price": 0, - "price_after_vat": 0, + "price": 1000, + "price_after_vat": 1000, "product": { "sku": "test", "external_identifier": "PDK-1", diff --git a/tests/__snapshots__/ExportOrderActionTest__it_exports_order_with_data_set_order_mode__data_set_export_only_recipient__data_set_single_order__1.json b/tests/__snapshots__/ExportOrderActionTest__it_exports_order_with_data_set_order_mode__data_set_export_only_recipient__data_set_single_order__1.json index 5e2ddee91..11878c1c6 100644 --- a/tests/__snapshots__/ExportOrderActionTest__it_exports_order_with_data_set_order_mode__data_set_export_only_recipient__data_set_single_order__1.json +++ b/tests/__snapshots__/ExportOrderActionTest__it_exports_order_with_data_set_order_mode__data_set_export_only_recipient__data_set_single_order__1.json @@ -16,8 +16,8 @@ "order_lines": [ { "quantity": 1, - "price": 0, - "price_after_vat": 0, + "price": 1000, + "price_after_vat": 1000, "product": { "sku": "test", "external_identifier": "PDK-1", diff --git a/tests/__snapshots__/ExportOrderActionTest__it_exports_order_with_data_set_order_mode__data_set_export_only_recipient__data_set_various_delivery_options__1.json b/tests/__snapshots__/ExportOrderActionTest__it_exports_order_with_data_set_order_mode__data_set_export_only_recipient__data_set_various_delivery_options__1.json index 164490296..e87d6fcdc 100644 --- a/tests/__snapshots__/ExportOrderActionTest__it_exports_order_with_data_set_order_mode__data_set_export_only_recipient__data_set_various_delivery_options__1.json +++ b/tests/__snapshots__/ExportOrderActionTest__it_exports_order_with_data_set_order_mode__data_set_export_only_recipient__data_set_various_delivery_options__1.json @@ -16,8 +16,8 @@ "order_lines": [ { "quantity": 5, - "price": 0, - "price_after_vat": 0, + "price": 1000, + "price_after_vat": 1000, "product": { "sku": "test", "external_identifier": "PDK-2", @@ -79,8 +79,8 @@ "order_lines": [ { "quantity": 1, - "price": 0, - "price_after_vat": 0, + "price": 1000, + "price_after_vat": 1000, "product": { "sku": "test", "external_identifier": "PDK-3", @@ -143,8 +143,8 @@ "order_lines": [ { "quantity": 1, - "price": 0, - "price_after_vat": 0, + "price": 1000, + "price_after_vat": 1000, "product": { "sku": "test", "external_identifier": "PDK-4", diff --git a/tests/__snapshots__/ExportOrderActionTest__it_exports_order_with_data_set_order_mode__data_set_export_return__data_set_carrier_dhl_for_you__1.json b/tests/__snapshots__/ExportOrderActionTest__it_exports_order_with_data_set_order_mode__data_set_export_return__data_set_carrier_dhl_for_you__1.json index 1105f10c5..3fcdcc535 100644 --- a/tests/__snapshots__/ExportOrderActionTest__it_exports_order_with_data_set_order_mode__data_set_export_return__data_set_carrier_dhl_for_you__1.json +++ b/tests/__snapshots__/ExportOrderActionTest__it_exports_order_with_data_set_order_mode__data_set_export_return__data_set_carrier_dhl_for_you__1.json @@ -16,8 +16,8 @@ "order_lines": [ { "quantity": 1, - "price": 0, - "price_after_vat": 0, + "price": 1000, + "price_after_vat": 1000, "product": { "sku": "test", "external_identifier": "PDK-1", diff --git a/tests/__snapshots__/ExportOrderActionTest__it_exports_order_with_data_set_order_mode__data_set_export_return__data_set_single_order__1.json b/tests/__snapshots__/ExportOrderActionTest__it_exports_order_with_data_set_order_mode__data_set_export_return__data_set_single_order__1.json index ec1ea0fb3..46dcbc3ff 100644 --- a/tests/__snapshots__/ExportOrderActionTest__it_exports_order_with_data_set_order_mode__data_set_export_return__data_set_single_order__1.json +++ b/tests/__snapshots__/ExportOrderActionTest__it_exports_order_with_data_set_order_mode__data_set_export_return__data_set_single_order__1.json @@ -16,8 +16,8 @@ "order_lines": [ { "quantity": 1, - "price": 0, - "price_after_vat": 0, + "price": 1000, + "price_after_vat": 1000, "product": { "sku": "test", "external_identifier": "PDK-1", diff --git a/tests/__snapshots__/ExportOrderActionTest__it_exports_order_with_data_set_order_mode__data_set_export_return__data_set_various_delivery_options__1.json b/tests/__snapshots__/ExportOrderActionTest__it_exports_order_with_data_set_order_mode__data_set_export_return__data_set_various_delivery_options__1.json index abedbb9e9..6ccce20cf 100644 --- a/tests/__snapshots__/ExportOrderActionTest__it_exports_order_with_data_set_order_mode__data_set_export_return__data_set_various_delivery_options__1.json +++ b/tests/__snapshots__/ExportOrderActionTest__it_exports_order_with_data_set_order_mode__data_set_export_return__data_set_various_delivery_options__1.json @@ -16,8 +16,8 @@ "order_lines": [ { "quantity": 5, - "price": 0, - "price_after_vat": 0, + "price": 1000, + "price_after_vat": 1000, "product": { "sku": "test", "external_identifier": "PDK-2", @@ -79,8 +79,8 @@ "order_lines": [ { "quantity": 1, - "price": 0, - "price_after_vat": 0, + "price": 1000, + "price_after_vat": 1000, "product": { "sku": "test", "external_identifier": "PDK-3", @@ -143,8 +143,8 @@ "order_lines": [ { "quantity": 1, - "price": 0, - "price_after_vat": 0, + "price": 1000, + "price_after_vat": 1000, "product": { "sku": "test", "external_identifier": "PDK-4", diff --git a/tests/__snapshots__/ExportOrderActionTest__it_exports_order_with_data_set_order_mode__data_set_export_signature__data_set_carrier_dhl_for_you__1.json b/tests/__snapshots__/ExportOrderActionTest__it_exports_order_with_data_set_order_mode__data_set_export_signature__data_set_carrier_dhl_for_you__1.json index 9fa591d8a..53dbdbeb7 100644 --- a/tests/__snapshots__/ExportOrderActionTest__it_exports_order_with_data_set_order_mode__data_set_export_signature__data_set_carrier_dhl_for_you__1.json +++ b/tests/__snapshots__/ExportOrderActionTest__it_exports_order_with_data_set_order_mode__data_set_export_signature__data_set_carrier_dhl_for_you__1.json @@ -16,8 +16,8 @@ "order_lines": [ { "quantity": 1, - "price": 0, - "price_after_vat": 0, + "price": 1000, + "price_after_vat": 1000, "product": { "sku": "test", "external_identifier": "PDK-1", diff --git a/tests/__snapshots__/ExportOrderActionTest__it_exports_order_with_data_set_order_mode__data_set_export_signature__data_set_single_order__1.json b/tests/__snapshots__/ExportOrderActionTest__it_exports_order_with_data_set_order_mode__data_set_export_signature__data_set_single_order__1.json index 7a596d1e6..333180869 100644 --- a/tests/__snapshots__/ExportOrderActionTest__it_exports_order_with_data_set_order_mode__data_set_export_signature__data_set_single_order__1.json +++ b/tests/__snapshots__/ExportOrderActionTest__it_exports_order_with_data_set_order_mode__data_set_export_signature__data_set_single_order__1.json @@ -16,8 +16,8 @@ "order_lines": [ { "quantity": 1, - "price": 0, - "price_after_vat": 0, + "price": 1000, + "price_after_vat": 1000, "product": { "sku": "test", "external_identifier": "PDK-1", diff --git a/tests/__snapshots__/ExportOrderActionTest__it_exports_order_with_data_set_order_mode__data_set_export_signature__data_set_various_delivery_options__1.json b/tests/__snapshots__/ExportOrderActionTest__it_exports_order_with_data_set_order_mode__data_set_export_signature__data_set_various_delivery_options__1.json index 164490296..e87d6fcdc 100644 --- a/tests/__snapshots__/ExportOrderActionTest__it_exports_order_with_data_set_order_mode__data_set_export_signature__data_set_various_delivery_options__1.json +++ b/tests/__snapshots__/ExportOrderActionTest__it_exports_order_with_data_set_order_mode__data_set_export_signature__data_set_various_delivery_options__1.json @@ -16,8 +16,8 @@ "order_lines": [ { "quantity": 5, - "price": 0, - "price_after_vat": 0, + "price": 1000, + "price_after_vat": 1000, "product": { "sku": "test", "external_identifier": "PDK-2", @@ -79,8 +79,8 @@ "order_lines": [ { "quantity": 1, - "price": 0, - "price_after_vat": 0, + "price": 1000, + "price_after_vat": 1000, "product": { "sku": "test", "external_identifier": "PDK-3", @@ -143,8 +143,8 @@ "order_lines": [ { "quantity": 1, - "price": 0, - "price_after_vat": 0, + "price": 1000, + "price_after_vat": 1000, "product": { "sku": "test", "external_identifier": "PDK-4", diff --git a/tests/__snapshots__/ExportReturnActionTest__it_exports_return_with_data_set_insurance__1.json b/tests/__snapshots__/ExportReturnActionTest__it_exports_return_with_data_set_insurance__1.json index 94294cff6..aa2fba800 100644 --- a/tests/__snapshots__/ExportReturnActionTest__it_exports_return_with_data_set_insurance__1.json +++ b/tests/__snapshots__/ExportReturnActionTest__it_exports_return_with_data_set_insurance__1.json @@ -206,9 +206,9 @@ "lines": [ { "quantity": 1, - "price": 0, + "price": 1000, "vat": 0, - "priceAfterVat": 0, + "priceAfterVat": 1000, "product": { "externalIdentifier": "PDK-1", "sku": "test", @@ -267,12 +267,12 @@ "shipmentPrice": 100, "shipmentPriceAfterVat": 121, "shipmentVat": 21, - "orderPrice": 0, - "orderPriceAfterVat": 0, + "orderPrice": 1000, + "orderPriceAfterVat": 1000, "orderVat": 0, - "totalPrice": 100, + "totalPrice": 1100, "totalVat": 21, - "totalPriceAfterVat": 121, + "totalPriceAfterVat": 1121, "audits": [] }, { diff --git a/tests/__snapshots__/ExportReturnActionTest__it_exports_return_with_data_set_no_return_capabilities__1.json b/tests/__snapshots__/ExportReturnActionTest__it_exports_return_with_data_set_no_return_capabilities__1.json index fe1fcc333..198ed4556 100644 --- a/tests/__snapshots__/ExportReturnActionTest__it_exports_return_with_data_set_no_return_capabilities__1.json +++ b/tests/__snapshots__/ExportReturnActionTest__it_exports_return_with_data_set_no_return_capabilities__1.json @@ -206,9 +206,9 @@ "lines": [ { "quantity": 1, - "price": 0, + "price": 1000, "vat": 0, - "priceAfterVat": 0, + "priceAfterVat": 1000, "product": { "externalIdentifier": "PDK-1", "sku": "test", @@ -267,12 +267,12 @@ "shipmentPrice": 100, "shipmentPriceAfterVat": 121, "shipmentVat": 21, - "orderPrice": 0, - "orderPriceAfterVat": 0, + "orderPrice": 1000, + "orderPriceAfterVat": 1000, "orderVat": 0, - "totalPrice": 100, + "totalPrice": 1100, "totalVat": 21, - "totalPriceAfterVat": 121, + "totalPriceAfterVat": 1121, "audits": [] }, { diff --git a/tests/__snapshots__/ExportReturnActionTest__it_exports_return_with_data_set_simple_orders__1.json b/tests/__snapshots__/ExportReturnActionTest__it_exports_return_with_data_set_simple_orders__1.json index c139ff696..98ddf5c9b 100644 --- a/tests/__snapshots__/ExportReturnActionTest__it_exports_return_with_data_set_simple_orders__1.json +++ b/tests/__snapshots__/ExportReturnActionTest__it_exports_return_with_data_set_simple_orders__1.json @@ -206,9 +206,9 @@ "lines": [ { "quantity": 1, - "price": 0, + "price": 1000, "vat": 0, - "priceAfterVat": 0, + "priceAfterVat": 1000, "product": { "externalIdentifier": "PDK-1", "sku": "test", @@ -267,12 +267,12 @@ "shipmentPrice": 100, "shipmentPriceAfterVat": 121, "shipmentVat": 21, - "orderPrice": 0, - "orderPriceAfterVat": 0, + "orderPrice": 1000, + "orderPriceAfterVat": 1000, "orderVat": 0, - "totalPrice": 100, + "totalPrice": 1100, "totalVat": 21, - "totalPriceAfterVat": 121, + "totalPriceAfterVat": 1121, "audits": [] }, { @@ -371,9 +371,9 @@ "lines": [ { "quantity": 1, - "price": 0, + "price": 1000, "vat": 0, - "priceAfterVat": 0, + "priceAfterVat": 1000, "product": { "externalIdentifier": "PDK-2", "sku": "test", @@ -432,12 +432,12 @@ "shipmentPrice": 100, "shipmentPriceAfterVat": 121, "shipmentVat": 21, - "orderPrice": 0, - "orderPriceAfterVat": 0, + "orderPrice": 1000, + "orderPriceAfterVat": 1000, "orderVat": 0, - "totalPrice": 100, + "totalPrice": 1100, "totalVat": 21, - "totalPriceAfterVat": 121, + "totalPriceAfterVat": 1121, "audits": [] } ] diff --git a/tests/__snapshots__/OrderTest__it_creates_fulfilment_order_from_pdk_order_with_data_set_order_to_germany__1.json b/tests/__snapshots__/OrderTest__it_creates_fulfilment_order_from_pdk_order_with_data_set_order_to_germany__1.json new file mode 100644 index 000000000..1475990f2 --- /dev/null +++ b/tests/__snapshots__/OrderTest__it_creates_fulfilment_order_from_pdk_order_with_data_set_order_to_germany__1.json @@ -0,0 +1,96 @@ +{ + "externalIdentifier": "PDK-1", + "invoiceAddress": { + "address1": "Antareslaan 31", + "cc": "NL", + "city": "Hoofddorp", + "postalCode": "2132 JE", + "email": "support@myparcel.nl", + "person": "Felicia Parcel", + "company": "MyParcel" + }, + "language": "nl", + "orderDate": "2030-01-01 12:00:00", + "lines": [ + { + "quantity": 3, + "price": 300, + "vat": 27, + "priceAfterVat": 327, + "product": { + "sku": "sku-1", + "ean": "ean-1", + "externalIdentifier": "product-1", + "name": "product-name (1)", + "width": 10, + "length": 10, + "height": 10, + "weight": 10 + } + }, + { + "quantity": 1, + "price": 300, + "vat": 63, + "priceAfterVat": 363, + "product": { + "sku": "sku-2", + "ean": "ean-2", + "externalIdentifier": "product-2", + "name": "product-name (2)", + "width": 10, + "length": 10, + "height": 10, + "weight": 10 + } + }, + { + "quantity": 6, + "price": 1800, + "vat": 378, + "priceAfterVat": 2178, + "product": { + "sku": "sku-3", + "ean": "ean-3", + "externalIdentifier": "product-3", + "name": "product-name (3)", + "width": 10, + "length": 10, + "height": 10, + "weight": 10 + } + } + ], + "notes": [], + "shipment": { + "carrier": 1, + "options": { + "ageCheck": false, + "deliveryType": 2, + "hideSender": false, + "insurance": 0, + "labelDescription": "", + "largeFormat": false, + "onlyRecipient": false, + "packageType": 1, + "return": false, + "sameDayDelivery": false, + "signature": false + }, + "recipient": { + "address1": "Musterstrasse 1", + "cc": "DE", + "city": "Berlin", + "postalCode": "10117", + "email": "support@myparcel.nl", + "person": "Felicia Parcel", + "company": "MyParcel" + }, + "physicalProperties": { + "weight": 100 + } + }, + "price": 12000, + "vat": 2412, + "priceAfterVat": 14412 +} diff --git a/tests/__snapshots__/OrderTest__it_creates_fulfilment_order_from_pdk_order_with_data_set_order_to_pickup_location__1.json b/tests/__snapshots__/OrderTest__it_creates_fulfilment_order_from_pdk_order_with_data_set_order_to_pickup_location__1.json new file mode 100644 index 000000000..3ba9350ce --- /dev/null +++ b/tests/__snapshots__/OrderTest__it_creates_fulfilment_order_from_pdk_order_with_data_set_order_to_pickup_location__1.json @@ -0,0 +1,106 @@ +{ + "externalIdentifier": "PDK-1", + "invoiceAddress": { + "address1": "Antareslaan 31", + "cc": "NL", + "city": "Hoofddorp", + "postalCode": "2132 JE", + "email": "support@myparcel.nl", + "person": "Felicia Parcel", + "company": "MyParcel" + }, + "language": "nl", + "orderDate": "2030-01-01 12:00:00", + "lines": [ + { + "quantity": 3, + "price": 300, + "vat": 27, + "priceAfterVat": 327, + "product": { + "sku": "sku-1", + "ean": "ean-1", + "externalIdentifier": "product-1", + "name": "product-name (1)", + "width": 10, + "length": 10, + "height": 10, + "weight": 10 + } + }, + { + "quantity": 1, + "price": 300, + "vat": 63, + "priceAfterVat": 363, + "product": { + "sku": "sku-2", + "ean": "ean-2", + "externalIdentifier": "product-2", + "name": "product-name (2)", + "width": 10, + "length": 10, + "height": 10, + "weight": 10 + } + }, + { + "quantity": 6, + "price": 1800, + "vat": 378, + "priceAfterVat": 2178, + "product": { + "sku": "sku-3", + "ean": "ean-3", + "externalIdentifier": "product-3", + "name": "product-name (3)", + "width": 10, + "length": 10, + "height": 10, + "weight": 10 + } + } + ], + "notes": [], + "shipment": { + "carrier": 1, + "options": { + "ageCheck": false, + "deliveryType": 4, + "hideSender": false, + "insurance": 0, + "labelDescription": "", + "largeFormat": false, + "onlyRecipient": false, + "packageType": 1, + "return": false, + "sameDayDelivery": false, + "signature": false + }, + "pickup": { + "locationCode": "215795", + "locationName": "Phone House Aalsmeer", + "retailNetworkId": "PNPNL-01", + "cc": "NL", + "city": "AALSMEER", + "number": "38", + "postalCode": "1431ED", + "street": "Zijdstraat" + }, + "recipient": { + "address1": "Antareslaan 31", + "cc": "NL", + "city": "Hoofddorp", + "postalCode": "2132 JE", + "email": "support@myparcel.nl", + "person": "Felicia Parcel", + "company": "MyParcel" + }, + "physicalProperties": { + "weight": 100 + } + }, + "price": 12000, + "vat": 2412, + "priceAfterVat": 14412 +} diff --git a/tests/__snapshots__/OrderTest__it_creates_fulfilment_order_from_pdk_order_with_data_set_order_with_delivery_options__1.json b/tests/__snapshots__/OrderTest__it_creates_fulfilment_order_from_pdk_order_with_data_set_order_with_delivery_options__1.json new file mode 100644 index 000000000..ae406d0cf --- /dev/null +++ b/tests/__snapshots__/OrderTest__it_creates_fulfilment_order_from_pdk_order_with_data_set_order_with_delivery_options__1.json @@ -0,0 +1,96 @@ +{ + "externalIdentifier": "PDK-1", + "invoiceAddress": { + "address1": "Antareslaan 31", + "cc": "NL", + "city": "Hoofddorp", + "postalCode": "2132 JE", + "email": "support@myparcel.nl", + "person": "Felicia Parcel", + "company": "MyParcel" + }, + "language": "nl", + "orderDate": "2030-01-01 12:00:00", + "lines": [ + { + "quantity": 3, + "price": 300, + "vat": 27, + "priceAfterVat": 327, + "product": { + "sku": "sku-1", + "ean": "ean-1", + "externalIdentifier": "product-1", + "name": "product-name (1)", + "width": 10, + "length": 10, + "height": 10, + "weight": 10 + } + }, + { + "quantity": 1, + "price": 300, + "vat": 63, + "priceAfterVat": 363, + "product": { + "sku": "sku-2", + "ean": "ean-2", + "externalIdentifier": "product-2", + "name": "product-name (2)", + "width": 10, + "length": 10, + "height": 10, + "weight": 10 + } + }, + { + "quantity": 6, + "price": 1800, + "vat": 378, + "priceAfterVat": 2178, + "product": { + "sku": "sku-3", + "ean": "ean-3", + "externalIdentifier": "product-3", + "name": "product-name (3)", + "width": 10, + "length": 10, + "height": 10, + "weight": 10 + } + } + ], + "notes": [], + "shipment": { + "carrier": 1, + "options": { + "ageCheck": true, + "deliveryType": 2, + "hideSender": true, + "insurance": 100, + "labelDescription": "test", + "largeFormat": true, + "onlyRecipient": true, + "packageType": 1, + "return": true, + "sameDayDelivery": true, + "signature": true + }, + "recipient": { + "address1": "Antareslaan 31", + "cc": "NL", + "city": "Hoofddorp", + "postalCode": "2132 JE", + "email": "support@myparcel.nl", + "person": "Felicia Parcel", + "company": "MyParcel" + }, + "physicalProperties": { + "weight": 100 + } + }, + "price": 12000, + "vat": 2412, + "priceAfterVat": 14412 +} diff --git a/tests/__snapshots__/OrderTest__it_creates_fulfilment_order_from_pdk_order_with_data_set_simple_order__1.json b/tests/__snapshots__/OrderTest__it_creates_fulfilment_order_from_pdk_order_with_data_set_simple_order__1.json new file mode 100644 index 000000000..8e15e8315 --- /dev/null +++ b/tests/__snapshots__/OrderTest__it_creates_fulfilment_order_from_pdk_order_with_data_set_simple_order__1.json @@ -0,0 +1,96 @@ +{ + "externalIdentifier": "PDK-1", + "invoiceAddress": { + "address1": "Antareslaan 31", + "cc": "NL", + "city": "Hoofddorp", + "postalCode": "2132 JE", + "email": "support@myparcel.nl", + "person": "Felicia Parcel", + "company": "MyParcel" + }, + "language": "nl", + "orderDate": "2030-01-01 12:00:00", + "lines": [ + { + "quantity": 3, + "price": 300, + "vat": 27, + "priceAfterVat": 327, + "product": { + "sku": "sku-1", + "ean": "ean-1", + "externalIdentifier": "product-1", + "name": "product-name (1)", + "width": 10, + "length": 10, + "height": 10, + "weight": 10 + } + }, + { + "quantity": 1, + "price": 300, + "vat": 63, + "priceAfterVat": 363, + "product": { + "sku": "sku-2", + "ean": "ean-2", + "externalIdentifier": "product-2", + "name": "product-name (2)", + "width": 10, + "length": 10, + "height": 10, + "weight": 10 + } + }, + { + "quantity": 6, + "price": 1800, + "vat": 378, + "priceAfterVat": 2178, + "product": { + "sku": "sku-3", + "ean": "ean-3", + "externalIdentifier": "product-3", + "name": "product-name (3)", + "width": 10, + "length": 10, + "height": 10, + "weight": 10 + } + } + ], + "notes": [], + "shipment": { + "carrier": 1, + "options": { + "ageCheck": false, + "deliveryType": 2, + "hideSender": false, + "insurance": 0, + "labelDescription": "", + "largeFormat": false, + "onlyRecipient": false, + "packageType": 1, + "return": false, + "sameDayDelivery": false, + "signature": false + }, + "recipient": { + "address1": "Antareslaan 31", + "cc": "NL", + "city": "Hoofddorp", + "postalCode": "2132 JE", + "email": "support@myparcel.nl", + "person": "Felicia Parcel", + "company": "MyParcel" + }, + "physicalProperties": { + "weight": 100 + } + }, + "price": 12000, + "vat": 2412, + "priceAfterVat": 14412 +} diff --git a/tests/__snapshots__/PostOrdersTest__it_creates_a_valid_order_collection_from_api_data_with_data_set_one_order_containing_many_attributes__1.json b/tests/__snapshots__/PostOrdersTest__it_creates_a_valid_order_collection_from_api_data_with_data_set_one_order_containing_many_attributes__1.json index 2b753d941..cae1f5ca4 100644 --- a/tests/__snapshots__/PostOrdersTest__it_creates_a_valid_order_collection_from_api_data_with_data_set_one_order_containing_many_attributes__1.json +++ b/tests/__snapshots__/PostOrdersTest__it_creates_a_valid_order_collection_from_api_data_with_data_set_one_order_containing_many_attributes__1.json @@ -1,30 +1,11 @@ [ { "uuid": "123", - "orderDate": "2022-08-22 00:00:00", - "lines": [ - { - "uuid": "1234", - "quantity": 1, - "price": 250, - "vat": 10, - "priceAfterVat": 260, - "product": { - "uuid": "12345", - "sku": "018234", - "ean": "018234", - "externalIdentifier": "018234", - "name": "Paarse stofzuiger", - "description": "Een paars object waarmee stof opgezogen kan worden", - "width": 0, - "length": 0, - "height": 0, - "weight": 3500 - } - } - ], + "invoiceAddress": [], + "lines": [], "notes": [], "shipment": { + "orderId": "123", "carrier": 1, "customsDeclaration": { "contents": 1, diff --git a/tests/__snapshots__/PostOrdersTest__it_creates_a_valid_order_collection_from_api_data_with_data_set_one_order_with_pickup__1.json b/tests/__snapshots__/PostOrdersTest__it_creates_a_valid_order_collection_from_api_data_with_data_set_one_order_with_pickup__1.json index 2b753d941..cae1f5ca4 100644 --- a/tests/__snapshots__/PostOrdersTest__it_creates_a_valid_order_collection_from_api_data_with_data_set_one_order_with_pickup__1.json +++ b/tests/__snapshots__/PostOrdersTest__it_creates_a_valid_order_collection_from_api_data_with_data_set_one_order_with_pickup__1.json @@ -1,30 +1,11 @@ [ { "uuid": "123", - "orderDate": "2022-08-22 00:00:00", - "lines": [ - { - "uuid": "1234", - "quantity": 1, - "price": 250, - "vat": 10, - "priceAfterVat": 260, - "product": { - "uuid": "12345", - "sku": "018234", - "ean": "018234", - "externalIdentifier": "018234", - "name": "Paarse stofzuiger", - "description": "Een paars object waarmee stof opgezogen kan worden", - "width": 0, - "length": 0, - "height": 0, - "weight": 3500 - } - } - ], + "invoiceAddress": [], + "lines": [], "notes": [], "shipment": { + "orderId": "123", "carrier": 1, "customsDeclaration": { "contents": 1, diff --git a/tests/__snapshots__/QueryTest__it_creates_order_collection_from_queried_data__1.json b/tests/__snapshots__/QueryTest__it_creates_order_collection_from_queried_data__1.json index 2b96a335e..0167f5295 100644 --- a/tests/__snapshots__/QueryTest__it_creates_order_collection_from_queried_data__1.json +++ b/tests/__snapshots__/QueryTest__it_creates_order_collection_from_queried_data__1.json @@ -6,7 +6,7 @@ "accountId": 123456, "dropOffPoint": null, "invoiceAddress": { - "address1": null, + "address1": "Antareslaan 31", "address2": null, "area": null, "cc": "NL", diff --git a/tests/__snapshots__/SaveOrderTest__it_creates_a_valid_order_collection_from_api_data_with_data_set_order_containing_many_attributes__1.json b/tests/__snapshots__/SaveOrderTest__it_creates_a_valid_order_collection_from_api_data_with_data_set_order_containing_many_attributes__1.json index 2b753d941..cae1f5ca4 100644 --- a/tests/__snapshots__/SaveOrderTest__it_creates_a_valid_order_collection_from_api_data_with_data_set_order_containing_many_attributes__1.json +++ b/tests/__snapshots__/SaveOrderTest__it_creates_a_valid_order_collection_from_api_data_with_data_set_order_containing_many_attributes__1.json @@ -1,30 +1,11 @@ [ { "uuid": "123", - "orderDate": "2022-08-22 00:00:00", - "lines": [ - { - "uuid": "1234", - "quantity": 1, - "price": 250, - "vat": 10, - "priceAfterVat": 260, - "product": { - "uuid": "12345", - "sku": "018234", - "ean": "018234", - "externalIdentifier": "018234", - "name": "Paarse stofzuiger", - "description": "Een paars object waarmee stof opgezogen kan worden", - "width": 0, - "length": 0, - "height": 0, - "weight": 3500 - } - } - ], + "invoiceAddress": [], + "lines": [], "notes": [], "shipment": { + "orderId": "123", "carrier": 1, "customsDeclaration": { "contents": 1, diff --git a/tests/__snapshots__/SaveOrderTest__it_creates_a_valid_order_collection_from_api_data_with_data_set_order_with_pickup__1.json b/tests/__snapshots__/SaveOrderTest__it_creates_a_valid_order_collection_from_api_data_with_data_set_order_with_pickup__1.json index 2b753d941..cae1f5ca4 100644 --- a/tests/__snapshots__/SaveOrderTest__it_creates_a_valid_order_collection_from_api_data_with_data_set_order_with_pickup__1.json +++ b/tests/__snapshots__/SaveOrderTest__it_creates_a_valid_order_collection_from_api_data_with_data_set_order_with_pickup__1.json @@ -1,30 +1,11 @@ [ { "uuid": "123", - "orderDate": "2022-08-22 00:00:00", - "lines": [ - { - "uuid": "1234", - "quantity": 1, - "price": 250, - "vat": 10, - "priceAfterVat": 260, - "product": { - "uuid": "12345", - "sku": "018234", - "ean": "018234", - "externalIdentifier": "018234", - "name": "Paarse stofzuiger", - "description": "Een paars object waarmee stof opgezogen kan worden", - "width": 0, - "length": 0, - "height": 0, - "weight": 3500 - } - } - ], + "invoiceAddress": [], + "lines": [], "notes": [], "shipment": { + "orderId": "123", "carrier": 1, "customsDeclaration": { "contents": 1, diff --git a/tests/__snapshots__/ValidationTest__it_validates_order_with_data_set_BE_mailbox__1.json b/tests/__snapshots__/ValidationTest__it_validates_order_with_data_set_BE_mailbox__1.json index fb63156f2..9f6696a4d 100644 --- a/tests/__snapshots__/ValidationTest__it_validates_order_with_data_set_BE_mailbox__1.json +++ b/tests/__snapshots__/ValidationTest__it_validates_order_with_data_set_BE_mailbox__1.json @@ -1,9 +1,7 @@ { - "0.property": "deliveryOptions.packageType", - "0.pointer": "/deliveryOptions/packageType", - "0.message": "Does not have a value in the enumeration [\"letter\",\"package\"]", - "0.constraint": "enum", - "0.context": 1, - "0.enum.0": "letter", - "0.enum.1": "package" + "0.property": "shippingAddress.cc", + "0.pointer": "/shippingAddress/cc", + "0.message": "The property cc is required", + "0.constraint": "required", + "0.context": 1 } diff --git a/tests/__snapshots__/ValidationTest__it_validates_order_with_data_set_BE_small_package__1.json b/tests/__snapshots__/ValidationTest__it_validates_order_with_data_set_BE_small_package__1.json new file mode 100644 index 000000000..9f6696a4d --- /dev/null +++ b/tests/__snapshots__/ValidationTest__it_validates_order_with_data_set_BE_small_package__1.json @@ -0,0 +1,7 @@ +{ + "0.property": "shippingAddress.cc", + "0.pointer": "/shippingAddress/cc", + "0.message": "The property cc is required", + "0.constraint": "required", + "0.context": 1 +} diff --git a/tests/__snapshots__/ValidationTest__it_validates_order_with_data_set_EU_package_with_correct_insurance__1.json b/tests/__snapshots__/ValidationTest__it_validates_order_with_data_set_EU_package_with_correct_insurance__1.json index a2649d489..9f6696a4d 100644 --- a/tests/__snapshots__/ValidationTest__it_validates_order_with_data_set_EU_package_with_correct_insurance__1.json +++ b/tests/__snapshots__/ValidationTest__it_validates_order_with_data_set_EU_package_with_correct_insurance__1.json @@ -1,20 +1,7 @@ { - "0.property": "deliveryOptions.shipmentOptions.signature", - "0.pointer": "/deliveryOptions/shipmentOptions/signature", - "0.message": "Does not have a value in the enumeration [1]", - "0.constraint": "enum", - "0.context": 1, - "0.enum.0": 1, - "1.property": "deliveryOptions.shipmentOptions.insurance", - "1.pointer": "/deliveryOptions/shipmentOptions/insurance", - "1.message": "Does not have a value in the enumeration [0,null]", - "1.constraint": "enum", - "1.context": 1, - "1.enum.0": 0, - "1.enum.1": null, - "2.property": "", - "2.pointer": "", - "2.message": "Failed to match at least one schema", - "2.constraint": "anyOf", - "2.context": 1 + "0.property": "shippingAddress.cc", + "0.pointer": "/shippingAddress/cc", + "0.message": "The property cc is required", + "0.constraint": "required", + "0.context": 1 } diff --git a/tests/__snapshots__/ValidationTest__it_validates_order_with_data_set_EU_package_with_no_weight__1.json b/tests/__snapshots__/ValidationTest__it_validates_order_with_data_set_EU_package_with_no_weight__1.json index a2649d489..9f6696a4d 100644 --- a/tests/__snapshots__/ValidationTest__it_validates_order_with_data_set_EU_package_with_no_weight__1.json +++ b/tests/__snapshots__/ValidationTest__it_validates_order_with_data_set_EU_package_with_no_weight__1.json @@ -1,20 +1,7 @@ { - "0.property": "deliveryOptions.shipmentOptions.signature", - "0.pointer": "/deliveryOptions/shipmentOptions/signature", - "0.message": "Does not have a value in the enumeration [1]", - "0.constraint": "enum", - "0.context": 1, - "0.enum.0": 1, - "1.property": "deliveryOptions.shipmentOptions.insurance", - "1.pointer": "/deliveryOptions/shipmentOptions/insurance", - "1.message": "Does not have a value in the enumeration [0,null]", - "1.constraint": "enum", - "1.context": 1, - "1.enum.0": 0, - "1.enum.1": null, - "2.property": "", - "2.pointer": "", - "2.message": "Failed to match at least one schema", - "2.constraint": "anyOf", - "2.context": 1 + "0.property": "shippingAddress.cc", + "0.pointer": "/shippingAddress/cc", + "0.message": "The property cc is required", + "0.constraint": "required", + "0.context": 1 } diff --git a/tests/__snapshots__/ValidationTest__it_validates_order_with_data_set_EU_package_without_insurance__1.json b/tests/__snapshots__/ValidationTest__it_validates_order_with_data_set_EU_package_without_insurance__1.json new file mode 100644 index 000000000..9f6696a4d --- /dev/null +++ b/tests/__snapshots__/ValidationTest__it_validates_order_with_data_set_EU_package_without_insurance__1.json @@ -0,0 +1,7 @@ +{ + "0.property": "shippingAddress.cc", + "0.pointer": "/shippingAddress/cc", + "0.message": "The property cc is required", + "0.constraint": "required", + "0.context": 1 +} diff --git a/tests/__snapshots__/ValidationTest__it_validates_order_with_data_set_ROW_package__1.json b/tests/__snapshots__/ValidationTest__it_validates_order_with_data_set_ROW_package__1.json index 7aff8dd4e..9f6696a4d 100644 --- a/tests/__snapshots__/ValidationTest__it_validates_order_with_data_set_ROW_package__1.json +++ b/tests/__snapshots__/ValidationTest__it_validates_order_with_data_set_ROW_package__1.json @@ -1,36 +1,7 @@ { - "0.property": "deliveryOptions.shipmentOptions.insurance", - "0.pointer": "/deliveryOptions/shipmentOptions/insurance", - "0.message": "Does not have a value in the enumeration [5000,50000]", - "0.constraint": "enum", - "0.context": 1, - "0.enum.0": 5000, - "0.enum.1": 50000, - "1.property": "deliveryOptions.shipmentOptions.signature", - "1.pointer": "/deliveryOptions/shipmentOptions/signature", - "1.message": "Does not have a value in the enumeration [1]", - "1.constraint": "enum", - "1.context": 1, - "1.enum.0": 1, - "2.property": "deliveryOptions.shipmentOptions.insurance", - "2.pointer": "/deliveryOptions/shipmentOptions/insurance", - "2.message": "Does not have a value in the enumeration [0,null]", - "2.constraint": "enum", - "2.context": 1, - "2.enum.0": 0, - "2.enum.1": null, - "3.property": "", - "3.pointer": "", - "3.message": "Failed to match at least one schema", - "3.constraint": "anyOf", - "3.context": 1, - "4.property": "deliveryOptions.shipmentOptions.insurance", - "4.pointer": "/deliveryOptions/shipmentOptions/insurance", - "4.message": "Does not have a value in the enumeration [0,5000,50000,null]", - "4.constraint": "enum", - "4.context": 1, - "4.enum.0": 0, - "4.enum.1": 5000, - "4.enum.2": 50000, - "4.enum.3": null + "0.property": "shippingAddress.cc", + "0.pointer": "/shippingAddress/cc", + "0.message": "The property cc is required", + "0.constraint": "required", + "0.context": 1 } diff --git a/tests/__snapshots__/ValidationTest__it_validates_order_with_data_set_ROW_package_without_weight,_without_invoice__1.json b/tests/__snapshots__/ValidationTest__it_validates_order_with_data_set_ROW_package_without_weight,_without_invoice__1.json index 43d9e3e57..9f6696a4d 100644 --- a/tests/__snapshots__/ValidationTest__it_validates_order_with_data_set_ROW_package_without_weight,_without_invoice__1.json +++ b/tests/__snapshots__/ValidationTest__it_validates_order_with_data_set_ROW_package_without_weight,_without_invoice__1.json @@ -1,41 +1,7 @@ { - "0.property": "customsDeclaration", - "0.pointer": "/customsDeclaration", - "0.message": "The property customsDeclaration is required", + "0.property": "shippingAddress.cc", + "0.pointer": "/shippingAddress/cc", + "0.message": "The property cc is required", "0.constraint": "required", - "0.context": 1, - "1.property": "deliveryOptions.shipmentOptions.insurance", - "1.pointer": "/deliveryOptions/shipmentOptions/insurance", - "1.message": "Does not have a value in the enumeration [5000,50000]", - "1.constraint": "enum", - "1.context": 1, - "1.enum.0": 5000, - "1.enum.1": 50000, - "2.property": "deliveryOptions.shipmentOptions.signature", - "2.pointer": "/deliveryOptions/shipmentOptions/signature", - "2.message": "Does not have a value in the enumeration [1]", - "2.constraint": "enum", - "2.context": 1, - "2.enum.0": 1, - "3.property": "deliveryOptions.shipmentOptions.insurance", - "3.pointer": "/deliveryOptions/shipmentOptions/insurance", - "3.message": "Does not have a value in the enumeration [0,null]", - "3.constraint": "enum", - "3.context": 1, - "3.enum.0": 0, - "3.enum.1": null, - "4.property": "", - "4.pointer": "", - "4.message": "Failed to match at least one schema", - "4.constraint": "anyOf", - "4.context": 1, - "5.property": "deliveryOptions.shipmentOptions.insurance", - "5.pointer": "/deliveryOptions/shipmentOptions/insurance", - "5.message": "Does not have a value in the enumeration [0,5000,50000,null]", - "5.constraint": "enum", - "5.context": 1, - "5.enum.0": 0, - "5.enum.1": 5000, - "5.enum.2": 50000, - "5.enum.3": null + "0.context": 1 } diff --git a/tests/__snapshots__/ValidationTest__it_validates_order_with_data_set_Small_packets_not_NL_tracked__1.json b/tests/__snapshots__/ValidationTest__it_validates_order_with_data_set_Small_packets_not_NL_tracked__1.json index 2c02db4a2..9f6696a4d 100644 --- a/tests/__snapshots__/ValidationTest__it_validates_order_with_data_set_Small_packets_not_NL_tracked__1.json +++ b/tests/__snapshots__/ValidationTest__it_validates_order_with_data_set_Small_packets_not_NL_tracked__1.json @@ -1,8 +1,7 @@ { - "0.property": "deliveryOptions.shipmentOptions.tracked", - "0.pointer": "/deliveryOptions/shipmentOptions/tracked", - "0.message": "Does not have a value in the enumeration [1]", - "0.constraint": "enum", - "0.context": 1, - "0.enum.0": 1 + "0.property": "shippingAddress.cc", + "0.pointer": "/shippingAddress/cc", + "0.message": "The property cc is required", + "0.constraint": "required", + "0.context": 1 } diff --git a/tests/__snapshots__/ValidationTest__it_validates_order_with_data_set_allows_property_tracked__1.json b/tests/__snapshots__/ValidationTest__it_validates_order_with_data_set_allows_property_tracked__1.json new file mode 100644 index 000000000..9f6696a4d --- /dev/null +++ b/tests/__snapshots__/ValidationTest__it_validates_order_with_data_set_allows_property_tracked__1.json @@ -0,0 +1,7 @@ +{ + "0.property": "shippingAddress.cc", + "0.pointer": "/shippingAddress/cc", + "0.message": "The property cc is required", + "0.constraint": "required", + "0.context": 1 +} diff --git a/tests/__snapshots__/ValidationTest__it_validates_order_with_data_set_dhlforyou_to_France__1.json b/tests/__snapshots__/ValidationTest__it_validates_order_with_data_set_dhlforyou_to_France__1.json new file mode 100644 index 000000000..9f6696a4d --- /dev/null +++ b/tests/__snapshots__/ValidationTest__it_validates_order_with_data_set_dhlforyou_to_France__1.json @@ -0,0 +1,7 @@ +{ + "0.property": "shippingAddress.cc", + "0.pointer": "/shippingAddress/cc", + "0.message": "The property cc is required", + "0.constraint": "required", + "0.context": 1 +} diff --git a/tests/__snapshots__/ValidationTest__it_validates_order_with_data_set_mailbox_with_morning_delivery__1.json b/tests/__snapshots__/ValidationTest__it_validates_order_with_data_set_mailbox_with_morning_delivery__1.json index c6801660b..9f6696a4d 100644 --- a/tests/__snapshots__/ValidationTest__it_validates_order_with_data_set_mailbox_with_morning_delivery__1.json +++ b/tests/__snapshots__/ValidationTest__it_validates_order_with_data_set_mailbox_with_morning_delivery__1.json @@ -1,9 +1,7 @@ { - "0.property": "deliveryOptions.deliveryType", - "0.pointer": "/deliveryOptions/deliveryType", - "0.message": "Does not have a value in the enumeration [\"standard\",null]", - "0.constraint": "enum", - "0.context": 1, - "0.enum.0": "standard", - "0.enum.1": null + "0.property": "shippingAddress.cc", + "0.pointer": "/shippingAddress/cc", + "0.message": "The property cc is required", + "0.constraint": "required", + "0.context": 1 } diff --git a/tests/__snapshots__/ValidationTest__it_validates_order_with_data_set_mailbox_with_shipmentOptions__1.json b/tests/__snapshots__/ValidationTest__it_validates_order_with_data_set_mailbox_with_shipmentOptions__1.json index 44d241783..9f6696a4d 100644 --- a/tests/__snapshots__/ValidationTest__it_validates_order_with_data_set_mailbox_with_shipmentOptions__1.json +++ b/tests/__snapshots__/ValidationTest__it_validates_order_with_data_set_mailbox_with_shipmentOptions__1.json @@ -1,8 +1,7 @@ { - "0.property": "deliveryOptions.shipmentOptions.signature", - "0.pointer": "/deliveryOptions/shipmentOptions/signature", - "0.message": "Does not have a value in the enumeration [0]", - "0.constraint": "enum", - "0.context": 1, - "0.enum.0": 0 + "0.property": "shippingAddress.cc", + "0.pointer": "/shippingAddress/cc", + "0.message": "The property cc is required", + "0.constraint": "required", + "0.context": 1 } diff --git a/tests/__snapshots__/ValidationTest__it_validates_order_with_data_set_morning_delivery_with_age_check__1.json b/tests/__snapshots__/ValidationTest__it_validates_order_with_data_set_morning_delivery_with_age_check__1.json index f1cfc644c..fc83358e7 100644 --- a/tests/__snapshots__/ValidationTest__it_validates_order_with_data_set_morning_delivery_with_age_check__1.json +++ b/tests/__snapshots__/ValidationTest__it_validates_order_with_data_set_morning_delivery_with_age_check__1.json @@ -26,5 +26,10 @@ "4.pointer": "", "4.message": "Failed to match all schemas", "4.constraint": "allOf", - "4.context": 1 + "4.context": 1, + "5.property": "shippingAddress.cc", + "5.pointer": "/shippingAddress/cc", + "5.message": "The property cc is required", + "5.constraint": "required", + "5.context": 1 } diff --git a/tests/__snapshots__/ValidationTest__it_validates_order_with_data_set_pickup_without_location_code__1.json b/tests/__snapshots__/ValidationTest__it_validates_order_with_data_set_pickup_without_location_code__1.json index 5254f04c7..658572147 100644 --- a/tests/__snapshots__/ValidationTest__it_validates_order_with_data_set_pickup_without_location_code__1.json +++ b/tests/__snapshots__/ValidationTest__it_validates_order_with_data_set_pickup_without_location_code__1.json @@ -1,22 +1,27 @@ { - "0.property": "deliveryOptions.pickupLocation.city", - "0.pointer": "/deliveryOptions/pickupLocation/city", - "0.message": "The property city is required", + "0.property": "shippingAddress.cc", + "0.pointer": "/shippingAddress/cc", + "0.message": "The property cc is required", "0.constraint": "required", "0.context": 1, - "1.property": "deliveryOptions.pickupLocation.locationName", - "1.pointer": "/deliveryOptions/pickupLocation/locationName", - "1.message": "The property locationName is required", + "1.property": "deliveryOptions.pickupLocation.city", + "1.pointer": "/deliveryOptions/pickupLocation/city", + "1.message": "The property city is required", "1.constraint": "required", "1.context": 1, - "2.property": "deliveryOptions.pickupLocation.postalCode", - "2.pointer": "/deliveryOptions/pickupLocation/postalCode", - "2.message": "The property postalCode is required", + "2.property": "deliveryOptions.pickupLocation.locationName", + "2.pointer": "/deliveryOptions/pickupLocation/locationName", + "2.message": "The property locationName is required", "2.constraint": "required", "2.context": 1, - "3.property": "deliveryOptions.pickupLocation.street", - "3.pointer": "/deliveryOptions/pickupLocation/street", - "3.message": "The property street is required", + "3.property": "deliveryOptions.pickupLocation.postalCode", + "3.pointer": "/deliveryOptions/pickupLocation/postalCode", + "3.message": "The property postalCode is required", "3.constraint": "required", - "3.context": 1 + "3.context": 1, + "4.property": "deliveryOptions.pickupLocation.street", + "4.pointer": "/deliveryOptions/pickupLocation/street", + "4.message": "The property street is required", + "4.constraint": "required", + "4.context": 1 } diff --git a/tests/__snapshots__/ValidationTest__it_validates_order_with_data_set_pickup_without_pickupLocation__1.json b/tests/__snapshots__/ValidationTest__it_validates_order_with_data_set_pickup_without_pickupLocation__1.json index 463f340df..de6a33f19 100644 --- a/tests/__snapshots__/ValidationTest__it_validates_order_with_data_set_pickup_without_pickupLocation__1.json +++ b/tests/__snapshots__/ValidationTest__it_validates_order_with_data_set_pickup_without_pickupLocation__1.json @@ -22,5 +22,10 @@ "3.pointer": "", "3.message": "Failed to match all schemas", "3.constraint": "allOf", - "3.context": 1 + "3.context": 1, + "4.property": "shippingAddress.cc", + "4.pointer": "/shippingAddress/cc", + "4.message": "The property cc is required", + "4.constraint": "required", + "4.context": 1 } diff --git a/tests/__snapshots__/ValidationTest__it_validates_order_with_data_set_postnl_non-standard_delivery_without_date__1.json b/tests/__snapshots__/ValidationTest__it_validates_order_with_data_set_postnl_non-standard_delivery_without_date__1.json index 9405b40b2..8724e4491 100644 --- a/tests/__snapshots__/ValidationTest__it_validates_order_with_data_set_postnl_non-standard_delivery_without_date__1.json +++ b/tests/__snapshots__/ValidationTest__it_validates_order_with_data_set_postnl_non-standard_delivery_without_date__1.json @@ -21,5 +21,10 @@ "3.pointer": "", "3.message": "Failed to match all schemas", "3.constraint": "allOf", - "3.context": 1 + "3.context": 1, + "4.property": "shippingAddress.cc", + "4.pointer": "/shippingAddress/cc", + "4.message": "The property cc is required", + "4.constraint": "required", + "4.context": 1 } diff --git a/tests/__snapshots__/ValidationTest__it_validates_order_with_data_set_postnl_with_same_day_delivery__1.json b/tests/__snapshots__/ValidationTest__it_validates_order_with_data_set_postnl_with_same_day_delivery__1.json index aa477deda..df9c41c6c 100644 --- a/tests/__snapshots__/ValidationTest__it_validates_order_with_data_set_postnl_with_same_day_delivery__1.json +++ b/tests/__snapshots__/ValidationTest__it_validates_order_with_data_set_postnl_with_same_day_delivery__1.json @@ -1,8 +1,13 @@ { - "0.property": "deliveryOptions.shipmentOptions.sameDayDelivery", - "0.pointer": "/deliveryOptions/shipmentOptions/sameDayDelivery", - "0.message": "Does not have a value in the enumeration [0]", - "0.constraint": "enum", + "0.property": "shippingAddress.cc", + "0.pointer": "/shippingAddress/cc", + "0.message": "The property cc is required", + "0.constraint": "required", "0.context": 1, - "0.enum.0": 0 + "1.property": "deliveryOptions.shipmentOptions.sameDayDelivery", + "1.pointer": "/deliveryOptions/shipmentOptions/sameDayDelivery", + "1.message": "Does not have a value in the enumeration [0]", + "1.constraint": "enum", + "1.context": 1, + "1.enum.0": 0 } diff --git a/tests/__snapshots__/ValidationTest__it_validates_order_with_data_set_weight_of_25kg__1.json b/tests/__snapshots__/ValidationTest__it_validates_order_with_data_set_weight_of_25kg__1.json new file mode 100644 index 000000000..9f6696a4d --- /dev/null +++ b/tests/__snapshots__/ValidationTest__it_validates_order_with_data_set_weight_of_25kg__1.json @@ -0,0 +1,7 @@ +{ + "0.property": "shippingAddress.cc", + "0.pointer": "/shippingAddress/cc", + "0.message": "The property cc is required", + "0.constraint": "required", + "0.context": 1 +} diff --git a/tests/__snapshots__/ValidationTest__it_validates_order_with_data_set_weight_of_29kg_with_large_format__1.json b/tests/__snapshots__/ValidationTest__it_validates_order_with_data_set_weight_of_29kg_with_large_format__1.json new file mode 100644 index 000000000..9f6696a4d --- /dev/null +++ b/tests/__snapshots__/ValidationTest__it_validates_order_with_data_set_weight_of_29kg_with_large_format__1.json @@ -0,0 +1,7 @@ +{ + "0.property": "shippingAddress.cc", + "0.pointer": "/shippingAddress/cc", + "0.message": "The property cc is required", + "0.constraint": "required", + "0.context": 1 +} diff --git a/tests/factories/App/Order/Model/PdkOrderLineFactory.php b/tests/factories/App/Order/Model/PdkOrderLineFactory.php index 549eb2122..7bebae512 100644 --- a/tests/factories/App/Order/Model/PdkOrderLineFactory.php +++ b/tests/factories/App/Order/Model/PdkOrderLineFactory.php @@ -7,6 +7,8 @@ use MyParcelNL\Pdk\App\Order\Collection\PdkOrderLineCollection; use MyParcelNL\Pdk\App\Order\Contract\PdkProductRepositoryInterface; +use MyParcelNL\Pdk\Base\Model\Currency; +use MyParcelNL\Pdk\Base\Model\CurrencyFactory; use MyParcelNL\Pdk\Base\Model\Model; use MyParcelNL\Pdk\Facade\Pdk; use MyParcelNL\Pdk\Tests\Factory\Contract\FactoryInterface; @@ -16,31 +18,46 @@ /** * @template T of PdkOrderLine * @method PdkOrderLine make() - * @method $this withPrice(int $price) - * @method $this withPriceAfterVat(int $priceAfterVat) + * @method $this withPrice(int|array|Currency|CurrencyFactory $price) + * @method $this withPriceAfterVat(int|array|Currency|CurrencyFactory $priceAfterVat) * @method $this withQuantity(int $quantity) - * @method $this withVat(int $vat) + * @method $this withVat(int|array|Currency|CurrencyFactory $vat) */ final class PdkOrderLineFactory extends AbstractModelFactory { + use UsesCurrency; + public function getModel(): string { return PdkOrderLine::class; } /** - * @param string|array|PdkProduct|PdkProductFactory $product + * @param int|string|array|PdkProduct|PdkProductFactory $product * * @return $this */ public function withProduct($product): self { if (is_scalar($product)) { - $product = Pdk::get(PdkProductRepositoryInterface::class) - ->getProduct($product); + /** @var \MyParcelNL\Pdk\App\Order\Contract\PdkProductRepositoryInterface $productRepository */ + $productRepository = Pdk::get(PdkProductRepositoryInterface::class); + + return $this->withProduct($productRepository->getProduct($product)); + } + + if (is_array($product)) { + return $this->withProduct(new PdkProduct($product)); + } + + if ($product instanceof FactoryInterface) { + return $this->withProduct($product->make()); } - return $this->with(['product' => $product]); + /** @var \MyParcelNL\Pdk\App\Order\Model\PdkProduct $product */ + return $this + ->with(['product' => $product]) + ->withPrice($this->toInt($product->price)); } public function withProductWithAllSettings(): self diff --git a/tests/factories/App/Order/Model/PdkProductFactory.php b/tests/factories/App/Order/Model/PdkProductFactory.php index 3f65b20e5..42d6b06fe 100644 --- a/tests/factories/App/Order/Model/PdkProductFactory.php +++ b/tests/factories/App/Order/Model/PdkProductFactory.php @@ -35,11 +35,51 @@ */ final class PdkProductFactory extends AbstractModelFactory { + use UsesCurrency; + public function getModel(): string { return PdkProduct::class; } + /** + * @return $this + */ + public function withAllFields(): self + { + $id = $this->getNextId('product'); + + return $this + ->withExternalIdentifier("product-$id") + ->withSku("sku-$id") + ->withEan("ean-$id") + ->withName("product-name ($id)"); + } + + /** + * @return $this + */ + public function withEverything(): self + { + return $this + ->withAllFields() + ->withPhysicalProperties() + ->withSettingsWithAllOptions() + ->withPrice(1000); + } + + /** + * @return $this + */ + public function withPhysicalProperties(): self + { + return $this + ->withHeight(10) + ->withLength(10) + ->withWeight(10) + ->withWidth(10); + } + /** * @param int|array|Currency|CurrencyFactory $price * @@ -47,11 +87,7 @@ public function getModel(): string */ public function withPrice($price): self { - if (is_numeric($price)) { - $price = factory(Currency::class)->withAmount($price); - } - - return $this->with(['price' => $price]); + return $this->withCurrencyField('price', $price); } /** diff --git a/tests/factories/App/Order/Model/UsesCurrency.php b/tests/factories/App/Order/Model/UsesCurrency.php new file mode 100644 index 000000000..3d193775a --- /dev/null +++ b/tests/factories/App/Order/Model/UsesCurrency.php @@ -0,0 +1,68 @@ +withAmount($input); + } + + if (is_array($input)) { + return factory(Currency::class)->with($input); + } + + if ($input instanceof Currency) { + return factory(Currency::class)->with($input->toArray()); + } + + return $input; + } + + /** + * @param int|array|Currency|CurrencyFactory $price + * + * @return int + */ + protected function toInt($price): int + { + if (is_array($price)) { + return $price['amount'] ?? 0; + } + + if ($price instanceof Currency) { + return $price->getAmount(); + } + + if ($price instanceof CurrencyFactory) { + return $price->make() + ->getAmount(); + } + + return $price ?? 0; + } + + /** + * @param string $field + * @param int|array|Currency|CurrencyFactory $input + * + * @return $this + */ + protected function withCurrencyField(string $field, $input): self + { + return $this->with([$field => $this->toCurrency($input)]); + } +} diff --git a/tests/factories/Context/Model/ProductDataContextFactory.php b/tests/factories/Context/Model/ProductDataContextFactory.php index eac6c1d02..b1a44e339 100644 --- a/tests/factories/Context/Model/ProductDataContextFactory.php +++ b/tests/factories/Context/Model/ProductDataContextFactory.php @@ -7,6 +7,7 @@ use MyParcelNL\Pdk\App\Order\Model\PdkProduct; use MyParcelNL\Pdk\App\Order\Model\PdkProductFactory; +use MyParcelNL\Pdk\App\Order\Model\UsesCurrency; use MyParcelNL\Pdk\Base\Model\Currency; use MyParcelNL\Pdk\Base\Model\CurrencyFactory; use MyParcelNL\Pdk\Settings\Model\ProductSettings; @@ -23,7 +24,6 @@ * @method $this withLength(int $length) * @method $this withName(string $name) * @method $this withParent(array|PdkProduct|PdkProductFactory|PdkProductFactory $parent) - * @method $this withPrice(array|Currency|CurrencyFactory|CurrencyFactory $price) * @method $this withSettings(array|ProductSettings|ProductSettingsFactory|ProductSettingsFactory $settings) * @method $this withSku(string $sku) * @method $this withWeight(int $weight) @@ -31,8 +31,20 @@ */ final class ProductDataContextFactory extends AbstractModelFactory { + use UsesCurrency; + public function getModel(): string { return ProductDataContext::class; } + + /** + * @param int|array|Currency|CurrencyFactory $price + * + * @return $this + */ + public function withPrice($price): self + { + return $this->withCurrencyField('price', $price); + } } diff --git a/tests/factories/Shipment/Model/ShipmentFactory.php b/tests/factories/Shipment/Model/ShipmentFactory.php index dcdd84869..e868b1059 100644 --- a/tests/factories/Shipment/Model/ShipmentFactory.php +++ b/tests/factories/Shipment/Model/ShipmentFactory.php @@ -11,6 +11,7 @@ use MyParcelNL\Pdk\App\Order\Model\PdkPhysicalPropertiesFactory; use MyParcelNL\Pdk\App\Order\Model\ShippingAddress; use MyParcelNL\Pdk\App\Order\Model\ShippingAddressFactory; +use MyParcelNL\Pdk\App\Order\Model\UsesCurrency; use MyParcelNL\Pdk\Base\Model\ContactDetails; use MyParcelNL\Pdk\Base\Model\ContactDetailsFactory; use MyParcelNL\Pdk\Base\Model\Currency; @@ -54,6 +55,8 @@ */ final class ShipmentFactory extends AbstractModelFactory { + use UsesCurrency; + public function getModel(): string { return Shipment::class; @@ -106,14 +109,10 @@ public function withId(?int $id = null): self /** * @param int|array|Currency|CurrencyFactory $price * - * @return self + * @return $this */ public function withPrice($price): self { - if (is_int($price)) { - $price = factory(Currency::class)->withAmount($price); - } - - return $this->with(['price' => $price]); + return $this->withCurrencyField('price', $price); } } From a6fc5a7960f9591a203cf8fd2f2e99b1cf86d020 Mon Sep 17 00:00:00 2001 From: Edie Lemoine Date: Thu, 7 Nov 2024 17:00:09 +0100 Subject: [PATCH 02/12] feat!: replace collection with illuminate collection --- composer.json | 3 +- src/App/Api/Service/PdkActionsService.php | 2 +- src/Base/Support/Collection.php | 10 ++- src/Base/Support/Helpers.php | 62 ------------------ .../Request/FetchShipmentsRequest.php | 2 +- .../Order/UpdateShipmentsActionTest.php | 2 +- tests/Unit/Base/Support/HelpersTest.php | 64 ------------------- tests/Unit/Carrier/Model/CarrierTest.php | 2 +- 8 files changed, 10 insertions(+), 137 deletions(-) delete mode 100644 src/Base/Support/Helpers.php delete mode 100644 tests/Unit/Base/Support/HelpersTest.php diff --git a/composer.json b/composer.json index a369a1448..ea74ecb6b 100644 --- a/composer.json +++ b/composer.json @@ -7,6 +7,7 @@ "license": "MIT", "require": { "ext-zip": "*", + "illuminate/support": ">= 8", "justinrainbow/json-schema": "^5.2", "myparcelnl/sdk": ">= 7", "php": ">=7.1.0", @@ -72,4 +73,4 @@ "pestphp/pest-plugin": true } } -} \ No newline at end of file +} diff --git a/src/App/Api/Service/PdkActionsService.php b/src/App/Api/Service/PdkActionsService.php index 5cfecc359..e40f5a8d7 100644 --- a/src/App/Api/Service/PdkActionsService.php +++ b/src/App/Api/Service/PdkActionsService.php @@ -114,7 +114,7 @@ private function resolveAction(Request $request): string $actions = new Collection(Config::get('actions')); - $match = $actions->dataGet("$this->context.$action") ?? $actions->dataGet("shared.$action"); + $match = $actions->getByKey("$this->context.$action") ?? $actions->getByKey("shared.$action"); $actionClass = $match['action'] ?? null; if (! $actionClass || ! class_exists($actionClass)) { diff --git a/src/Base/Support/Collection.php b/src/Base/Support/Collection.php index f3f584544..80953d646 100644 --- a/src/Base/Support/Collection.php +++ b/src/Base/Support/Collection.php @@ -6,11 +6,9 @@ use MyParcelNL\Pdk\Base\Contract\Arrayable; use MyParcelNL\Pdk\Base\Contract\StorableArrayable; -use MyParcelNL\Sdk\src\Support\Arr; -use MyParcelNL\Sdk\src\Support\Collection as SdkCollection; use Throwable; -class Collection extends SdkCollection implements StorableArrayable +class Collection extends \Illuminate\Support\Collection implements StorableArrayable { /** * Defines a class items should be cast into. @@ -30,13 +28,13 @@ public function __construct($items = []) /** * @param string $key - * @param $default + * @param mixed $default * * @return mixed */ - public function dataGet(string $key, $default = null) + public function getByKey(string $key, $default = null) { - return (new Helpers())->data_get($this->toArray(), $key, $default); + return Arr::get($this->toArray(), $key, $default); } /** diff --git a/src/Base/Support/Helpers.php b/src/Base/Support/Helpers.php deleted file mode 100644 index 48ac3b7be..000000000 --- a/src/Base/Support/Helpers.php +++ /dev/null @@ -1,62 +0,0 @@ - $segment) { - unset($key[$i]); - - if (null === $segment) { - return $target; - } - - if ('*' === $segment) { - if ($target instanceof Collection) { - $target = $target->all(); - } elseif (! is_array($target)) { - return $this->value($default); - } - - $result = []; - - foreach ($target as $item) { - $result[] = $this->data_get($item, $key); - } - - return in_array('*', $key, true) ? Arr::collapse($result) : $result; - } - - if (Arr::accessible($target) && Arr::exists($target, $segment)) { - $target = $target[$segment]; - } elseif (is_object($target) && isset($target->{$segment})) { - $target = $target->{$segment}; - } else { - return $this->value($default); - } - } - - return $target; - } -} diff --git a/src/Shipment/Request/FetchShipmentsRequest.php b/src/Shipment/Request/FetchShipmentsRequest.php index 553c26837..49f54941e 100644 --- a/src/Shipment/Request/FetchShipmentsRequest.php +++ b/src/Shipment/Request/FetchShipmentsRequest.php @@ -6,8 +6,8 @@ use InvalidArgumentException; use MyParcelNL\Pdk\Api\Request\Request; +use MyParcelNL\Pdk\Base\Support\Collection; use MyParcelNL\Pdk\Shipment\Collection\ShipmentCollection; -use MyParcelNL\Sdk\src\Support\Collection; class FetchShipmentsRequest extends Request { diff --git a/tests/Unit/App/Action/Backend/Order/UpdateShipmentsActionTest.php b/tests/Unit/App/Action/Backend/Order/UpdateShipmentsActionTest.php index c8e263c4c..c5b24c091 100644 --- a/tests/Unit/App/Action/Backend/Order/UpdateShipmentsActionTest.php +++ b/tests/Unit/App/Action/Backend/Order/UpdateShipmentsActionTest.php @@ -12,6 +12,7 @@ use MyParcelNL\Pdk\App\Order\Contract\PdkOrderNoteRepositoryInterface; use MyParcelNL\Pdk\App\Order\Model\PdkOrder; use MyParcelNL\Pdk\Base\Support\Arr; +use MyParcelNL\Pdk\Base\Support\Collection; use MyParcelNL\Pdk\Facade\Actions; use MyParcelNL\Pdk\Facade\Pdk; use MyParcelNL\Pdk\Settings\Model\OrderSettings; @@ -20,7 +21,6 @@ use MyParcelNL\Pdk\Tests\Bootstrap\MockApi; use MyParcelNL\Pdk\Tests\Uses\UsesApiMock; use MyParcelNL\Pdk\Tests\Uses\UsesMockPdkInstance; -use MyParcelNL\Sdk\src\Support\Collection; use Symfony\Component\HttpFoundation\Response; use function MyParcelNL\Pdk\Tests\factory; use function MyParcelNL\Pdk\Tests\usesShared; diff --git a/tests/Unit/Base/Support/HelpersTest.php b/tests/Unit/Base/Support/HelpersTest.php deleted file mode 100644 index 13a856931..000000000 --- a/tests/Unit/Base/Support/HelpersTest.php +++ /dev/null @@ -1,64 +0,0 @@ - [ - 'nested' => 1, - 'nested2' => 2, - 'nested3' => [ - 'level' => new Collection(), - ], - 'nested4' => null, - 'nested5' => (object) ['property' => 5], - ], -]; - -it('executes data_get', function ($key, $result) use ($data) { - $helpers = new Helpers(); - - expect($helpers->data_get($data, $key))->toEqual($result); -})->with([ - 'nested' => [ - 'key' => 'value.nested', - 'result' => 1, - ], - - 'wildcard' => [ - 'key' => 'value.*', - 'result' => array_values($data['value']), - ], - - 'null key' => [ - 'key' => null, - 'result' => $data, - ], - - 'null segment' => [ - 'key' => ['value', null], - 'result' => $data['value'], - ], - - 'collection' => [ - 'key' => 'value.nested3.level.*', - 'result' => [], - ], - - 'wildcard on non-array' => [ - 'key' => 'value.nested2.*', - 'result' => null, - ], - - 'nonexistent key' => [ - 'key' => 'value.nested2.another', - 'result' => null, - ], - - 'key in object' => [ - 'key' => 'value.nested5.property', - 'result' => 5, - ], -]); diff --git a/tests/Unit/Carrier/Model/CarrierTest.php b/tests/Unit/Carrier/Model/CarrierTest.php index e410afbdc..aabccb16f 100644 --- a/tests/Unit/Carrier/Model/CarrierTest.php +++ b/tests/Unit/Carrier/Model/CarrierTest.php @@ -7,10 +7,10 @@ use MyParcelNL\Pdk\Base\Contract\Arrayable; use MyParcelNL\Pdk\Base\Support\Arr; +use MyParcelNL\Pdk\Base\Support\Collection; use MyParcelNL\Pdk\Facade\Platform; use MyParcelNL\Pdk\Tests\Bootstrap\MockConfig; use MyParcelNL\Pdk\Tests\Uses\UsesEachMockPdkInstance; -use MyParcelNL\Sdk\src\Support\Collection; use function MyParcelNL\Pdk\Tests\mockPlatform; use function MyParcelNL\Pdk\Tests\usesShared; use function Spatie\Snapshots\assertMatchesJsonSnapshot; From 1a478ef0c5ae12726f12cdd2a2648cbf033830c4 Mon Sep 17 00:00:00 2001 From: Edie Lemoine Date: Thu, 7 Nov 2024 17:00:46 +0100 Subject: [PATCH 03/12] feat!: replace arr with illuminate arr --- src/Base/Support/Arr.php | 39 +-------------------------------------- 1 file changed, 1 insertion(+), 38 deletions(-) diff --git a/src/Base/Support/Arr.php b/src/Base/Support/Arr.php index 7a2db8b99..b9d4a67bf 100644 --- a/src/Base/Support/Arr.php +++ b/src/Base/Support/Arr.php @@ -4,41 +4,4 @@ namespace MyParcelNL\Pdk\Base\Support; -use MyParcelNL\Sdk\src\Support\Arr as SdkArr; - -class Arr extends SdkArr -{ - /** - * @var \MyParcelNL\Pdk\Base\Support\Helpers - */ - private static $helpers; - - /** - * @param array $dotted - * - * @return array - */ - public static function undot(array $dotted): array - { - $array = []; - - foreach ($dotted as $key => $value) { - self::getHelpers() - ->data_set($array, $key, $value); - } - - return $array; - } - - /** - * @return \MyParcelNL\Pdk\Base\Support\Helpers - */ - protected static function getHelpers(): Helpers - { - if (! self::$helpers) { - self::$helpers = new Helpers(); - } - - return self::$helpers; - } -} +class Arr extends \Illuminate\Support\Arr { } From ee80a6267dd1561963aaee8511f85bc73aad7010 Mon Sep 17 00:00:00 2001 From: Edie Lemoine Date: Thu, 7 Nov 2024 17:08:13 +0100 Subject: [PATCH 04/12] feat!: replace str with illuminate str --- .../Service/ModelFactoryGeneratorService.php | 2 +- private/PhpLoader.php | 2 +- .../Documentation/DocumentationGenerator.php | 2 +- private/Types/Php/IdeHelperGenerator.php | 2 +- private/Types/Shared/Concern/UsesCache.php | 2 +- .../Types/Shared/Service/PhpSourceParser.php | 2 +- .../Types/Shared/Service/PhpTypeParser.php | 2 +- private/Types/TypeScript/TsTypeParser.php | 2 +- .../Webhook/AbstractWebhooksAction.php | 2 +- .../Service/DeliveryOptionsFeesService.php | 2 +- .../Service/DeliveryOptionsService.php | 2 +- .../General/LabelDescriptionCalculator.php | 2 +- src/Base/Concern/HasAttributes.php | 2 +- src/Base/Config.php | 2 +- src/Base/Model/Model.php | 2 +- src/Base/Service/CountryService.php | 2 +- src/Base/Support/Str.php | 20 +++++++++++++++++++ src/Base/Support/Utils.php | 2 +- src/Context/Model/CheckoutContext.php | 2 +- .../Service/FrontendRenderService.php | 2 +- src/Frontend/View/AbstractSettingsView.php | 2 +- src/Frontend/View/CarrierSettingsItemView.php | 2 +- src/Frontend/View/NewAbstractSettingsView.php | 2 +- .../WebhookSubscriptionRepository.php | 2 +- tests/Factory/Model/AbstractModelFactory.php | 2 +- tests/Integration/Base/BehatConfig.php | 2 +- .../Context/Concern/ResolvesModels.php | 2 +- .../Context/Concern/ValidatesValues.php | 2 +- tests/Unit/Base/Support/StrTest.php | 19 ++++++++++++++++++ tests/usesShared.php | 2 +- 30 files changed, 67 insertions(+), 28 deletions(-) create mode 100644 src/Base/Support/Str.php create mode 100644 tests/Unit/Base/Support/StrTest.php diff --git a/private/GenerateFactory/Service/ModelFactoryGeneratorService.php b/private/GenerateFactory/Service/ModelFactoryGeneratorService.php index 4aaf80f15..365a66317 100644 --- a/private/GenerateFactory/Service/ModelFactoryGeneratorService.php +++ b/private/GenerateFactory/Service/ModelFactoryGeneratorService.php @@ -10,7 +10,7 @@ use MyParcelNL\Pdk\Console\Types\Shared\Model\ClassDefinition; use MyParcelNL\Pdk\Console\Types\Shared\Model\ClassProperty; use MyParcelNL\Pdk\Tests\Factory\FactoryFactory; -use MyParcelNL\Sdk\src\Support\Str; +use MyParcelNL\Pdk\Base\Support\Str; use Throwable; final class ModelFactoryGeneratorService extends AbstractFactoryGeneratorService diff --git a/private/PhpLoader.php b/private/PhpLoader.php index 0177a2623..222a05960 100644 --- a/private/PhpLoader.php +++ b/private/PhpLoader.php @@ -10,7 +10,7 @@ use MyParcelNL\Pdk\Console\Types\Shared\Concern\ReportsTiming; use MyParcelNL\Pdk\Console\Types\Shared\Service\ParsesPhpDocs; use MyParcelNL\Pdk\Facade\Pdk; -use MyParcelNL\Sdk\src\Support\Str; +use MyParcelNL\Pdk\Base\Support\Str; use Nette\Loaders\RobotLoader; final class PhpLoader diff --git a/private/Types/Documentation/DocumentationGenerator.php b/private/Types/Documentation/DocumentationGenerator.php index 335a26c9f..264e203a4 100644 --- a/private/Types/Documentation/DocumentationGenerator.php +++ b/private/Types/Documentation/DocumentationGenerator.php @@ -8,7 +8,7 @@ use MyParcelNL\Pdk\Console\Types\Shared\AbstractHelperGenerator; use MyParcelNL\Pdk\Console\Types\Shared\Model\ClassDefinition; use MyParcelNL\Pdk\Console\Types\Shared\Model\KeyValue; -use MyParcelNL\Sdk\src\Support\Str; +use MyParcelNL\Pdk\Base\Support\Str; use ReflectionClass; final class DocumentationGenerator extends AbstractHelperGenerator diff --git a/private/Types/Php/IdeHelperGenerator.php b/private/Types/Php/IdeHelperGenerator.php index 2b744abc0..1d5205b58 100644 --- a/private/Types/Php/IdeHelperGenerator.php +++ b/private/Types/Php/IdeHelperGenerator.php @@ -14,7 +14,7 @@ use MyParcelNL\Pdk\Console\Types\Shared\Model\KeyValue; use MyParcelNL\Pdk\Console\Types\Shared\Service\PhpTypeParser; use MyParcelNL\Pdk\Facade\Pdk; -use MyParcelNL\Sdk\src\Support\Str; +use MyParcelNL\Pdk\Base\Support\Str; use Symfony\Component\PropertyInfo\Type; final class IdeHelperGenerator extends AbstractHelperGenerator diff --git a/private/Types/Shared/Concern/UsesCache.php b/private/Types/Shared/Concern/UsesCache.php index 54ea2bce5..7b4bb8792 100644 --- a/private/Types/Shared/Concern/UsesCache.php +++ b/private/Types/Shared/Concern/UsesCache.php @@ -9,7 +9,7 @@ use MyParcelNL\Pdk\Console\Storage\ConsoleMemoryCacheStorage; use MyParcelNL\Pdk\Console\Storage\Contract\ConsoleStorageInterface; use MyParcelNL\Pdk\Facade\Pdk; -use MyParcelNL\Sdk\src\Support\Str; +use MyParcelNL\Pdk\Base\Support\Str; trait UsesCache { diff --git a/private/Types/Shared/Service/PhpSourceParser.php b/private/Types/Shared/Service/PhpSourceParser.php index 2d1778942..4226d1907 100644 --- a/private/Types/Shared/Service/PhpSourceParser.php +++ b/private/Types/Shared/Service/PhpSourceParser.php @@ -16,7 +16,7 @@ use MyParcelNL\Pdk\Console\Types\Shared\Concern\ReportsTiming; use MyParcelNL\Pdk\Console\Types\Shared\Model\ClassDefinition; use MyParcelNL\Pdk\Console\Types\Shared\Model\KeyValue; -use MyParcelNL\Sdk\src\Support\Str; +use MyParcelNL\Pdk\Base\Support\Str; use ReflectionClass; use ReflectionMethod; use Symfony\Component\PropertyInfo\Extractor\ReflectionExtractor; diff --git a/private/Types/Shared/Service/PhpTypeParser.php b/private/Types/Shared/Service/PhpTypeParser.php index 01b97cd57..28db3a5aa 100644 --- a/private/Types/Shared/Service/PhpTypeParser.php +++ b/private/Types/Shared/Service/PhpTypeParser.php @@ -7,7 +7,7 @@ use MyParcelNL\Pdk\Base\Support\Arr; use MyParcelNL\Pdk\Base\Support\Collection; use MyParcelNL\Pdk\Base\Support\Utils; -use MyParcelNL\Sdk\src\Support\Str; +use MyParcelNL\Pdk\Base\Support\Str; use Symfony\Component\PropertyInfo\Type; class PhpTypeParser diff --git a/private/Types/TypeScript/TsTypeParser.php b/private/Types/TypeScript/TsTypeParser.php index 8b4961371..305f85592 100644 --- a/private/Types/TypeScript/TsTypeParser.php +++ b/private/Types/TypeScript/TsTypeParser.php @@ -9,7 +9,7 @@ use DateTimeImmutable; use MyParcelNL\Pdk\Base\Support\Arr; use MyParcelNL\Pdk\Console\Types\Shared\Concern\UsesCache; -use MyParcelNL\Sdk\src\Support\Str; +use MyParcelNL\Pdk\Base\Support\Str; class TsTypeParser { diff --git a/src/App/Action/Backend/Webhook/AbstractWebhooksAction.php b/src/App/Action/Backend/Webhook/AbstractWebhooksAction.php index 50bc4c91f..6a72252b9 100644 --- a/src/App/Action/Backend/Webhook/AbstractWebhooksAction.php +++ b/src/App/Action/Backend/Webhook/AbstractWebhooksAction.php @@ -11,7 +11,7 @@ use MyParcelNL\Pdk\Webhook\Collection\WebhookSubscriptionCollection; use MyParcelNL\Pdk\Webhook\Model\WebhookSubscription; use MyParcelNL\Pdk\Webhook\Repository\WebhookSubscriptionRepository; -use MyParcelNL\Sdk\src\Support\Str; +use MyParcelNL\Pdk\Base\Support\Str; abstract class AbstractWebhooksAction implements ActionInterface { diff --git a/src/App/DeliveryOptions/Service/DeliveryOptionsFeesService.php b/src/App/DeliveryOptions/Service/DeliveryOptionsFeesService.php index f0445b609..2be5fe4ad 100644 --- a/src/App/DeliveryOptions/Service/DeliveryOptionsFeesService.php +++ b/src/App/DeliveryOptions/Service/DeliveryOptionsFeesService.php @@ -12,7 +12,7 @@ use MyParcelNL\Pdk\Shipment\Model\DeliveryOptions; use MyParcelNL\Pdk\Shipment\Model\ShipmentOptions; use MyParcelNL\Pdk\Types\Service\TriStateService; -use MyParcelNL\Sdk\src\Support\Str; +use MyParcelNL\Pdk\Base\Support\Str; class DeliveryOptionsFeesService implements DeliveryOptionsFeesServiceInterface { diff --git a/src/App/DeliveryOptions/Service/DeliveryOptionsService.php b/src/App/DeliveryOptions/Service/DeliveryOptionsService.php index 1ccbc6b96..b1b5d0612 100644 --- a/src/App/DeliveryOptions/Service/DeliveryOptionsService.php +++ b/src/App/DeliveryOptions/Service/DeliveryOptionsService.php @@ -21,7 +21,7 @@ use MyParcelNL\Pdk\Shipment\Model\DeliveryOptions; use MyParcelNL\Pdk\Validation\Repository\SchemaRepository; use MyParcelNL\Pdk\Validation\Validator\OrderPropertiesValidator; -use MyParcelNL\Sdk\src\Support\Str; +use MyParcelNL\Pdk\Base\Support\Str; class DeliveryOptionsService implements DeliveryOptionsServiceInterface { diff --git a/src/App/Order/Calculator/General/LabelDescriptionCalculator.php b/src/App/Order/Calculator/General/LabelDescriptionCalculator.php index 533ba330a..3f1f6875f 100644 --- a/src/App/Order/Calculator/General/LabelDescriptionCalculator.php +++ b/src/App/Order/Calculator/General/LabelDescriptionCalculator.php @@ -6,13 +6,13 @@ use MyParcelNL\Pdk\App\Order\Calculator\AbstractPdkOrderOptionCalculator; use MyParcelNL\Pdk\Base\Support\Arr; +use MyParcelNL\Pdk\Base\Support\Str; use MyParcelNL\Pdk\Base\Support\Utils; use MyParcelNL\Pdk\Facade\Pdk; use MyParcelNL\Pdk\Facade\Settings; use MyParcelNL\Pdk\Fulfilment\Model\OrderNote; use MyParcelNL\Pdk\Settings\Model\LabelSettings; use MyParcelNL\Pdk\Types\Service\TriStateService; -use MyParcelNL\Sdk\src\Support\Str; final class LabelDescriptionCalculator extends AbstractPdkOrderOptionCalculator { diff --git a/src/Base/Concern/HasAttributes.php b/src/Base/Concern/HasAttributes.php index 364f18be3..c7be71d9a 100644 --- a/src/Base/Concern/HasAttributes.php +++ b/src/Base/Concern/HasAttributes.php @@ -19,7 +19,7 @@ use MyParcelNL\Pdk\Facade\Pdk; use MyParcelNL\Pdk\Types\Contract\TriStateServiceInterface; use MyParcelNL\Pdk\Types\Service\TriStateService; -use MyParcelNL\Sdk\src\Support\Str; +use MyParcelNL\Pdk\Base\Support\Str; use Throwable; /** diff --git a/src/Base/Config.php b/src/Base/Config.php index 9a8c09a89..b5e6a9a9a 100644 --- a/src/Base/Config.php +++ b/src/Base/Config.php @@ -8,7 +8,7 @@ use MyParcelNL\Pdk\Base\Contract\ConfigInterface; use MyParcelNL\Pdk\Base\Support\Arr; use MyParcelNL\Pdk\Facade\Pdk as PdkFacade; -use MyParcelNL\Sdk\src\Support\Str; +use MyParcelNL\Pdk\Base\Support\Str; class Config implements ConfigInterface { diff --git a/src/Base/Model/Model.php b/src/Base/Model/Model.php index 7d2b0e4ba..0b40e57fd 100644 --- a/src/Base/Model/Model.php +++ b/src/Base/Model/Model.php @@ -11,7 +11,7 @@ use MyParcelNL\Pdk\Base\Contract\ModelInterface; use MyParcelNL\Pdk\Base\Contract\StorableArrayable; use MyParcelNL\Pdk\Base\Support\Utils; -use MyParcelNL\Sdk\src\Support\Str; +use MyParcelNL\Pdk\Base\Support\Str; /** * @SuppressWarnings(PHPMD.TooManyPublicMethods) diff --git a/src/Base/Service/CountryService.php b/src/Base/Service/CountryService.php index ef449bf0b..b212bf9f6 100644 --- a/src/Base/Service/CountryService.php +++ b/src/Base/Service/CountryService.php @@ -6,7 +6,7 @@ use MyParcelNL\Pdk\Base\Contract\CountryServiceInterface; use MyParcelNL\Pdk\Facade\Platform; -use MyParcelNL\Sdk\src\Support\Str; +use MyParcelNL\Pdk\Base\Support\Str; class CountryService implements CountryServiceInterface { diff --git a/src/Base/Support/Str.php b/src/Base/Support/Str.php new file mode 100644 index 000000000..5b731fd9b --- /dev/null +++ b/src/Base/Support/Str.php @@ -0,0 +1,20 @@ +toBe($result) + ->and(strlen($limited)) + ->toBeLessThanOrEqual($length); +})->with([ + ['some long string', 10, '...', 'some lo...'], + ['short enough', 40, '_-.', 'short enough'], + ['broccoli', 5, '~', 'broc~'], +]); diff --git a/tests/usesShared.php b/tests/usesShared.php index 513b3a149..dcce6336e 100644 --- a/tests/usesShared.php +++ b/tests/usesShared.php @@ -6,7 +6,7 @@ namespace MyParcelNL\Pdk\Tests; use MyParcelNL\Pdk\Tests\Uses\BaseMock; -use MyParcelNL\Sdk\src\Support\Str; +use MyParcelNL\Pdk\Base\Support\Str; use Pest\PendingObjects\UsesCall; use Pest\Support\Backtrace; From 5bf4f6291688ce948a64b1f22de9bc28bb97b209 Mon Sep 17 00:00:00 2001 From: Edie Lemoine Date: Thu, 7 Nov 2024 17:09:49 +0100 Subject: [PATCH 05/12] refactor!: remove sdk extends from utils --- src/Base/Support/Utils.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Base/Support/Utils.php b/src/Base/Support/Utils.php index 32058c8e6..c283cfac7 100644 --- a/src/Base/Support/Utils.php +++ b/src/Base/Support/Utils.php @@ -5,10 +5,9 @@ namespace MyParcelNL\Pdk\Base\Support; use MyParcelNL\Pdk\Base\Contract\Arrayable; -use MyParcelNL\Pdk\Base\Support\Str; use Throwable; -class Utils extends \MyParcelNL\Sdk\src\Helper\Utils +class Utils { /** * @var array From 379dea23fce66836543649ee9640f87a2d777b8a Mon Sep 17 00:00:00 2001 From: Edie Lemoine Date: Thu, 7 Nov 2024 17:12:24 +0100 Subject: [PATCH 06/12] chore(deps)!: remove myparcelnl/sdk dependency --- composer.json | 1 - 1 file changed, 1 deletion(-) diff --git a/composer.json b/composer.json index ea74ecb6b..8875f59bd 100644 --- a/composer.json +++ b/composer.json @@ -9,7 +9,6 @@ "ext-zip": "*", "illuminate/support": ">= 8", "justinrainbow/json-schema": "^5.2", - "myparcelnl/sdk": ">= 7", "php": ">=7.1.0", "php-di/php-di": ">= 6", "psr/log": "^1 || ^2 || ^3", From e95057d3011d6ef771b839e550dbfb7597fb2bba Mon Sep 17 00:00:00 2001 From: Edie Lemoine Date: Thu, 14 Nov 2024 13:38:16 +0100 Subject: [PATCH 07/12] perf!: improve model performance (#301) --- src/App/Order/Model/PdkProduct.php | 4 +- src/Base/Concern/HasAttributes.php | 18 ++-- src/Base/Model/Model.php | 35 +++++-- src/Base/Support/Str.php | 48 ++++++++++ src/Base/Support/Utils.php | 37 +------ src/Context/Model/ContextBag.php | 15 +++ src/Fulfilment/Model/ShippedItem.php | 8 +- .../Repository/ShipmentRepository.php | 2 +- tests/Mocks/MockCastingModel.php | 96 +++++++++---------- tests/Mocks/MockNestedModel.php | 8 +- tests/Unit/Base/Model/ModelToArrayTest.php | 6 +- 11 files changed, 164 insertions(+), 113 deletions(-) diff --git a/src/App/Order/Model/PdkProduct.php b/src/App/Order/Model/PdkProduct.php index f43a24065..e92211393 100644 --- a/src/App/Order/Model/PdkProduct.php +++ b/src/App/Order/Model/PdkProduct.php @@ -84,6 +84,7 @@ public function toStorableArray(): array /** * @return \MyParcelNL\Pdk\Settings\Model\ProductSettings + * @noinspection PhpUnused */ protected function getMergedSettingsAttribute(): ProductSettings { @@ -121,12 +122,13 @@ private function resolveMergedSettings(): ProductSettings return $settings; } + /** @var \MyParcelNL\Pdk\Types\Contract\TriStateServiceInterface $triStateService */ $triStateService = Pdk::get(TriStateServiceInterface::class); foreach ($settings->getAttributes() as $key => $value) { $coerced = $triStateService->coerce($settings->getAttribute($key)); - if ($coerced === '-1') { + if ((string) TriStateService::INHERIT === $coerced) { $coerced = (int) $coerced; } diff --git a/src/Base/Concern/HasAttributes.php b/src/Base/Concern/HasAttributes.php index c7be71d9a..0e29405dd 100644 --- a/src/Base/Concern/HasAttributes.php +++ b/src/Base/Concern/HasAttributes.php @@ -14,12 +14,12 @@ use MyParcelNL\Pdk\Base\Exception\InvalidCastException; use MyParcelNL\Pdk\Base\Support\Arr; use MyParcelNL\Pdk\Base\Support\Collection; +use MyParcelNL\Pdk\Base\Support\Str; use MyParcelNL\Pdk\Base\Support\Utils; use MyParcelNL\Pdk\Facade\Logger; use MyParcelNL\Pdk\Facade\Pdk; use MyParcelNL\Pdk\Types\Contract\TriStateServiceInterface; use MyParcelNL\Pdk\Types\Service\TriStateService; -use MyParcelNL\Pdk\Base\Support\Str; use Throwable; /** @@ -183,7 +183,7 @@ public function getAttribute(string $key) return null; } - $key = Utils::changeCase($key); + $key = Str::changeCase($key); if ($this->isGuarded($key)) { return $this->guarded[$key]; @@ -269,7 +269,7 @@ public function only($attributes, ?int $flags = null): array */ public function setAttribute(string $key, $value): self { - $key = $this->convertDeprecatedKey(Utils::changeCase($key)); + $key = $this->convertDeprecatedKey(Str::changeCase($key)); if ($this->isGuarded($key)) { return $this; @@ -301,8 +301,8 @@ public function setAttribute(string $key, $value): self protected function addCastAttributesToArray(array $attributes, array $mutatedAttributes, ?int $flags): array { foreach ($this->getCasts() as $key => $value) { - $originalKey = Utils::changeCase($key); - $key = Utils::changeCase($key, $flags); + $originalKey = Str::changeCase($key); + $key = Str::changeCase($key, $flags); if (! array_key_exists($key, $attributes) || in_array($key, $mutatedAttributes, true)) { continue; @@ -358,8 +358,8 @@ protected function addCastAttributesToArray(array $attributes, array $mutatedAtt protected function addMutatedAttributesToArray(array $attributes, array $mutatedAttributes, ?int $flags): array { foreach ($mutatedAttributes as $key) { - $originalKey = Utils::changeCase($key); - $key = Utils::changeCase($key, $flags); + $originalKey = Str::changeCase($key); + $key = Str::changeCase($key, $flags); if (! array_key_exists($key, $attributes)) { continue; @@ -585,7 +585,7 @@ protected function getCastAttributeValue(string $string) protected function getCastType(string $key): ?string { $casts = $this->getCasts(); - $normalizedKey = Utils::changeCase($key); + $normalizedKey = Str::changeCase($key); return $casts[$normalizedKey]; } @@ -597,7 +597,7 @@ protected function getCastType(string $key): ?string */ protected function getCasts(): array { - return Utils::changeArrayKeysCase($this->casts); + return $this->casts; } /** diff --git a/src/Base/Model/Model.php b/src/Base/Model/Model.php index 0b40e57fd..073111aca 100644 --- a/src/Base/Model/Model.php +++ b/src/Base/Model/Model.php @@ -10,8 +10,9 @@ use MyParcelNL\Pdk\Base\Contract\Arrayable; use MyParcelNL\Pdk\Base\Contract\ModelInterface; use MyParcelNL\Pdk\Base\Contract\StorableArrayable; -use MyParcelNL\Pdk\Base\Support\Utils; +use MyParcelNL\Pdk\Base\Support\Arr; use MyParcelNL\Pdk\Base\Support\Str; +use MyParcelNL\Pdk\Base\Support\Utils; /** * @SuppressWarnings(PHPMD.TooManyPublicMethods) @@ -36,6 +37,11 @@ class Model implements StorableArrayable, ArrayAccess, ModelInterface */ protected $cloned = false; + /** + * @var array + */ + protected $lazy = []; + /** * @param null|array $data */ @@ -43,14 +49,19 @@ public function __construct(?array $data = null) { $this->bootIfNotBooted(); - $this->guarded = Utils::changeArrayKeysCase($this->guarded); - $this->attributes = $this->guarded + Utils::changeArrayKeysCase($this->attributes); + $this->attributes = $this->guarded + $this->attributes; $this->initializeTraits(); - $convertedData = Utils::changeArrayKeysCase($data ?? []); + // filter out the items that are in $this->lazy + $attributes = Utils::changeArrayKeysCase($data ?? []) + $this->attributes; - $this->fill($convertedData + $this->attributes); + $filteredAttributes = count($this->lazy) + ? Arr::where($attributes, function ($value, $key) { + return $value !== null || ! $this->isLazy($key); + }) : $attributes; + + $this->fill($filteredAttributes); } public static function isBooted(): bool @@ -215,7 +226,7 @@ public function offsetSet($offset, $value): void */ public function offsetUnset($offset): void { - unset($this->attributes[(Utils::changeCase($offset))]); + unset($this->attributes[(Str::changeCase($offset))]); } /** @@ -293,6 +304,16 @@ protected function initializeTraits(): void } } + /** + * @param string $key + * + * @return bool + */ + private function isLazy(string $key): bool + { + return in_array($key, $this->lazy, true); + } + /** * @param array $attributes * @@ -303,7 +324,7 @@ private function normalizeAttributes(array $attributes): array $normalizedAttributes = []; foreach ($attributes as $initialKey => $value) { - $caseKey = Utils::changeCase($initialKey); + $caseKey = Str::changeCase($initialKey); $key = $this->convertDeprecatedKey($caseKey); if (array_key_exists($key, $normalizedAttributes)) { diff --git a/src/Base/Support/Str.php b/src/Base/Support/Str.php index 5b731fd9b..18c72eff1 100644 --- a/src/Base/Support/Str.php +++ b/src/Base/Support/Str.php @@ -4,8 +4,28 @@ namespace MyParcelNL\Pdk\Base\Support; +use MyParcelNL\Pdk\Base\Contract\Arrayable; + class Str extends \Illuminate\Support\Str { + /** + * @var array + */ + private static $flagCaseCache = []; + + /** + * @param string $string + * @param null|int $flags + * + * @return string + */ + public static function changeCase(string $string, ?int $flags = null): string + { + $case = self::getFlagCase($flags); + + return self::{$case}($string); + } + /** * @param string $value * @param int $limit @@ -17,4 +37,32 @@ public static function limit($value, $limit = 100, $end = '...'): string { return parent::limit($value, $limit - strlen($end), $end); } + + /** + * @param null|int $flags + * + * @return string + */ + private static function getFlagCase(?int $flags = null): string + { + if (! isset(self::$flagCaseCache[$flags])) { + $case = 'camel'; + + if ($flags & Arrayable::CASE_SNAKE) { + $case = 'snake'; + } + + if ($flags & Arrayable::CASE_KEBAB) { + $case = 'kebab'; + } + + if ($flags & Arrayable::CASE_STUDLY) { + $case = 'studly'; + } + + self::$flagCaseCache[$flags] = $case; + } + + return self::$flagCaseCache[$flags]; + } } diff --git a/src/Base/Support/Utils.php b/src/Base/Support/Utils.php index c283cfac7..5bdd0ecdb 100644 --- a/src/Base/Support/Utils.php +++ b/src/Base/Support/Utils.php @@ -67,26 +67,13 @@ public static function changeArrayKeysCase(array $array, ?int $flags = null): ar $value = self::changeArrayKeysCase($value, $flags); } - $newKey = self::changeCase($key, $flags); + $newKey = Str::changeCase($key, $flags); $newArray[$newKey] = $value; } return $newArray; } - /** - * @param string $string - * @param null|int $flags - * - * @return string - */ - public static function changeCase(string $string, ?int $flags = null): string - { - $case = self::getFlagCase($flags); - - return Str::{$case}($string); - } - /** * Get the class "basename" of the given object / class. * @@ -264,26 +251,4 @@ public static function toRecursiveCollection(array $array): Collection return $collection; } - - /** - * @param null|int $flags - * - * @return string - */ - private static function getFlagCase(?int $flags = null): string - { - if ($flags & Arrayable::CASE_SNAKE) { - return 'snake'; - } - - if ($flags & Arrayable::CASE_KEBAB) { - return 'kebab'; - } - - if ($flags & Arrayable::CASE_STUDLY) { - return 'studly'; - } - - return 'camel'; - } } diff --git a/src/Context/Model/ContextBag.php b/src/Context/Model/ContextBag.php index 67953c1c6..c8e90b9b0 100644 --- a/src/Context/Model/ContextBag.php +++ b/src/Context/Model/ContextBag.php @@ -39,4 +39,19 @@ class ContextBag extends Model Context::ID_PRODUCT_DATA => ProductDataContextCollection::class, Context::ID_PRODUCT_SETTINGS_VIEW => ProductSettingsViewContext::class, ]; + + public $lazy = [ + Context::ID_GLOBAL, + Context::ID_DYNAMIC, + Context::ID_CHECKOUT, + Context::ID_ORDER_DATA, + Context::ID_PLUGIN_SETTINGS_VIEW, + Context::ID_PRODUCT_DATA, + Context::ID_PRODUCT_SETTINGS_VIEW, + ]; + + public function __construct(?array $data = null) + { + parent::__construct($data); + } } diff --git a/src/Fulfilment/Model/ShippedItem.php b/src/Fulfilment/Model/ShippedItem.php index 1cd69bde2..6fc70b2ec 100644 --- a/src/Fulfilment/Model/ShippedItem.php +++ b/src/Fulfilment/Model/ShippedItem.php @@ -13,12 +13,12 @@ class ShippedItem extends Model { public $attributes = [ - 'order_line_identifier' => null, - 'quantity' => 1, + 'orderLineIdentifier' => null, + 'quantity' => 1, ]; protected $casts = [ - 'order_line_identifier' => 'string', - 'quantity' => 'int', + 'orderLineIdentifier' => 'string', + 'quantity' => 'int', ]; } diff --git a/src/Shipment/Repository/ShipmentRepository.php b/src/Shipment/Repository/ShipmentRepository.php index 677562383..aa255f349 100644 --- a/src/Shipment/Repository/ShipmentRepository.php +++ b/src/Shipment/Repository/ShipmentRepository.php @@ -132,7 +132,7 @@ public function fetchLabelPdf( */ public function getByReferenceIdentifiers(array $referenceIdentifiers, ?int $size = null): ShipmentCollection { - return $this->query(['reference_identifier' => $referenceIdentifiers, 'size' => $size]); + return $this->query(['referenceIdentifier' => $referenceIdentifiers, 'size' => $size]); } /** diff --git a/tests/Mocks/MockCastingModel.php b/tests/Mocks/MockCastingModel.php index 5048fb212..31ba87f18 100644 --- a/tests/Mocks/MockCastingModel.php +++ b/tests/Mocks/MockCastingModel.php @@ -31,7 +31,7 @@ class MockCastingModel extends Model { protected $attributes = [ - 'collection' => [ + 'collection' => [ [ 'value' => 1, ], @@ -39,56 +39,56 @@ class MockCastingModel extends Model 'value' => 2, ], ], - 'object' => ['property' => 'hello'], - 'date' => '2022-01-10', - 'datetime' => '2022-01-10 14:03:00', - 'date_from_arr' => [ - 'date' => '2022-12-25 17:02:32.000000', - 'timezone_type' => 3, - 'timezone' => 'Europe/Amsterdam', + 'object' => ['property' => 'hello'], + 'date' => '2022-01-10', + 'datetime' => '2022-01-10 14:03:00', + 'dateFromArr' => [ + 'date' => '2022-12-25 17:02:32.000000', + 'timezoneType' => 3, + 'timezone' => 'Europe/Amsterdam', ], - 'timestamp' => '2022-01-10 14:03:00', - 'string_bool' => 'true', - 'string_false_bool' => 'false', - 'string_false_int' => 'false', - 'string_int' => '4', - 'string_true_bool' => 'true', - 'string_true_int' => 'true', - 'int_string' => 1234, - 'int_float' => 2, - 'string_float' => '2', - 'without_a_cast' => 'whatever', - 'null' => null, - 'tristate1' => TriStateService::ENABLED, - 'tristate2' => TriStateService::INHERIT, - 'tristateCoerced1' => 1000, - 'tristateCoerced2' => TriStateService::INHERIT, - 'tristateString1' => 'hello', - 'tristateString2' => TriStateService::INHERIT, + 'timestamp' => '2022-01-10 14:03:00', + 'stringBool' => 'true', + 'stringFalseBool' => 'false', + 'stringFalseInt' => 'false', + 'stringInt' => '4', + 'stringTrueBool' => 'true', + 'stringTrueInt' => 'true', + 'intString' => 1234, + 'intFloat' => 2, + 'stringFloat' => '2', + 'withoutACast' => 'whatever', + 'null' => null, + 'tristate1' => TriStateService::ENABLED, + 'tristate2' => TriStateService::INHERIT, + 'tristateCoerced1' => 1000, + 'tristateCoerced2' => TriStateService::INHERIT, + 'tristateString1' => 'hello', + 'tristateString2' => TriStateService::INHERIT, ]; protected $casts = [ - 'collection' => Collection::class, - 'object' => MockCastModel::class, - 'date' => 'date', - 'datetime' => 'datetime', - 'date_from_arr' => DateTime::class, - 'timestamp' => 'timestamp', - 'string_bool' => 'bool', - 'string_false_bool' => 'bool', - 'string_false_int' => 'int', - 'string_int' => 'int', - 'string_true_bool' => 'bool', - 'string_true_int' => 'int', - 'int_string' => 'string', - 'int_float' => 'float', - 'string_float' => 'float', - 'null' => 'string', - 'tristate1' => TriStateService::TYPE_STRICT, - 'tristate2' => TriStateService::TYPE_STRICT, - 'tristateCoerced1' => TriStateService::TYPE_COERCED, - 'tristateCoerced2' => TriStateService::TYPE_COERCED, - 'tristateString1' => TriStateService::TYPE_STRING, - 'tristateString2' => TriStateService::TYPE_STRING, + 'collection' => Collection::class, + 'object' => MockCastModel::class, + 'date' => 'date', + 'datetime' => 'datetime', + 'dateFromArr' => DateTime::class, + 'timestamp' => 'timestamp', + 'stringBool' => 'bool', + 'stringFalseBool' => 'bool', + 'stringFalseInt' => 'int', + 'stringInt' => 'int', + 'stringTrueBool' => 'bool', + 'stringTrueInt' => 'int', + 'intString' => 'string', + 'intFloat' => 'float', + 'stringFloat' => 'float', + 'null' => 'string', + 'tristate1' => TriStateService::TYPE_STRICT, + 'tristate2' => TriStateService::TYPE_STRICT, + 'tristateCoerced1' => TriStateService::TYPE_COERCED, + 'tristateCoerced2' => TriStateService::TYPE_COERCED, + 'tristateString1' => TriStateService::TYPE_STRING, + 'tristateString2' => TriStateService::TYPE_STRING, ]; } diff --git a/tests/Mocks/MockNestedModel.php b/tests/Mocks/MockNestedModel.php index 6df68aa26..2256e8dd4 100644 --- a/tests/Mocks/MockNestedModel.php +++ b/tests/Mocks/MockNestedModel.php @@ -9,12 +9,12 @@ class MockNestedModel extends Model { public $attributes = [ - 'my_value' => null, - 'myModel' => null, + 'myValue' => null, + 'myModel' => null, ]; protected $casts = [ - 'my_value' => 'string', - 'myModel' => MockNestedModel::class, + 'myValue' => 'string', + 'myModel' => MockNestedModel::class, ]; } diff --git a/tests/Unit/Base/Model/ModelToArrayTest.php b/tests/Unit/Base/Model/ModelToArrayTest.php index 3f4f325c7..6d7563ce8 100644 --- a/tests/Unit/Base/Model/ModelToArrayTest.php +++ b/tests/Unit/Base/Model/ModelToArrayTest.php @@ -9,10 +9,10 @@ use MyParcelNL\Pdk\Tests\Mocks\MockNestedModel; const MODEL_DATA = [ - 'my_value' => 1, - 'myModel' => [ + 'myValue' => 1, + 'myModel' => [ 'myModel' => [ - 'my_value' => null, + 'myValue' => null, ], ], ]; From 653d6d487ee3fcf45ce22617cf531808c366dda9 Mon Sep 17 00:00:00 2001 From: Edie Lemoine Date: Thu, 14 Nov 2024 15:54:09 +0100 Subject: [PATCH 08/12] refactor!: move CASE_ constants to Str --- src/Base/Concern/HasAttributes.php | 4 ++-- src/Base/Contract/Arrayable.php | 14 +++++++------- src/Base/Model/Model.php | 6 +++--- src/Base/Support/Str.php | 18 ++++++++++++------ src/Shipment/Response/GetShipmentsResponse.php | 4 ++-- tests/Unit/Base/Model/ModelToArrayTest.php | 3 ++- tests/Unit/Base/Support/UtilsTest.php | 5 ++--- 7 files changed, 30 insertions(+), 24 deletions(-) diff --git a/src/Base/Concern/HasAttributes.php b/src/Base/Concern/HasAttributes.php index 0e29405dd..c737ab1cf 100644 --- a/src/Base/Concern/HasAttributes.php +++ b/src/Base/Concern/HasAttributes.php @@ -214,7 +214,7 @@ public function getAttributes(?int $flags = null): array }); } - if ($flags & Arrayable::CASE_SNAKE || $flags & Arrayable::CASE_KEBAB || $flags & Arrayable::CASE_STUDLY) { + if ($flags & Str::CASE_SNAKE || $flags & Str::CASE_KEBAB || $flags & Str::CASE_STUDLY) { $attributes = Utils::changeArrayKeysCase($this->attributes, $flags); } } @@ -340,7 +340,7 @@ protected function addCastAttributesToArray(array $attributes, array $mutatedAtt } } - if ($flags & Arrayable::CASE_SNAKE || $flags & Arrayable::CASE_KEBAB || $flags & Arrayable::CASE_STUDLY) { + if ($flags & Str::CASE_SNAKE || $flags & Str::CASE_KEBAB || $flags & Str::CASE_STUDLY) { $attributes = Utils::changeArrayKeysCase($attributes, $flags); } } diff --git a/src/Base/Contract/Arrayable.php b/src/Base/Contract/Arrayable.php index 786571b2e..da788e1be 100644 --- a/src/Base/Contract/Arrayable.php +++ b/src/Base/Contract/Arrayable.php @@ -4,17 +4,17 @@ namespace MyParcelNL\Pdk\Base\Contract; +use MyParcelNL\Pdk\Base\Support\Str; + interface Arrayable { - public const CASE_SNAKE = 1; - public const CASE_KEBAB = 2; - public const CASE_STUDLY = 4; - public const SKIP_NULL = 8; - public const STORABLE = 16; - public const RECURSIVE = 32; + // Starts at 8 to support Str::CASE_* constants + public const SKIP_NULL = 8; + public const STORABLE = 16; + public const RECURSIVE = 32; // Combinations public const STORABLE_NULL = self::STORABLE | self::SKIP_NULL | self::RECURSIVE; - public const ENCODED = self::SKIP_NULL | self::CASE_SNAKE | self::RECURSIVE; + public const ENCODED = self::SKIP_NULL | Str::CASE_SNAKE | self::RECURSIVE; /** * Get the instance as an array. diff --git a/src/Base/Model/Model.php b/src/Base/Model/Model.php index 073111aca..1a753347f 100644 --- a/src/Base/Model/Model.php +++ b/src/Base/Model/Model.php @@ -254,7 +254,7 @@ public function toArrayWithoutNull(): array */ public function toKebabCaseArray(): array { - return $this->toArray(Arrayable::CASE_KEBAB); + return $this->toArray(Str::CASE_KEBAB); } /** @@ -262,7 +262,7 @@ public function toKebabCaseArray(): array */ public function toSnakeCaseArray(): array { - return $this->toArray(Arrayable::CASE_SNAKE); + return $this->toArray(Str::CASE_SNAKE); } /** @@ -278,7 +278,7 @@ public function toStorableArray(): array */ public function toStudlyCaseArray(): array { - return $this->toArray(Arrayable::CASE_STUDLY); + return $this->toArray(Str::CASE_STUDLY); } /** diff --git a/src/Base/Support/Str.php b/src/Base/Support/Str.php index 18c72eff1..1d9bb30f5 100644 --- a/src/Base/Support/Str.php +++ b/src/Base/Support/Str.php @@ -4,10 +4,12 @@ namespace MyParcelNL\Pdk\Base\Support; -use MyParcelNL\Pdk\Base\Contract\Arrayable; - class Str extends \Illuminate\Support\Str { + public const CASE_SNAKE = 1; + public const CASE_KEBAB = 2; + public const CASE_STUDLY = 4; + /** * @var array */ @@ -35,7 +37,11 @@ public static function changeCase(string $string, ?int $flags = null): string */ public static function limit($value, $limit = 100, $end = '...'): string { - return parent::limit($value, $limit - strlen($end), $end); + if (mb_strwidth($value, 'UTF-8') <= $limit) { + return $value; + } + + return rtrim(mb_strimwidth($value, 0, $limit - mb_strwidth($end, 'UTF-8'), '', 'UTF-8')) . $end; } /** @@ -48,15 +54,15 @@ private static function getFlagCase(?int $flags = null): string if (! isset(self::$flagCaseCache[$flags])) { $case = 'camel'; - if ($flags & Arrayable::CASE_SNAKE) { + if ($flags & self::CASE_SNAKE) { $case = 'snake'; } - if ($flags & Arrayable::CASE_KEBAB) { + if ($flags & self::CASE_KEBAB) { $case = 'kebab'; } - if ($flags & Arrayable::CASE_STUDLY) { + if ($flags & self::CASE_STUDLY) { $case = 'studly'; } diff --git a/src/Shipment/Response/GetShipmentsResponse.php b/src/Shipment/Response/GetShipmentsResponse.php index 978663d8f..4dcc336c2 100644 --- a/src/Shipment/Response/GetShipmentsResponse.php +++ b/src/Shipment/Response/GetShipmentsResponse.php @@ -6,8 +6,8 @@ use MyParcelNL\Pdk\Api\Concern\DecodesAddressFields; use MyParcelNL\Pdk\Api\Response\ApiResponseWithBody; -use MyParcelNL\Pdk\Base\Contract\Arrayable; use MyParcelNL\Pdk\Base\Support\Arr; +use MyParcelNL\Pdk\Base\Support\Str; use MyParcelNL\Pdk\Shipment\Collection\ShipmentCollection; use MyParcelNL\Pdk\Shipment\Model\Shipment; use MyParcelNL\Pdk\Shipment\Model\ShipmentOptions; @@ -102,7 +102,7 @@ private function decodeShipment(array $data): Shipment */ private function getShipmentOptions(array $options): array { - $keys = array_keys((new ShipmentOptions())->getAttributes(Arrayable::CASE_SNAKE)); + $keys = array_keys((new ShipmentOptions())->getAttributes(Str::CASE_SNAKE)); $shipmentOptions = Arr::only($options, $keys); $shipmentOptions['insurance'] = $options['insurance']['amount'] ?? null; diff --git a/tests/Unit/Base/Model/ModelToArrayTest.php b/tests/Unit/Base/Model/ModelToArrayTest.php index 6d7563ce8..b0e37d5fc 100644 --- a/tests/Unit/Base/Model/ModelToArrayTest.php +++ b/tests/Unit/Base/Model/ModelToArrayTest.php @@ -6,6 +6,7 @@ namespace MyParcelNL\Pdk\Base\Model; use MyParcelNL\Pdk\Base\Contract\Arrayable; +use MyParcelNL\Pdk\Base\Support\Str; use MyParcelNL\Pdk\Tests\Mocks\MockNestedModel; const MODEL_DATA = [ @@ -81,7 +82,7 @@ }); it('can combine case and skipping null', function () { - expect((new MockNestedModel(MODEL_DATA))->toArray(Arrayable::SKIP_NULL | Arrayable::CASE_KEBAB))->toBe([ + expect((new MockNestedModel(MODEL_DATA))->toArray(Arrayable::SKIP_NULL | Str::CASE_KEBAB))->toBe([ 'my-value' => '1', 'my-model' => [ 'my-model' => [], diff --git a/tests/Unit/Base/Support/UtilsTest.php b/tests/Unit/Base/Support/UtilsTest.php index 1dcd71408..728bb56fa 100644 --- a/tests/Unit/Base/Support/UtilsTest.php +++ b/tests/Unit/Base/Support/UtilsTest.php @@ -6,7 +6,6 @@ namespace MyParcelNL\Pdk\Base\Support; use DateTime; -use MyParcelNL\Pdk\Base\Contract\Arrayable; use MyParcelNL\Pdk\Tests\Mocks\MockBeConcerned; use MyParcelNL\Pdk\Tests\Mocks\MockCastModel; use MyParcelNL\Pdk\Tests\Mocks\MockClassWithTrait; @@ -28,8 +27,8 @@ expect(Utils::changeArrayKeysCase($input, $flags))->toEqual($expectation); })->with([ 'to camelCase' => [null, ['snakeCase' => 1, 'camelCase' => 2, 'studlyCase' => 3]], - 'to snake_case' => [Arrayable::CASE_SNAKE, ['snake_case' => 1, 'camel_case' => 2, 'studly_case' => 3]], - 'to StudlyCase' => [Arrayable::CASE_STUDLY, ['SnakeCase' => 1, 'CamelCase' => 2, 'StudlyCase' => 3]], + 'to snake_case' => [Str::CASE_SNAKE, ['snake_case' => 1, 'camel_case' => 2, 'studly_case' => 3]], + 'to StudlyCase' => [Str::CASE_STUDLY, ['SnakeCase' => 1, 'CamelCase' => 2, 'StudlyCase' => 3]], ]); it('converts id to name', function ($input, $output) { From 5ef784eb5b5c32e92e3e2e1e6e584fa40dccba7e Mon Sep 17 00:00:00 2001 From: Edie Lemoine Date: Thu, 14 Nov 2024 15:57:28 +0100 Subject: [PATCH 09/12] test: add test for changing string case --- tests/Unit/Base/Support/StrTest.php | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/tests/Unit/Base/Support/StrTest.php b/tests/Unit/Base/Support/StrTest.php index 5b313f6bf..6f461002d 100644 --- a/tests/Unit/Base/Support/StrTest.php +++ b/tests/Unit/Base/Support/StrTest.php @@ -17,3 +17,32 @@ ['short enough', 40, '_-.', 'short enough'], ['broccoli', 5, '~', 'broc~'], ]); + +it('changes string case', function (string $string, ?int $flags, string $result) { + expect(Str::changeCase($string, $flags))->toBe($result); +})->with([ + ['my string', null, 'myString'], + ['my string', Str::CASE_KEBAB, 'my-string'], + ['my string', Str::CASE_SNAKE, 'my_string'], + ['my string', Str::CASE_STUDLY, 'MyString'], + + ['myString', null, 'myString'], + ['myString', Str::CASE_SNAKE, 'my_string'], + ['myString', Str::CASE_KEBAB, 'my-string'], + ['myString', Str::CASE_STUDLY, 'MyString'], + + ['my-string', null, 'myString'], + // Kebab can't be converted to snake + ['my-string', Str::CASE_KEBAB, 'my-string'], + ['my-string', Str::CASE_STUDLY, 'MyString'], + + ['my_string', null, 'myString'], + ['my_string', Str::CASE_SNAKE, 'my_string'], + // Snake can't be converted to kebab + ['my_string', Str::CASE_STUDLY, 'MyString'], + + ['MyString', null, 'myString'], + ['MyString', Str::CASE_SNAKE, 'my_string'], + ['MyString', Str::CASE_KEBAB, 'my-string'], + ['MyString', Str::CASE_STUDLY, 'MyString'], +]); From 6726bd5954c6eb4be91bb264cb04acaaf94c10ce Mon Sep 17 00:00:00 2001 From: Edie Lemoine Date: Thu, 14 Nov 2024 16:32:38 +0100 Subject: [PATCH 10/12] chore: update phpstan baseline --- phpstan-baseline.php | 31 +++++++++++-------------------- 1 file changed, 11 insertions(+), 20 deletions(-) diff --git a/phpstan-baseline.php b/phpstan-baseline.php index 6638f063c..e8f7bbec9 100644 --- a/phpstan-baseline.php +++ b/phpstan-baseline.php @@ -2,76 +2,67 @@ $ignoreErrors = []; $ignoreErrors[] = [ + // identifier: isset.offset 'message' => '#^Offset \'date\' on array\\{date\\: string, timezone\\: string, timezone_type\\: int\\} in isset\\(\\) always exists and is not nullable\\.$#', 'count' => 1, 'path' => __DIR__ . '/src/Base/Model/Model.php', ]; $ignoreErrors[] = [ + // identifier: return.phpDocType 'message' => '#^PHPDoc tag @return with type void is incompatible with native type string\\.$#', 'count' => 1, 'path' => __DIR__ . '/src/Base/Model/Model.php', ]; $ignoreErrors[] = [ + // identifier: assign.propertyType 'message' => '#^Static property MyParcelNL\\\\Pdk\\\\Base\\\\PdkBootstrapper\\:\\:\\$pdk \\(MyParcelNL\\\\Pdk\\\\Base\\\\Pdk\\) does not accept MyParcelNL\\\\Pdk\\\\Base\\\\Concern\\\\PdkInterface\\.$#', 'count' => 1, 'path' => __DIR__ . '/src/Base/PdkBootstrapper.php', ]; $ignoreErrors[] = [ + // identifier: booleanNot.alwaysTrue 'message' => '#^Negated boolean expression is always true\\.$#', 'count' => 2, 'path' => __DIR__ . '/src/Base/Service/CurrencyService.php', ]; $ignoreErrors[] = [ - 'message' => '#^Negated boolean expression is always false\\.$#', - 'count' => 1, - 'path' => __DIR__ . '/src/Base/Support/Arr.php', -]; -$ignoreErrors[] = [ - 'message' => '#^PHPDoc tag @mixin contains invalid type MyParcelNL\\\\Pdk\\\\Carrier\\\\Concern\\\\HasDeprecatedSubscriptionId\\.$#', - 'count' => 1, - 'path' => __DIR__ . '/src/Carrier/Model/Carrier.php', -]; -$ignoreErrors[] = [ + // identifier: return.phpDocType 'message' => '#^PHPDoc tag @return with type void is incompatible with native type MyParcelNL\\\\Pdk\\\\Settings\\\\Model\\\\Settings\\.$#', 'count' => 1, 'path' => __DIR__ . '/src/Settings/Repository/AbstractPdkSettingsRepository.php', ]; $ignoreErrors[] = [ + // identifier: varTag.differentVariable 'message' => '#^Variable \\$existing in PHPDoc tag @var does not match assigned variable \\$id\\.$#', 'count' => 1, 'path' => __DIR__ . '/src/Settings/Repository/AbstractPdkSettingsRepository.php', ]; $ignoreErrors[] = [ + // identifier: return.phpDocType 'message' => '#^PHPDoc tag @return with type void is incompatible with native type array\\.$#', 'count' => 1, 'path' => __DIR__ . '/src/Shipment/Collection/ShipmentCollection.php', ]; $ignoreErrors[] = [ + // identifier: method.notFound 'message' => '#^Call to an undefined method MyParcelNL\\\\Pdk\\\\Api\\\\Contract\\\\ApiServiceInterface\\:\\:getBaseUrl\\(\\)\\.$#', 'count' => 1, 'path' => __DIR__ . '/src/Shipment/Repository/ShipmentRepository.php', ]; $ignoreErrors[] = [ + // identifier: return.phpDocType 'message' => '#^PHPDoc tag @return with type MyParcelNL\\\\Pdk\\\\Shipment\\\\Collection\\\\ShipmentCollection is incompatible with native type string\\.$#', 'count' => 1, 'path' => __DIR__ . '/src/Shipment/Repository/ShipmentRepository.php', ]; $ignoreErrors[] = [ - 'message' => '#^Property MyParcelNL\\\\Pdk\\\\Shipment\\\\Request\\\\FetchShipmentsRequest\\:\\:\\$ids \\(MyParcelNL\\\\Pdk\\\\Base\\\\Support\\\\Collection\\) does not accept MyParcelNL\\\\Sdk\\\\src\\\\Support\\\\Collection\\.$#', - 'count' => 1, - 'path' => __DIR__ . '/src/Shipment/Request/FetchShipmentsRequest.php', -]; -$ignoreErrors[] = [ - 'message' => '#^Property MyParcelNL\\\\Pdk\\\\Shipment\\\\Request\\\\FetchShipmentsRequest\\:\\:\\$referenceIdentifiers \\(MyParcelNL\\\\Pdk\\\\Base\\\\Support\\\\Collection\\) does not accept MyParcelNL\\\\Sdk\\\\src\\\\Support\\\\Collection\\.$#', - 'count' => 1, - 'path' => __DIR__ . '/src/Shipment/Request/FetchShipmentsRequest.php', -]; -$ignoreErrors[] = [ + // identifier: nullCoalesce.offset 'message' => '#^Offset \'positions\' on array\\{string, string\\} on left side of \\?\\? does not exist\\.$#', 'count' => 1, 'path' => __DIR__ . '/src/Shipment/Request/GetLabelsRequest.php', ]; $ignoreErrors[] = [ + // identifier: method.notFound 'message' => '#^Call to an undefined method DateTimeInterface\\:\\:modify\\(\\)\\.$#', 'count' => 1, 'path' => __DIR__ . '/src/Shipment/Service/DropOffService.php', From 26d72025122ba8d843c10f6603cd1fdaaeb9f994 Mon Sep 17 00:00:00 2001 From: Edie Lemoine Date: Thu, 14 Nov 2024 16:35:55 +0100 Subject: [PATCH 11/12] chore: add junit.xml to gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index fea352f4d..361f75f48 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,7 @@ .yarn-*.log composer.lock clover.xml +junit.xml docker-compose.override.yml .env From 69ef295b87c030020b2cd03eb7ae54332a21b4e9 Mon Sep 17 00:00:00 2001 From: Edie Lemoine Date: Wed, 20 Nov 2024 16:10:29 +0100 Subject: [PATCH 12/12] test: update snapshots --- ...hide_sender__data_set_carrier_dhl_for_you__1.json | 4 ++-- ...export_hide_sender__data_set_single_order__1.json | 4 ++-- ...sender__data_set_various_delivery_options__1.json | 12 ++++++------ ...eceipt_code__data_set_carrier_dhl_for_you__1.json | 4 ++-- ...xport_receipt_code__data_set_single_order__1.json | 4 ++-- ...t_code__data_set_various_delivery_options__1.json | 12 ++++++------ ...arge_format__data_set_carrier_dhl_for_you__1.json | 4 ++-- ...eturn_large_format__data_set_single_order__1.json | 4 ++-- ...format__data_set_various_delivery_options__1.json | 12 ++++++------ 9 files changed, 30 insertions(+), 30 deletions(-) diff --git a/tests/__snapshots__/ExportOrderActionTest__it_exports_order_with_data_set_order_mode__data_set_export_hide_sender__data_set_carrier_dhl_for_you__1.json b/tests/__snapshots__/ExportOrderActionTest__it_exports_order_with_data_set_order_mode__data_set_export_hide_sender__data_set_carrier_dhl_for_you__1.json index 9dc510010..83aa831d5 100644 --- a/tests/__snapshots__/ExportOrderActionTest__it_exports_order_with_data_set_order_mode__data_set_export_hide_sender__data_set_carrier_dhl_for_you__1.json +++ b/tests/__snapshots__/ExportOrderActionTest__it_exports_order_with_data_set_order_mode__data_set_export_hide_sender__data_set_carrier_dhl_for_you__1.json @@ -16,8 +16,8 @@ "order_lines": [ { "quantity": 1, - "price": 0, - "price_after_vat": 0, + "price": 1000, + "price_after_vat": 1000, "product": { "sku": "test", "external_identifier": "PDK-1", diff --git a/tests/__snapshots__/ExportOrderActionTest__it_exports_order_with_data_set_order_mode__data_set_export_hide_sender__data_set_single_order__1.json b/tests/__snapshots__/ExportOrderActionTest__it_exports_order_with_data_set_order_mode__data_set_export_hide_sender__data_set_single_order__1.json index 7a596d1e6..333180869 100644 --- a/tests/__snapshots__/ExportOrderActionTest__it_exports_order_with_data_set_order_mode__data_set_export_hide_sender__data_set_single_order__1.json +++ b/tests/__snapshots__/ExportOrderActionTest__it_exports_order_with_data_set_order_mode__data_set_export_hide_sender__data_set_single_order__1.json @@ -16,8 +16,8 @@ "order_lines": [ { "quantity": 1, - "price": 0, - "price_after_vat": 0, + "price": 1000, + "price_after_vat": 1000, "product": { "sku": "test", "external_identifier": "PDK-1", diff --git a/tests/__snapshots__/ExportOrderActionTest__it_exports_order_with_data_set_order_mode__data_set_export_hide_sender__data_set_various_delivery_options__1.json b/tests/__snapshots__/ExportOrderActionTest__it_exports_order_with_data_set_order_mode__data_set_export_hide_sender__data_set_various_delivery_options__1.json index 164490296..e87d6fcdc 100644 --- a/tests/__snapshots__/ExportOrderActionTest__it_exports_order_with_data_set_order_mode__data_set_export_hide_sender__data_set_various_delivery_options__1.json +++ b/tests/__snapshots__/ExportOrderActionTest__it_exports_order_with_data_set_order_mode__data_set_export_hide_sender__data_set_various_delivery_options__1.json @@ -16,8 +16,8 @@ "order_lines": [ { "quantity": 5, - "price": 0, - "price_after_vat": 0, + "price": 1000, + "price_after_vat": 1000, "product": { "sku": "test", "external_identifier": "PDK-2", @@ -79,8 +79,8 @@ "order_lines": [ { "quantity": 1, - "price": 0, - "price_after_vat": 0, + "price": 1000, + "price_after_vat": 1000, "product": { "sku": "test", "external_identifier": "PDK-3", @@ -143,8 +143,8 @@ "order_lines": [ { "quantity": 1, - "price": 0, - "price_after_vat": 0, + "price": 1000, + "price_after_vat": 1000, "product": { "sku": "test", "external_identifier": "PDK-4", diff --git a/tests/__snapshots__/ExportOrderActionTest__it_exports_order_with_data_set_order_mode__data_set_export_receipt_code__data_set_carrier_dhl_for_you__1.json b/tests/__snapshots__/ExportOrderActionTest__it_exports_order_with_data_set_order_mode__data_set_export_receipt_code__data_set_carrier_dhl_for_you__1.json index 1105f10c5..3fcdcc535 100644 --- a/tests/__snapshots__/ExportOrderActionTest__it_exports_order_with_data_set_order_mode__data_set_export_receipt_code__data_set_carrier_dhl_for_you__1.json +++ b/tests/__snapshots__/ExportOrderActionTest__it_exports_order_with_data_set_order_mode__data_set_export_receipt_code__data_set_carrier_dhl_for_you__1.json @@ -16,8 +16,8 @@ "order_lines": [ { "quantity": 1, - "price": 0, - "price_after_vat": 0, + "price": 1000, + "price_after_vat": 1000, "product": { "sku": "test", "external_identifier": "PDK-1", diff --git a/tests/__snapshots__/ExportOrderActionTest__it_exports_order_with_data_set_order_mode__data_set_export_receipt_code__data_set_single_order__1.json b/tests/__snapshots__/ExportOrderActionTest__it_exports_order_with_data_set_order_mode__data_set_export_receipt_code__data_set_single_order__1.json index 8526b1a63..7e149be87 100644 --- a/tests/__snapshots__/ExportOrderActionTest__it_exports_order_with_data_set_order_mode__data_set_export_receipt_code__data_set_single_order__1.json +++ b/tests/__snapshots__/ExportOrderActionTest__it_exports_order_with_data_set_order_mode__data_set_export_receipt_code__data_set_single_order__1.json @@ -16,8 +16,8 @@ "order_lines": [ { "quantity": 1, - "price": 0, - "price_after_vat": 0, + "price": 1000, + "price_after_vat": 1000, "product": { "sku": "test", "external_identifier": "PDK-1", diff --git a/tests/__snapshots__/ExportOrderActionTest__it_exports_order_with_data_set_order_mode__data_set_export_receipt_code__data_set_various_delivery_options__1.json b/tests/__snapshots__/ExportOrderActionTest__it_exports_order_with_data_set_order_mode__data_set_export_receipt_code__data_set_various_delivery_options__1.json index 04628a7bb..898cd9446 100644 --- a/tests/__snapshots__/ExportOrderActionTest__it_exports_order_with_data_set_order_mode__data_set_export_receipt_code__data_set_various_delivery_options__1.json +++ b/tests/__snapshots__/ExportOrderActionTest__it_exports_order_with_data_set_order_mode__data_set_export_receipt_code__data_set_various_delivery_options__1.json @@ -16,8 +16,8 @@ "order_lines": [ { "quantity": 5, - "price": 0, - "price_after_vat": 0, + "price": 1000, + "price_after_vat": 1000, "product": { "sku": "test", "external_identifier": "PDK-2", @@ -79,8 +79,8 @@ "order_lines": [ { "quantity": 1, - "price": 0, - "price_after_vat": 0, + "price": 1000, + "price_after_vat": 1000, "product": { "sku": "test", "external_identifier": "PDK-3", @@ -143,8 +143,8 @@ "order_lines": [ { "quantity": 1, - "price": 0, - "price_after_vat": 0, + "price": 1000, + "price_after_vat": 1000, "product": { "sku": "test", "external_identifier": "PDK-4", diff --git a/tests/__snapshots__/ExportOrderActionTest__it_exports_order_with_data_set_order_mode__data_set_export_return_large_format__data_set_carrier_dhl_for_you__1.json b/tests/__snapshots__/ExportOrderActionTest__it_exports_order_with_data_set_order_mode__data_set_export_return_large_format__data_set_carrier_dhl_for_you__1.json index 1105f10c5..3fcdcc535 100644 --- a/tests/__snapshots__/ExportOrderActionTest__it_exports_order_with_data_set_order_mode__data_set_export_return_large_format__data_set_carrier_dhl_for_you__1.json +++ b/tests/__snapshots__/ExportOrderActionTest__it_exports_order_with_data_set_order_mode__data_set_export_return_large_format__data_set_carrier_dhl_for_you__1.json @@ -16,8 +16,8 @@ "order_lines": [ { "quantity": 1, - "price": 0, - "price_after_vat": 0, + "price": 1000, + "price_after_vat": 1000, "product": { "sku": "test", "external_identifier": "PDK-1", diff --git a/tests/__snapshots__/ExportOrderActionTest__it_exports_order_with_data_set_order_mode__data_set_export_return_large_format__data_set_single_order__1.json b/tests/__snapshots__/ExportOrderActionTest__it_exports_order_with_data_set_order_mode__data_set_export_return_large_format__data_set_single_order__1.json index 7a596d1e6..333180869 100644 --- a/tests/__snapshots__/ExportOrderActionTest__it_exports_order_with_data_set_order_mode__data_set_export_return_large_format__data_set_single_order__1.json +++ b/tests/__snapshots__/ExportOrderActionTest__it_exports_order_with_data_set_order_mode__data_set_export_return_large_format__data_set_single_order__1.json @@ -16,8 +16,8 @@ "order_lines": [ { "quantity": 1, - "price": 0, - "price_after_vat": 0, + "price": 1000, + "price_after_vat": 1000, "product": { "sku": "test", "external_identifier": "PDK-1", diff --git a/tests/__snapshots__/ExportOrderActionTest__it_exports_order_with_data_set_order_mode__data_set_export_return_large_format__data_set_various_delivery_options__1.json b/tests/__snapshots__/ExportOrderActionTest__it_exports_order_with_data_set_order_mode__data_set_export_return_large_format__data_set_various_delivery_options__1.json index 164490296..e87d6fcdc 100644 --- a/tests/__snapshots__/ExportOrderActionTest__it_exports_order_with_data_set_order_mode__data_set_export_return_large_format__data_set_various_delivery_options__1.json +++ b/tests/__snapshots__/ExportOrderActionTest__it_exports_order_with_data_set_order_mode__data_set_export_return_large_format__data_set_various_delivery_options__1.json @@ -16,8 +16,8 @@ "order_lines": [ { "quantity": 5, - "price": 0, - "price_after_vat": 0, + "price": 1000, + "price_after_vat": 1000, "product": { "sku": "test", "external_identifier": "PDK-2", @@ -79,8 +79,8 @@ "order_lines": [ { "quantity": 1, - "price": 0, - "price_after_vat": 0, + "price": 1000, + "price_after_vat": 1000, "product": { "sku": "test", "external_identifier": "PDK-3", @@ -143,8 +143,8 @@ "order_lines": [ { "quantity": 1, - "price": 0, - "price_after_vat": 0, + "price": 1000, + "price_after_vat": 1000, "product": { "sku": "test", "external_identifier": "PDK-4",