From 3c5b94c7926f55dafdec4a0f1af30cda3418e598 Mon Sep 17 00:00:00 2001 From: Mohammed Elhaouari Date: Wed, 30 Oct 2024 22:37:21 +0100 Subject: [PATCH 1/2] add php8.3 --- .github/ISSUE_TEMPLATE/bug_report.md | 1 + .github/workflows/php.yml | 2 +- composer.json | 17 ++--- src/Concerns/CastsToJson.php | 4 +- src/Concerns/HasCollection.php | 13 +--- src/Contracts/Amount.php | 11 --- src/Contracts/Arrayable.php | 2 - src/Contracts/Jsonable.php | 4 -- src/Exceptions/InvalidOrderException.php | 2 +- src/Exceptions/JsonEncodingException.php | 4 +- src/Orders/Amount.php | 15 +--- src/Orders/AmountBreakdown.php | 9 +-- src/Orders/ApplicationContext.php | 36 ++-------- src/Orders/Item.php | 20 ++---- src/Orders/Order.php | 31 ++------- src/Orders/Payee.php | 4 -- src/Orders/PurchaseUnit.php | 15 ++-- src/Requests/OrderCreateRequest.php | 2 +- tests/Orders/AmountBreakdownTest.php | 79 +++++++++++----------- tests/Orders/AmountTest.php | 40 +++++------ tests/Orders/ApplicationContextTest.php | 41 ++++++----- tests/Orders/ItemTest.php | 27 ++++---- tests/Orders/OrderTest.php | 30 ++++---- tests/Orders/PayeeTest.php | 10 +-- tests/Orders/PurchaseUnitTest.php | 20 +++--- tests/Pest.php | 1 + tests/Requests/OrderCaptureRequestTest.php | 8 +-- tests/Requests/OrderCreateRequestTest.php | 20 +++--- tests/Requests/OrderShowRequestTest.php | 10 +-- 29 files changed, 183 insertions(+), 295 deletions(-) diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md index 891c617..9a3c65c 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.md +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -12,6 +12,7 @@ A clear and concise description of what the bug is. **To Reproduce** Steps to reproduce the behavior: + 1. Go to '...' 2. Click on '....' 3. Scroll down to '....' diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml index 63de439..96cf32f 100644 --- a/.github/workflows/php.yml +++ b/.github/workflows/php.yml @@ -9,7 +9,7 @@ jobs: fail-fast: true matrix: os: [ubuntu-latest, windows-latest] - php: [8.1, 8.0, 7.4] + php: [8.3, 8.2, 8.1, 7.4] stability: [prefer-stable] name: PHP${{ matrix.php }} - ${{ matrix.stability }} - ${{ matrix.os }} diff --git a/composer.json b/composer.json index 699cf91..f65f6a8 100644 --- a/composer.json +++ b/composer.json @@ -17,15 +17,15 @@ } ], "require": { - "php": "^7.4|^8.0|^8.1", + "php": "^7.4|^8.0|^8.1|^8.2|^8.3", "ext-json": "*", "brick/money": "^0.5.2", "phpjuice/paypal-http-client": "^1.0" }, "require-dev": { - "squizlabs/php_codesniffer": "^3.4", - "phpstan/phpstan": "^0.12", - "pestphp/pest": "^1.18" + "laravel/pint": "^1.18", + "pestphp/pest": "^1.18", + "phpstan/phpstan": "^0.12" }, "autoload": { "psr-4": { @@ -41,11 +41,8 @@ "prefer-stable": true, "scripts": { "test": "vendor/bin/pest --colors=always", - "analyse": "phpstan analyse --ansi --debug", - "php-cs-fixer": [ - "php-cs-fixer fix src --rules=@PSR2", - "php-cs-fixer fix tests --rules=@PSR2" - ] + "pint": "./vendor/bin/pint", + "analyse": "phpstan analyse --ansi --debug" }, "config": { "sort-packages": true, @@ -53,4 +50,4 @@ "pestphp/pest-plugin": true } } -} +} \ No newline at end of file diff --git a/src/Concerns/CastsToJson.php b/src/Concerns/CastsToJson.php index 44e198f..6c0c011 100644 --- a/src/Concerns/CastsToJson.php +++ b/src/Concerns/CastsToJson.php @@ -19,9 +19,7 @@ public function __toString() /** * Convert the model instance to JSON. * - * @param int $options * - * @return string * * @throws JsonEncodingException */ @@ -29,7 +27,7 @@ public function toJson(int $options = 0): string { $json = json_encode($this->toArray(), $options); - if (JSON_ERROR_NONE !== json_last_error() || !$json) { + if (json_last_error() !== JSON_ERROR_NONE || ! $json) { throw new JsonEncodingException(json_last_error_msg()); } diff --git a/src/Concerns/HasCollection.php b/src/Concerns/HasCollection.php index 03d8dc8..0c4bfae 100644 --- a/src/Concerns/HasCollection.php +++ b/src/Concerns/HasCollection.php @@ -9,7 +9,6 @@ trait HasCollection /** * Determine if an attribute or relation exists on the model. * - * @param string $key * * @return bool */ @@ -20,9 +19,6 @@ public function __isset(string $key) /** * Determine if a key exists on the items. - * - * @param string $offset - * @return bool */ public function offsetExists(string $offset): bool { @@ -32,7 +28,6 @@ public function offsetExists(string $offset): bool /** * Unset an attribute on the model. * - * @param string $key * * @return void */ @@ -44,7 +39,6 @@ public function __unset(string $key) /** * Unset an attribute on the model. * - * @param string $offset * @return void */ public function offsetUnset(string $offset) @@ -53,8 +47,8 @@ public function offsetUnset(string $offset) } /** - * @param mixed $offset - * @param mixed $value + * @param mixed $offset + * @param mixed $value * @return void */ public function offsetSet($offset, $value) @@ -67,7 +61,6 @@ public function offsetSet($offset, $value) } /** - * @param string $offset * @return mixed|Item|null */ public function offsetGet(string $offset) @@ -77,8 +70,6 @@ public function offsetGet(string $offset) /** * Determine if the purchase unit is empty or not. - * - * @return bool */ public function isEmpty(): bool { diff --git a/src/Contracts/Amount.php b/src/Contracts/Amount.php index 51bd9c6..6839459 100644 --- a/src/Contracts/Amount.php +++ b/src/Contracts/Amount.php @@ -6,26 +6,15 @@ interface Amount { /** * convert amount to an array. - * @return array */ public function toArray(): array; - /** - * @return string - */ public function getCurrencyCode(): string; - /** - * @return string - */ public function getValue(): string; /** * Convert the object to its JSON representation. - * - * @param int $options - * - * @return string */ public function toJson(int $options = 0): string; } diff --git a/src/Contracts/Arrayable.php b/src/Contracts/Arrayable.php index 701aec2..fb87f7d 100644 --- a/src/Contracts/Arrayable.php +++ b/src/Contracts/Arrayable.php @@ -6,8 +6,6 @@ interface Arrayable { /** * Get the instance as an array. - * - * @return array */ public function toArray(): array; } diff --git a/src/Contracts/Jsonable.php b/src/Contracts/Jsonable.php index 5b5c9bf..7360933 100644 --- a/src/Contracts/Jsonable.php +++ b/src/Contracts/Jsonable.php @@ -6,10 +6,6 @@ interface Jsonable { /** * Convert the object to its JSON representation. - * - * @param int $options - * - * @return string */ public function toJson(int $options = 0): string; } diff --git a/src/Exceptions/InvalidOrderException.php b/src/Exceptions/InvalidOrderException.php index 4300eda..af2d7d4 100644 --- a/src/Exceptions/InvalidOrderException.php +++ b/src/Exceptions/InvalidOrderException.php @@ -8,6 +8,6 @@ class InvalidOrderException extends RuntimeException { public static function invalidPurchaseUnit(): InvalidOrderException { - return new self("Paypal orders must have 1 purchase_unit at least."); + return new self('Paypal orders must have 1 purchase_unit at least.'); } } diff --git a/src/Exceptions/JsonEncodingException.php b/src/Exceptions/JsonEncodingException.php index 4158bc8..f2c5656 100644 --- a/src/Exceptions/JsonEncodingException.php +++ b/src/Exceptions/JsonEncodingException.php @@ -4,6 +4,4 @@ use RuntimeException; -class JsonEncodingException extends RuntimeException -{ -} +class JsonEncodingException extends RuntimeException {} diff --git a/src/Orders/Amount.php b/src/Orders/Amount.php index cbffd7e..a177149 100644 --- a/src/Orders/Amount.php +++ b/src/Orders/Amount.php @@ -16,15 +16,12 @@ class Amount implements AmountContract /** * The three-character ISO-4217 currency code that identifies the currency. - * - * @var Money */ protected Money $money; /** * create a new amount instance. - * @param string $value - * @param string $currency_code + * * @throws UnknownCurrencyException */ public function __construct(string $value, string $currency_code = 'USD') @@ -33,9 +30,6 @@ public function __construct(string $value, string $currency_code = 'USD') } /** - * @param string $value - * @param string $currency_code - * @return Amount * @throws UnknownCurrencyException */ public static function of(string $value, string $currency_code = 'USD'): Amount @@ -45,7 +39,6 @@ public static function of(string $value, string $currency_code = 'USD'): Amount /** * convert amount to an array. - * @return array */ public function toArray(): array { @@ -55,17 +48,11 @@ public function toArray(): array ]; } - /** - * @return string - */ public function getCurrencyCode(): string { return $this->money->getCurrency()->getCurrencyCode(); } - /** - * @return string - */ public function getValue(): string { return (string) $this->money->getAmount(); diff --git a/src/Orders/AmountBreakdown.php b/src/Orders/AmountBreakdown.php index e931489..d31dc82 100644 --- a/src/Orders/AmountBreakdown.php +++ b/src/Orders/AmountBreakdown.php @@ -14,20 +14,17 @@ class AmountBreakdown extends Amount * The subtotal for all items. Required if the request includes purchase_units[].items[].unit_amount. * Must equal the sum of (items[].unit_amount * items[].quantity) for all items. * item_total.value can not be a negative number. - * @var Money */ protected Money $item_total; /** * The discount for all items within a given purchase_unit. discount.value can not be a negative number. - * @var Money|null */ protected ?Money $discount = null; /** * create a new AmountBreakdown instance. - * @param string $value - * @param string $currency_code + * * @throws UnknownCurrencyException */ public function __construct(string $value, string $currency_code = 'USD') @@ -37,9 +34,6 @@ public function __construct(string $value, string $currency_code = 'USD') } /** - * @param string $value - * @param string $currency_code - * @return AmountBreakdown * @throws UnknownCurrencyException */ public static function of(string $value, string $currency_code = 'USD'): self @@ -49,7 +43,6 @@ public static function of(string $value, string $currency_code = 'USD'): self /** * Get the instance as an array. - * @return array */ public function toArray(): array { diff --git a/src/Orders/ApplicationContext.php b/src/Orders/ApplicationContext.php index 82344aa..2248e32 100644 --- a/src/Orders/ApplicationContext.php +++ b/src/Orders/ApplicationContext.php @@ -32,8 +32,6 @@ class ApplicationContext implements Arrayable, Jsonable /** * The label that overrides the business name in the PayPal account on the PayPal site. - * - * @var string|null */ protected ?string $brand_name = null; @@ -41,8 +39,6 @@ class ApplicationContext implements Arrayable, Jsonable * The BCP 47-formatted locale of pages that the PayPal payment experience shows. * PayPal supports a five-character code. * Examples : da-DK, he-IL, id-ID, ja-JP, no-NO, pt-BR. - * - * @var string */ protected string $locale = 'en-US'; @@ -58,8 +54,6 @@ class ApplicationContext implements Arrayable, Jsonable * * - NO_PREFERENCE: A decimal fraction for currencies like TND * that are subdivided into thousandths. - * - * @var string */ protected string $landing_page = NO_PREFERENCE; @@ -69,22 +63,16 @@ class ApplicationContext implements Arrayable, Jsonable * - NO_SHIPPING: Redact the shipping address from the PayPal site. Recommended for digital goods. * - SET_PROVIDED_ADDRESS: Use the merchant-provided address. * The customer cannot change this address on the PayPal site. - * - * @var string */ protected string $shipping_preference = NO_SHIPPING; /** * The URL where the customer is redirected after the customer approves the payment. - * - * @var string|null */ protected ?string $return_url = null; /** * The URL where the customer is redirected after the customer cancels the payment. - * - * @var string|null */ protected ?string $cancel_url = null; @@ -100,19 +88,9 @@ class ApplicationContext implements Arrayable, Jsonable * a Pay Now button appears,Use this option when the final amount is known * when the checkout is initiated, and you want to process the payment * immediately when the customer clicks Pay Now. - * - * @var string */ protected string $user_action = ACTION_CONTINUE; - /** - * @param string|null $brand_name - * @param string $locale - * @param string $landing_page - * @param string $shipping_preference - * @param string|null $return_url - * @param string|null $cancel_url - */ public function __construct( ?string $brand_name = null, string $locale = 'en-US', @@ -165,7 +143,7 @@ public function toArray(): array return array_filter( $arrayable, function ($item) { - return null !== $item; + return $item !== null; } ); } @@ -202,8 +180,8 @@ public function getShippingPreference(): string public function setShippingPreference(string $shipping_preference): self { $validOptions = [GET_FROM_FILE, NO_SHIPPING, SET_PROVIDED_ADDRESS]; - if (!in_array($shipping_preference, $validOptions)) { - throw new InvalidShippingPreferenceException(); + if (! in_array($shipping_preference, $validOptions)) { + throw new InvalidShippingPreferenceException; } $this->shipping_preference = $shipping_preference; @@ -219,8 +197,8 @@ public function getLandingPage(): string public function setLandingPage(string $landing_page): self { $validOptions = [LOGIN, BILLING, NO_PREFERENCE]; - if (!in_array($landing_page, $validOptions)) { - throw new InvalidLandingPageException(); + if (! in_array($landing_page, $validOptions)) { + throw new InvalidLandingPageException; } $this->landing_page = $landing_page; @@ -236,8 +214,8 @@ public function getUserAction(): string public function setUserAction(string $user_action): self { $validOptions = [ACTION_CONTINUE, ACTION_PAY_NOW]; - if (!in_array($user_action, $validOptions)) { - throw new InvalidUserActionException(); + if (! in_array($user_action, $validOptions)) { + throw new InvalidUserActionException; } $this->user_action = $user_action; diff --git a/src/Orders/Item.php b/src/Orders/Item.php index e6a1690..b9b64a1 100644 --- a/src/Orders/Item.php +++ b/src/Orders/Item.php @@ -21,8 +21,6 @@ class Item implements Arrayable, Jsonable /** * The item name or title. - * - * @var string */ protected string $name; @@ -30,8 +28,6 @@ class Item implements Arrayable, Jsonable * The item price or rate per unit. * If you specify unit_amount, purchase_units[].amount.breakdown.item_total is required. * Must equal unit_amount * quantity for all items. - * - * @var AmountContract */ protected AmountContract $unit_amount; @@ -39,29 +35,21 @@ class Item implements Arrayable, Jsonable * The item tax for each unit. * If tax is specified, purchase_units[].amount.breakdown.tax_total is required. * Must equal tax * quantity for all items. - * - * @var AmountContract|null */ protected ?AmountContract $tax = null; /** * The item quantity. Must be a whole number. - * - * @var int */ protected int $quantity; /** * The stock keeping unit (SKU) for the item. - * - * @var string */ protected string $sku; /** * The detailed item description. - * - * @var string */ protected string $description = ''; @@ -69,8 +57,6 @@ class Item implements Arrayable, Jsonable * The item category type. The possible values are:.The item category type. The possible values are: * - DIGITAL_GOODS. Goods that are stored, delivered, and used in their electronic format. * - PHYSICAL_GOODS. A tangible item that can be shipped with proof of delivery. - * - * @var string */ protected string $category = DIGITAL_GOODS; @@ -87,11 +73,13 @@ public function __construct(string $name, AmountContract $amount, int $quantity /** * create a new item instance. + * * @throws UnknownCurrencyException */ public static function create(string $name, string $value, string $currency_code = 'USD', int $quantity = 1): Item { $amount = Amount::of($value, $currency_code); + return new self($name, $amount, $quantity); } @@ -213,8 +201,8 @@ public function getCategory(): ?string public function setCategory(string $category): self { $validOptions = [DIGITAL_GOODS, PHYSICAL_GOODS]; - if (!in_array($category, $validOptions)) { - throw new InvalidItemCategoryException(); + if (! in_array($category, $validOptions)) { + throw new InvalidItemCategoryException; } $this->category = $category; diff --git a/src/Orders/Order.php b/src/Orders/Order.php index 6495e98..723bb14 100644 --- a/src/Orders/Order.php +++ b/src/Orders/Order.php @@ -15,7 +15,7 @@ /** * https://developer.paypal.com/docs/api/orders/v2/#definition-order. */ -class Order implements Arrayable, Jsonable, ArrayAccess +class Order implements Arrayable, ArrayAccess, Jsonable { use CastsToJson; @@ -35,8 +35,6 @@ class Order implements Arrayable, Jsonable, ArrayAccess * * AUTHORIZE : The merchant intends to authorize a payment and place funds * on hold after the customer makes a payment. - * - * @var string */ protected string $intent; @@ -67,16 +65,12 @@ class Order implements Arrayable, Jsonable, ArrayAccess /** * The order application context. * https://developer.paypal.com/docs/api/orders/v2/#definition-order_application_context. - * - * @var ApplicationContext|null */ protected ?ApplicationContext $application_context = null; /** * The order payee. * https://developer.paypal.com/docs/api/orders/v2/#definition-payee. - * - * @var Payee|null */ protected ?Payee $payee = null; @@ -86,7 +80,7 @@ class Order implements Arrayable, Jsonable, ArrayAccess public function __construct(string $intent = CAPTURE) { $this->setIntent($intent); - $this->application_context = new ApplicationContext(); + $this->application_context = new ApplicationContext; } /** @@ -105,6 +99,7 @@ public function addPurchaseUnit(PurchaseUnit $purchase_unit): self /** * return's order purchase units. + * * @return PurchaseUnit[] */ public function getPurchaseUnits(): array @@ -114,7 +109,6 @@ public function getPurchaseUnits(): array /** * return's order application context. - * @return ApplicationContext|null */ public function getApplicationContext(): ?ApplicationContext { @@ -123,8 +117,6 @@ public function getApplicationContext(): ?ApplicationContext /** * set's order application context. - * @param ApplicationContext $application_context - * @return Order */ public function setApplicationContext(ApplicationContext $application_context): self { @@ -135,7 +127,6 @@ public function setApplicationContext(ApplicationContext $application_context): /** * return's order intent. - * @return string */ public function getIntent(): string { @@ -144,13 +135,11 @@ public function getIntent(): string /** * set's order intent. - * @param string $intent - * @return Order */ public function setIntent(string $intent): self { - if (!in_array($intent, [CAPTURE, AUTHORIZE])) { - throw new InvalidOrderIntentException(); + if (! in_array($intent, [CAPTURE, AUTHORIZE])) { + throw new InvalidOrderIntentException; } $this->intent = $intent; @@ -160,7 +149,6 @@ public function setIntent(string $intent): self /** * return's order id. - * @return string */ public function getId(): string { @@ -169,7 +157,6 @@ public function getId(): string /** * return's order status. - * @return string */ public function getStatus(): string { @@ -178,7 +165,6 @@ public function getStatus(): string /** * Get the instance as an array. - * @return array */ public function toArray(): array { @@ -189,7 +175,7 @@ public function toArray(): array return [ 'intent' => $this->intent, 'purchase_units' => array_map( - fn(PurchaseUnit $purchase_unit) => $purchase_unit->toArray(), + fn (PurchaseUnit $purchase_unit) => $purchase_unit->toArray(), $this->purchase_units ), 'application_context' => $this->application_context ? $this->application_context->toArray() : null, @@ -199,7 +185,6 @@ public function toArray(): array /** * @param mixed $offset * @param mixed $value - * @return void */ public function offsetSet($offset, $value): void { @@ -214,7 +199,6 @@ public function offsetSet($offset, $value): void * Unset an attribute on the model. * * @param mixed $offset - * @return void */ public function offsetUnset($offset): void { @@ -223,7 +207,6 @@ public function offsetUnset($offset): void /** * @param mixed $offset - * @return PurchaseUnit|null */ public function offsetGet($offset): ?PurchaseUnit { @@ -234,7 +217,6 @@ public function offsetGet($offset): ?PurchaseUnit * Determine if a key exists on the purchase_units. * * @param mixed $offset - * @return bool */ public function offsetExists($offset): bool { @@ -242,7 +224,6 @@ public function offsetExists($offset): bool } /** - * @return Payee * @noinspection PhpUnused */ public function getPayee(): ?Payee diff --git a/src/Orders/Payee.php b/src/Orders/Payee.php index 8b5fef7..b9b7987 100644 --- a/src/Orders/Payee.php +++ b/src/Orders/Payee.php @@ -15,15 +15,11 @@ class Payee implements Arrayable, Jsonable /** * The email address of merchant. - * - * @var string */ protected string $email_address; /** * The encrypted PayPal account ID of the merchant. - * - * @var string */ protected string $merchant_id; diff --git a/src/Orders/PurchaseUnit.php b/src/Orders/PurchaseUnit.php index cda2495..3bdbd90 100644 --- a/src/Orders/PurchaseUnit.php +++ b/src/Orders/PurchaseUnit.php @@ -20,8 +20,6 @@ class PurchaseUnit implements Arrayable, Jsonable * The total order Amount with an optional breakdown that provides details, * such as the total item Amount, total tax Amount, shipping, handling, insurance, * and discounts, if any. - * - * @var AmountBreakdown */ protected AmountBreakdown $amount; @@ -42,8 +40,9 @@ public function __construct(AmountBreakdown $amount) /** * push a new item into items array. + * * @param Item[] $items - * @return PurchaseUnit + * * @throws MultiCurrencyOrderException */ public function addItems(array $items): self @@ -57,14 +56,13 @@ public function addItems(array $items): self /** * push a new item into items array. - * @param Item $item - * @return PurchaseUnit + * * @throws MultiCurrencyOrderException */ public function addItem(Item $item): self { if ($item->getAmount()->getCurrencyCode() != $this->amount->getCurrencyCode()) { - throw new MultiCurrencyOrderException(); + throw new MultiCurrencyOrderException; } $this->items[] = $item; @@ -74,7 +72,6 @@ public function addItem(Item $item): self /** * return's purchase unit items. - * @return array */ public function getItems(): array { @@ -83,7 +80,6 @@ public function getItems(): array /** * return's the purchase unit amount breakdown. - * @return AmountBreakdown */ public function getAmount(): AmountBreakdown { @@ -92,14 +88,13 @@ public function getAmount(): AmountBreakdown /** * convert a purchase unit instance to array. - * @return array */ public function toArray(): array { return [ 'amount' => $this->amount->toArray(), 'items' => array_map( - fn(Item $item) => $item->toArray(), + fn (Item $item) => $item->toArray(), $this->items ), ]; diff --git a/src/Requests/OrderCreateRequest.php b/src/Requests/OrderCreateRequest.php index b6d9fa6..283d7da 100644 --- a/src/Requests/OrderCreateRequest.php +++ b/src/Requests/OrderCreateRequest.php @@ -8,7 +8,7 @@ class OrderCreateRequest extends PaypalRequest { - public function __construct(Order $order = null) + public function __construct(?Order $order = null) { $headers = [ 'Prefer' => 'return=representation', diff --git a/tests/Orders/AmountBreakdownTest.php b/tests/Orders/AmountBreakdownTest.php index 9a8afb1..dfb2972 100644 --- a/tests/Orders/AmountBreakdownTest.php +++ b/tests/Orders/AmountBreakdownTest.php @@ -1,4 +1,6 @@ - $currency->getCurrencyCode(), - 'value' => "100.00", + 'value' => '100.00', 'breakdown' => [ 'item_total' => [ 'currency_code' => $currency->getCurrencyCode(), - 'value' => "100.00", + 'value' => '100.00', ], ], ]; // Act - $amount = new AmountBreakdown("100.00", $currency->getCurrencyCode()); + $amount = new AmountBreakdown('100.00', $currency->getCurrencyCode()); // Assert expect($amount->toArray())->toBe($expected); }); - -it("can cast to an array with a discount", function () { +it('can cast to an array with a discount', function () { // Arrange $currency = Currency::of('USD'); $expected = [ 'currency_code' => $currency->getCurrencyCode(), - 'value' => "100.00", + 'value' => '100.00', 'breakdown' => [ 'item_total' => [ 'currency_code' => $currency->getCurrencyCode(), - 'value' => "150.00", + 'value' => '150.00', ], 'discount' => [ 'currency_code' => $currency->getCurrencyCode(), - 'value' => "50.00", + 'value' => '50.00', ], ], ]; // Act - $amount = new AmountBreakdown("100.00", $currency->getCurrencyCode()); - $amount->setItemTotal(Money::of("150", $currency)); - $amount->setDiscount(Money::of("50", $currency)); + $amount = new AmountBreakdown('100.00', $currency->getCurrencyCode()); + $amount->setItemTotal(Money::of('150', $currency)); + $amount->setDiscount(Money::of('50', $currency)); // Assert expect($amount->toArray())->toBe($expected); }); - -it("can cast to json", function () { +it('can cast to json', function () { // Arrange $currency = Currency::of('USD'); $expectedJson = json_encode([ - "currency_code" => $currency->getCurrencyCode(), - "value" => "100.00", - "breakdown" => [ - "item_total" => [ - "currency_code" => $currency->getCurrencyCode(), - "value" => "100.00" - ] - ] + 'currency_code' => $currency->getCurrencyCode(), + 'value' => '100.00', + 'breakdown' => [ + 'item_total' => [ + 'currency_code' => $currency->getCurrencyCode(), + 'value' => '100.00', + ], + ], ]); // Act - $amount = new AmountBreakdown("100.00", $currency->getCurrencyCode()); + $amount = new AmountBreakdown('100.00', $currency->getCurrencyCode()); // Assert expect($amount->toJson())->toBe($expectedJson); }); - -it("can cast to json with a discount", function () { +it('can cast to json with a discount', function () { // Arrange $currency = Currency::of('USD'); $expectedJson = json_encode([ - "currency_code" => "USD", - "value" => "100.00", - "breakdown" => [ - "item_total" => [ - "currency_code" => "USD", - "value" => "150.00" + 'currency_code' => 'USD', + 'value' => '100.00', + 'breakdown' => [ + 'item_total' => [ + 'currency_code' => 'USD', + 'value' => '150.00', ], - "discount" => [ - "currency_code" => "USD", - "value" => "50.00" - ] - ] + 'discount' => [ + 'currency_code' => 'USD', + 'value' => '50.00', + ], + ], ]); // Act - $amount = new AmountBreakdown("100.00", $currency->getCurrencyCode()); - $amount->setItemTotal(Money::of("150", $currency)); - $amount->setDiscount(Money::of("50", $currency)); + $amount = new AmountBreakdown('100.00', $currency->getCurrencyCode()); + $amount->setItemTotal(Money::of('150', $currency)); + $amount->setDiscount(Money::of('50', $currency)); // Assert expect($amount->toJson())->toBe($expectedJson); diff --git a/tests/Orders/AmountTest.php b/tests/Orders/AmountTest.php index 674c294..3b22881 100644 --- a/tests/Orders/AmountTest.php +++ b/tests/Orders/AmountTest.php @@ -1,14 +1,16 @@ -getCurrencyCode())->toBe($currency_code); }); -it("can initialize amount using of", function () { +it('can initialize amount using of', function () { // Arrange - $value = "100.00"; - $currency_code = "USD"; + $value = '100.00'; + $currency_code = 'USD'; // Act $amount = Amount::of($value, $currency_code); @@ -31,46 +33,46 @@ expect($amount->getCurrencyCode())->toBe($currency_code); }); -it("can cast to an array", function () { +it('can cast to an array', function () { // Arrange $expected = [ 'currency_code' => 'CAD', - 'value' => "100.00", + 'value' => '100.00', ]; // Act - $amount = new Amount("100.00", 'CAD'); + $amount = new Amount('100.00', 'CAD'); // Assert expect($amount->toArray())->toBe($expected); }); -it("can cast to an array using of", function () { +it('can cast to an array using of', function () { // Arrange $expected = [ 'currency_code' => 'CAD', - 'value' => "100.00", + 'value' => '100.00', ]; // Act - $amount = Amount::of("100.00", 'CAD'); + $amount = Amount::of('100.00', 'CAD'); // Assert expect($amount->toArray())->toBe($expected); }); -it("can cast to json", function () { +it('can cast to json', function () { $expectedJson = '{"currency_code":"CAD","value":"100.00"}'; - $amount = new Amount("100.00", 'CAD'); + $amount = new Amount('100.00', 'CAD'); expect($amount->toJson())->toBe($expectedJson); }); -it("can cast to json using of", function () { +it('can cast to json using of', function () { $expectedJson = '{"currency_code":"CAD","value":"100.00"}'; - $amount = Amount::of("100.00", 'CAD'); + $amount = Amount::of('100.00', 'CAD'); expect($amount->toJson())->toBe($expectedJson); }); -it("throws unknown currency exception", function () { - Amount::of("100.00", 'R'); +it('throws unknown currency exception', function () { + Amount::of('100.00', 'R'); })->throws(UnknownCurrencyException::class); diff --git a/tests/Orders/ApplicationContextTest.php b/tests/Orders/ApplicationContextTest.php index 0c0f3fc..024e3bd 100644 --- a/tests/Orders/ApplicationContextTest.php +++ b/tests/Orders/ApplicationContextTest.php @@ -7,8 +7,8 @@ use PayPal\Checkout\Exceptions\InvalidUserActionException; use PayPal\Checkout\Orders\ApplicationContext; -it("throws an exception when setting invalid user action", function () { - $applicationContext = new ApplicationContext(); +it('throws an exception when setting invalid user action', function () { + $applicationContext = new ApplicationContext; $applicationContext->setUserAction('invalid user action'); })->throws( InvalidUserActionException::class, @@ -16,16 +16,16 @@ 'User Action provided is not supported. Please refer to https://developer.paypal.com/docs/api/orders/v2/#definition-order_application_context.' ); -it("can set a valid user action", function () { - $applicationContext = new ApplicationContext(); +it('can set a valid user action', function () { + $applicationContext = new ApplicationContext; $applicationContext->setUserAction('PAY_NOW'); expect($applicationContext->getUserAction())->toBe('PAY_NOW'); $applicationContext->setUserAction('CONTINUE'); expect($applicationContext->getUserAction())->toBe('CONTINUE'); }); -it("throws an exception when setting invalid shipping preferences", function () { - $applicationContext = new ApplicationContext(); +it('throws an exception when setting invalid shipping preferences', function () { + $applicationContext = new ApplicationContext; $applicationContext->setShippingPreference('invalid shipping preference'); })->throws( InvalidShippingPreferenceException::class, @@ -33,8 +33,8 @@ 'Shipping preference provided is not supported. Please refer to https://developer.paypal.com/docs/api/orders/v2/#definition-order_application_context.' ); -it("can set shipping preferences", function () { - $applicationContext = new ApplicationContext(); +it('can set shipping preferences', function () { + $applicationContext = new ApplicationContext; expect($applicationContext->getShippingPreference())->toBe('NO_SHIPPING'); $applicationContext->setShippingPreference('GET_FROM_FILE'); expect($applicationContext->getShippingPreference())->toBe('GET_FROM_FILE'); @@ -44,8 +44,8 @@ expect($applicationContext->getShippingPreference())->toBe('SET_PROVIDED_ADDRESS'); }); -it("throws an exception when setting invalid landing page", function () { - $applicationContext = new ApplicationContext(); +it('throws an exception when setting invalid landing page', function () { + $applicationContext = new ApplicationContext; $applicationContext->setLandingPage('invalid landing page'); })->throws( InvalidLandingPageException::class, @@ -53,8 +53,8 @@ 'Landing page provided is not supported. Please refer to https://developer.paypal.com/docs/api/orders/v2/#definition-order_application_context.' // ); -it("can set landing page", function () { - $applicationContext = new ApplicationContext(); +it('can set landing page', function () { + $applicationContext = new ApplicationContext; expect($applicationContext->getLandingPage())->toBe('NO_PREFERENCE'); $applicationContext->setLandingPage('LOGIN'); expect($applicationContext->getLandingPage())->toBe('LOGIN'); @@ -64,9 +64,9 @@ expect($applicationContext->getLandingPage())->toBe('NO_PREFERENCE'); }); -it("can set locale", function () { +it('can set locale', function () { // Act - $applicationContext = new ApplicationContext(); + $applicationContext = new ApplicationContext; // Assert expect($applicationContext->getLocale())->toBe('en-US'); @@ -76,9 +76,9 @@ expect($applicationContext->getLocale())->toBe('fr'); }); -it("can set return and cancel urls", function () { +it('can set return and cancel urls', function () { // Act - $applicationContext = new ApplicationContext(); + $applicationContext = new ApplicationContext; // Assert expect($applicationContext->getReturnUrl())->toBeNull(); @@ -93,8 +93,7 @@ expect($applicationContext->getCancelUrl())->toBe('test cancel url'); }); - -it("can cast to an array with no null values", function () { +it('can cast to an array with no null values', function () { // Arrange $expected = [ 'locale' => 'en-US', @@ -104,13 +103,13 @@ ]; // Act - $applicationContext = new ApplicationContext(); + $applicationContext = new ApplicationContext; // Assert expect($applicationContext->toArray())->toBe($expected); }); -it("can cast to an array", function () { +it('can cast to an array', function () { // Arrange $expected = [ 'brand_name' => 'Paypal Inc', @@ -135,7 +134,7 @@ expect($applicationContext->toArray())->toBe($expected); }); -it("can cast to json", function () { +it('can cast to json', function () { // Arrange $expected = json_encode([ 'brand_name' => 'Paypal Inc', diff --git a/tests/Orders/ItemTest.php b/tests/Orders/ItemTest.php index 0dc18c2..f368674 100644 --- a/tests/Orders/ItemTest.php +++ b/tests/Orders/ItemTest.php @@ -1,4 +1,5 @@ getQuantity())->toBe(1); }); - -it("can create new item", function () { +it('can create new item', function () { // Arrange - $value = "100.00"; - $currency_code = "USD"; + $value = '100.00'; + $currency_code = 'USD'; // Act $item = Item::create('Item 1', $value, $currency_code, 2); @@ -36,7 +36,7 @@ expect($item->getQuantity())->toBe(2); }); -it("can cast to an array", function () { +it('can cast to an array', function () { // Arrange $expected = [ 'name' => 'Item 1', @@ -50,7 +50,7 @@ ]; // Act - $item = Item::create('Item 1', "100.00", "CAD"); + $item = Item::create('Item 1', '100.00', 'CAD'); $item->setDescription('Item Description') ->setQuantity(2); @@ -58,8 +58,7 @@ expect($item->toArray())->toBe($expected); }); - -it("can cast to json", function () { +it('can cast to json', function () { // Arrange $expected = json_encode([ 'name' => 'Item 1', @@ -73,7 +72,7 @@ ]); // Act - $item = Item::create('Item 1', "100.00", "CAD"); + $item = Item::create('Item 1', '100.00', 'CAD'); $item->setDescription('Item Description') ->setQuantity(2); @@ -81,7 +80,7 @@ expect($item->toJson())->toBe($expected); }); -it("throws an exception when setting invalid category", function () { +it('throws an exception when setting invalid category', function () { // Act $item = Item::create('Item', '100.00', 'CAD', 2); $item->setCategory('invalid category'); @@ -90,7 +89,7 @@ 'Item category is not supported. Please refer to https://developer.paypal.com/docs/api/orders/v2/#definition-item.' ); -it("returns item sku", function () { +it('returns item sku', function () { // Arrange $item = Item::create('Item', '100.00', 'CAD', 2); diff --git a/tests/Orders/OrderTest.php b/tests/Orders/OrderTest.php index 70b8c1e..6a81e55 100644 --- a/tests/Orders/OrderTest.php +++ b/tests/Orders/OrderTest.php @@ -1,4 +1,6 @@ -throws( InvalidOrderIntentException::class, @@ -19,8 +21,8 @@ 'Order intent provided is not supported. Please refer to https://developer.paypal.com/docs/api/orders/v2/#orders_create.' ); -it("can not set an invalid intent on an order", function () { - $order = new Order(); +it('can not set an invalid intent on an order', function () { + $order = new Order; $order->setIntent('invalid intent'); })->throws( InvalidOrderIntentException::class, @@ -28,9 +30,9 @@ 'Order intent provided is not supported. Please refer to https://developer.paypal.com/docs/api/orders/v2/#orders_create.' ); -it("can initialize an order", function () { +it('can initialize an order', function () { // Act - $order = new Order(); + $order = new Order; // Assert expect($order->getIntent())->toBe('CAPTURE'); @@ -49,11 +51,11 @@ expect($order->getPurchaseUnits())->toBeEmpty(); }); -it("can add a purchase unit to an order", function () { +it('can add a purchase unit to an order', function () { // Arrange $amount = AmountBreakdown::of('200.00', 'EUR'); $purchase_unit = new PurchaseUnit($amount); - $order = new Order(); + $order = new Order; // Act $order->addPurchaseUnit($purchase_unit); @@ -62,10 +64,10 @@ expect(count($order->getPurchaseUnits()))->toBe(1); }); -it("can not add multiple purchase units to an order", function () { +it('can not add multiple purchase units to an order', function () { $amount = AmountBreakdown::of('200.00', 'EUR'); $purchase_unit = new PurchaseUnit($amount); - $order = new Order(); + $order = new Order; // Act $order->addPurchaseUnit($purchase_unit); @@ -75,14 +77,14 @@ 'At present only 1 purchase_unit is supported.' ); -it("asserts an order has at least one purchase unit", function () { - (new Order())->toArray(); +it('asserts an order has at least one purchase unit', function () { + (new Order)->toArray(); })->throws( InvalidOrderException::class, 'Paypal orders must have 1 purchase_unit at least.' ); -it("casts to an array", function () { +it('casts to an array', function () { // Arrange $amount = AmountBreakdown::of('250.00'); $amount->setItemTotal(Money::of('300', 'USD')); @@ -158,7 +160,7 @@ expect($order->toArray())->toBe($expected); }); -it("casts to json", function () { +it('casts to json', function () { // Arrange $amount = AmountBreakdown::of('250.00'); $amount->setItemTotal(Money::of('300', 'USD')); diff --git a/tests/Orders/PayeeTest.php b/tests/Orders/PayeeTest.php index 8d34632..3e7bf09 100644 --- a/tests/Orders/PayeeTest.php +++ b/tests/Orders/PayeeTest.php @@ -1,10 +1,12 @@ - 'payee@paypal.com', @@ -18,7 +20,7 @@ expect($payee->toArray())->toBe($expected); }); -it("casts to an array", function () { +it('casts to an array', function () { // Arrange $expected = [ 'email_address' => 'payee@paypal.com', @@ -32,7 +34,7 @@ expect($payee->toArray())->toBe($expected); }); -it("casts to json", function () { +it('casts to json', function () { // Arrange $expected = json_encode([ 'email_address' => 'payee@paypal.com', diff --git a/tests/Orders/PurchaseUnitTest.php b/tests/Orders/PurchaseUnitTest.php index 46d957b..659adbb 100644 --- a/tests/Orders/PurchaseUnitTest.php +++ b/tests/Orders/PurchaseUnitTest.php @@ -1,4 +1,6 @@ -getAmount()->getValue())->toBe('100.00'); }); - -it("can create an empty purchase unit", function () { +it('can create an empty purchase unit', function () { // Arrange $amount = AmountBreakdown::of('100.00', 'CAD'); @@ -32,8 +33,7 @@ expect(count($purchase_unit->getItems()))->toBe(0); }); - -it("can add a single item", function () { +it('can add a single item', function () { // Arrange $amount = AmountBreakdown::of('100', 'CAD'); $purchase_unit = new PurchaseUnit($amount); @@ -45,8 +45,7 @@ expect(count($purchase_unit->getItems()))->toBe(1); }); - -it("can add multiple items", function () { +it('can add multiple items', function () { // Arrange $amount = AmountBreakdown::of('100', 'CAD'); $purchase_unit = new PurchaseUnit($amount); @@ -61,7 +60,7 @@ expect(count($purchase_unit->getItems()))->toBe(3); }); -it("it throws an exception when using multiple currencies", function () { +it('it throws an exception when using multiple currencies', function () { $amount = AmountBreakdown::of('100', 'CAD'); $purchase_unit = new PurchaseUnit($amount); @@ -71,8 +70,7 @@ $purchase_unit->addItem($item); })->throws(MultiCurrencyOrderException::class); - -it("casts to an array", function () { +it('casts to an array', function () { // Arrange $amount = AmountBreakdown::of('300.00', 'CAD'); $purchase_unit = new PurchaseUnit($amount); diff --git a/tests/Pest.php b/tests/Pest.php index eb78035..294bc73 100644 --- a/tests/Pest.php +++ b/tests/Pest.php @@ -52,5 +52,6 @@ function mockCreateOrderResponse(): Client new Response(200, ['Content-Type' => 'application/json'], $mockResponse), ]); $handlerStack = HandlerStack::create($mock); + return new Client(['handler' => $handlerStack]); } diff --git a/tests/Requests/OrderCaptureRequestTest.php b/tests/Requests/OrderCaptureRequestTest.php index 76b20f4..523671f 100644 --- a/tests/Requests/OrderCaptureRequestTest.php +++ b/tests/Requests/OrderCaptureRequestTest.php @@ -9,24 +9,24 @@ use GuzzleHttp\Utils; use PayPal\Checkout\Requests\OrderCaptureRequest; -it("has correct request uri", function () { +it('has correct request uri', function () { $request = new OrderCaptureRequest('1KC5501443316171H'); expect((string) $request->getUri())->toBe('/v2/checkout/orders/1KC5501443316171H/capture'); }); -it("has correct request method", function () { +it('has correct request method', function () { $request = new OrderCaptureRequest('1KC5501443316171H'); expect($request->getMethod())->toBe('POST'); }); -it("has correct request headers", function () { +it('has correct request headers', function () { $request = new OrderCaptureRequest('1KC5501443316171H'); expect($request->getHeaderLine('Content-Type'))->toBe('application/json'); expect($request->getHeaderLine('Prefer'))->toBe('return=representation'); }); -it("can execute request", function () { +it('can execute request', function () { $mockResponse = Utils::jsonEncode([ 'id' => '1KC5501443316171H', ]); diff --git a/tests/Requests/OrderCreateRequestTest.php b/tests/Requests/OrderCreateRequestTest.php index 7cb8b8f..4347e8e 100644 --- a/tests/Requests/OrderCreateRequestTest.php +++ b/tests/Requests/OrderCreateRequestTest.php @@ -3,30 +3,30 @@ namespace Tests\Requests; use GuzzleHttp\Utils; -use PayPal\Checkout\Requests\OrderCreateRequest; use PayPal\Checkout\Orders\AmountBreakdown; use PayPal\Checkout\Orders\ApplicationContext; use PayPal\Checkout\Orders\Item; use PayPal\Checkout\Orders\Order; use PayPal\Checkout\Orders\PurchaseUnit; +use PayPal\Checkout\Requests\OrderCreateRequest; -it("has correct request uri", function () { - $request = new OrderCreateRequest(); +it('has correct request uri', function () { + $request = new OrderCreateRequest; expect((string) $request->getUri())->toBe('/v2/checkout/orders'); }); -it("has correct request method", function () { - $request = new OrderCreateRequest(); +it('has correct request method', function () { + $request = new OrderCreateRequest; expect($request->getMethod())->toBe('POST'); }); -it("has correct request headers", function () { - $request = new OrderCreateRequest(); +it('has correct request headers', function () { + $request = new OrderCreateRequest; expect($request->getHeaderLine('Content-Type'))->toBe('application/json'); expect($request->getHeaderLine('Prefer'))->toBe('return=representation'); }); -it("has correct request body", function () { +it('has correct request body', function () { // Arrange /** @noinspection PhpUnhandledExceptionInspection */ $amount = AmountBreakdown::of('100.00'); @@ -51,7 +51,7 @@ expect(Utils::jsonDecode($request->getBody(), true))->toBe($order->toArray()); }); -it("can execute request", function () { +it('can execute request', function () { // Arrange /** @noinspection PhpUnhandledExceptionInspection */ $amount = AmountBreakdown::of('100.00'); @@ -80,6 +80,6 @@ expect($result)->toBe([ 'id' => '1KC5501443316171H', 'intent' => 'CAPTURE', - 'status' => 'CREATED' + 'status' => 'CREATED', ]); }); diff --git a/tests/Requests/OrderShowRequestTest.php b/tests/Requests/OrderShowRequestTest.php index e08f04d..cd1461d 100644 --- a/tests/Requests/OrderShowRequestTest.php +++ b/tests/Requests/OrderShowRequestTest.php @@ -5,23 +5,23 @@ use GuzzleHttp\Utils; use PayPal\Checkout\Requests\OrderShowRequest; -it("has correct request uri", function () { +it('has correct request uri', function () { $request = new OrderShowRequest('1KC5501443316171H'); expect((string) $request->getUri())->toBe('/v2/checkout/orders/1KC5501443316171H'); }); -it("has correct request method", function () { +it('has correct request method', function () { $request = new OrderShowRequest('1KC5501443316171H'); expect($request->getMethod())->toBe('GET'); }); -it("has correct request headers", function () { +it('has correct request headers', function () { $request = new OrderShowRequest('1KC5501443316171H'); expect($request->getHeaderLine('Content-Type'))->toBe('application/json'); expect($request->getHeaderLine('Prefer'))->toBe('return=representation'); }); -it("can execute request", function () { +it('can execute request', function () { // Arrange $client = mockCreateOrderResponse(); @@ -34,6 +34,6 @@ expect($result)->toBe([ 'id' => '1KC5501443316171H', 'intent' => 'CAPTURE', - 'status' => 'CREATED' + 'status' => 'CREATED', ]); }); From 0f49de0ebaa6f08e7e01e901f5899b873094a76f Mon Sep 17 00:00:00 2001 From: Mohammed Elhaouari Date: Wed, 30 Oct 2024 22:40:53 +0100 Subject: [PATCH 2/2] drop php7.4 support --- .github/workflows/php.yml | 2 +- composer.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml index 96cf32f..07280d1 100644 --- a/.github/workflows/php.yml +++ b/.github/workflows/php.yml @@ -9,7 +9,7 @@ jobs: fail-fast: true matrix: os: [ubuntu-latest, windows-latest] - php: [8.3, 8.2, 8.1, 7.4] + php: [8.3, 8.2, 8.1] stability: [prefer-stable] name: PHP${{ matrix.php }} - ${{ matrix.stability }} - ${{ matrix.os }} diff --git a/composer.json b/composer.json index f65f6a8..baf784c 100644 --- a/composer.json +++ b/composer.json @@ -17,7 +17,7 @@ } ], "require": { - "php": "^7.4|^8.0|^8.1|^8.2|^8.3", + "php": "^8.1|^8.2|^8.3", "ext-json": "*", "brick/money": "^0.5.2", "phpjuice/paypal-http-client": "^1.0"