From ef810637a6666f79be4ccaab426416d9256690cb Mon Sep 17 00:00:00 2001 From: Wiktor Ramut Date: Mon, 30 Sep 2024 22:11:24 +0200 Subject: [PATCH] Support symfony 7 --- .github/workflows/phpunit.yml | 3 +- .github/workflows/static-analysis.yml | 2 +- composer.json | 19 ++++---- phpunit.xml.dist | 17 ++----- src/PayPo/Enum/OrderStatusEnum.php | 48 ++++--------------- src/PayPo/Enum/SettlementStatusEnum.php | 25 ++-------- src/PayPo/Enum/ShipmentEnum.php | 39 +++------------ src/PayPo/Exception/BadResponseException.php | 16 ++----- .../Exception/PrepareRequestException.php | 14 ++---- .../Exception/SignatureNotValidException.php | 22 ++------- .../Request/Transaction/CancelRequest.php | 6 +-- .../Request/Transaction/ConfirmRequest.php | 6 +-- .../Request/Transaction/CreateRequest.php | 12 ++--- .../Request/Transaction/RefundRequest.php | 11 ++--- .../Transaction/StatusDetailsRequest.php | 5 +- src/PayPo/Response/Notify.php | 24 ++++------ src/PayPo/Response/Order/ConfirmResponse.php | 13 ++--- src/PayPo/Response/Order/CreateResponse.php | 13 ++--- src/PayPo/Response/Order/Response.php | 13 ++--- src/PayPo/Response/Order/StatusResponse.php | 26 ++++------ src/PayPo/Service/Authorization.php | 5 +- src/PayPo/Service/Order.php | 10 ++-- src/PayPo/Service/PayPoClient.php | 15 +++--- src/PayPo/Service/Validation.php | 11 ++--- src/PayPo/ValueObject/Address.php | 25 +++------- src/PayPo/ValueObject/Configuration.php | 14 ++---- src/PayPo/ValueObject/Customer.php | 17 +++---- src/PayPo/ValueObject/Order.php | 22 +++------ tests/DataFixtures/.gitkeep | 0 ...bstractOrderTest.php => AbstractOrder.php} | 21 ++++---- .../Request/Transaction/CancelTest.php | 15 +++--- .../Request/Transaction/ConfirmTest.php | 15 +++--- .../Request/Transaction/CreateTest.php | 21 ++++---- .../Request/Transaction/RefundTest.php | 15 +++--- .../Request/Transaction/StatusDetailsTest.php | 19 ++++---- 35 files changed, 181 insertions(+), 378 deletions(-) delete mode 100755 tests/DataFixtures/.gitkeep rename tests/Integration/Request/Transaction/{AbstractOrderTest.php => AbstractOrder.php} (83%) diff --git a/.github/workflows/phpunit.yml b/.github/workflows/phpunit.yml index c5e50ab..c9157a8 100644 --- a/.github/workflows/phpunit.yml +++ b/.github/workflows/phpunit.yml @@ -11,9 +11,10 @@ jobs: strategy: matrix: php-version: - - "8.1" + - "8.2" deps: - "normal" + - "low" steps: - name: "Checkout" diff --git a/.github/workflows/static-analysis.yml b/.github/workflows/static-analysis.yml index a578011..b6bcaf6 100644 --- a/.github/workflows/static-analysis.yml +++ b/.github/workflows/static-analysis.yml @@ -11,7 +11,7 @@ jobs: strategy: matrix: php-version: - - "8.1" + - "8.2" steps: - name: "Checkout" diff --git a/composer.json b/composer.json index c92e67c..318430d 100755 --- a/composer.json +++ b/composer.json @@ -4,21 +4,20 @@ "type": "library", "license": "MIT", "require": { - "php": "^8.1", + "php": "^8.2", "ext-json": "*", "guzzlehttp/guzzle": "^6.0|^7.0", - "marc-mabe/php-enum": "^4.3", - "symfony/property-access": "6.4.*", - "symfony/serializer": "6.4.*" + "symfony/property-access": "6.4.*|^7.0", + "symfony/serializer": "6.4.*|^7.0" }, "require-dev": { "roave/security-advisories": "dev-latest", - "phpunit/phpunit": "^9.5", - "symfony/phpunit-bridge": "6.4.*", - "phpro/grumphp": "^v2.5", - "friendsofphp/php-cs-fixer": "^3.58", - "phpstan/phpstan": "^1.11", - "phpstan/phpstan-webmozart-assert": "^1.0" + "phpunit/phpunit": "^10.5", + "symfony/phpunit-bridge": "6.4.*|^7.0", + "phpro/grumphp": "^v2.8", + "friendsofphp/php-cs-fixer": "^3.64", + "phpstan/phpstan": "^1.12", + "phpstan/phpstan-webmozart-assert": "^1.2" }, "autoload": { "psr-4": { diff --git a/phpunit.xml.dist b/phpunit.xml.dist index b8a7389..560a3ae 100755 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,29 +1,22 @@ - + + ./tests - - - - diff --git a/src/PayPo/Enum/OrderStatusEnum.php b/src/PayPo/Enum/OrderStatusEnum.php index 77d27d6..63e0cc6 100644 --- a/src/PayPo/Enum/OrderStatusEnum.php +++ b/src/PayPo/Enum/OrderStatusEnum.php @@ -4,49 +4,17 @@ namespace Answear\PayPo\Enum; -use MabeEnum\Enum; - -class OrderStatusEnum extends Enum +enum OrderStatusEnum: string { - public const NEW = 'NEW'; - public const PENDING = 'PENDING'; - public const ACCEPTED = 'ACCEPTED'; - public const COMPLETED = 'COMPLETED'; - public const REJECTED = 'REJECTED'; - public const CANCELED = 'CANCELED'; - - public static function new(): self - { - return static::get(static::NEW); - } - - public static function pending(): self - { - return static::get(static::PENDING); - } - - public static function accepted(): self - { - return static::get(static::ACCEPTED); - } - - public static function completed(): self - { - return static::get(static::COMPLETED); - } - - public static function rejected(): self - { - return static::get(static::REJECTED); - } - - public static function canceled(): self - { - return static::get(static::CANCELED); - } + case New = 'NEW'; + case Pending = 'PENDING'; + case Accepted = 'ACCEPTED'; + case Completed = 'COMPLETED'; + case Rejected = 'REJECTED'; + case Canceled = 'CANCELED'; public function isFinal(): bool { - return $this->is(self::completed()) || $this->is(self::rejected()) || $this->is(self::canceled()); + return self::Completed === $this || self::Rejected === $this || self::Canceled === $this; } } diff --git a/src/PayPo/Enum/SettlementStatusEnum.php b/src/PayPo/Enum/SettlementStatusEnum.php index 56cfe7a..9147ae5 100644 --- a/src/PayPo/Enum/SettlementStatusEnum.php +++ b/src/PayPo/Enum/SettlementStatusEnum.php @@ -4,26 +4,9 @@ namespace Answear\PayPo\Enum; -use MabeEnum\Enum; - -class SettlementStatusEnum extends Enum +enum SettlementStatusEnum: string { - public const NEW = 'NEW'; - public const CONFIRMED = 'CONFIRMED'; - public const PAID = 'PAID'; - - public static function new(): self - { - return static::get(static::NEW); - } - - public static function confirmed(): self - { - return static::get(static::CONFIRMED); - } - - public static function paid(): self - { - return static::get(static::PAID); - } + case New = 'NEW'; + case Confirmed = 'CONFIRMED'; + case Paid = 'PAID'; } diff --git a/src/PayPo/Enum/ShipmentEnum.php b/src/PayPo/Enum/ShipmentEnum.php index 2eeb5b9..3b8d0dd 100644 --- a/src/PayPo/Enum/ShipmentEnum.php +++ b/src/PayPo/Enum/ShipmentEnum.php @@ -4,38 +4,11 @@ namespace Answear\PayPo\Enum; -use MabeEnum\Enum; - -class ShipmentEnum extends Enum +enum ShipmentEnum: int { - public const COURIER = 0; - public const PICKUP_POINT = 1; - public const PARCEL_LOCKER = 2; - public const RUCH_PACK = 3; - public const CLICK_COLLECT = 4; - - public static function clickCollect(): self - { - return static::get(static::CLICK_COLLECT); - } - - public static function ruchPack(): self - { - return static::get(static::RUCH_PACK); - } - - public static function parcelLocker(): self - { - return static::get(static::PARCEL_LOCKER); - } - - public static function pickupPoint(): self - { - return static::get(static::PICKUP_POINT); - } - - public static function courier(): self - { - return static::get(static::COURIER); - } + case Courier = 0; + case PickupPoint = 1; + case ParcelLocker = 2; + case RuchPack = 3; + case ClickCollect = 4; } diff --git a/src/PayPo/Exception/BadResponseException.php b/src/PayPo/Exception/BadResponseException.php index 2a5c842..8b4d52d 100644 --- a/src/PayPo/Exception/BadResponseException.php +++ b/src/PayPo/Exception/BadResponseException.php @@ -8,16 +8,10 @@ class BadResponseException extends \RuntimeException { - private ResponseInterface $response; - - public function __construct(ResponseInterface $response, ?\Throwable $t) - { - parent::__construct('Response error.', 0, $t); - $this->response = $response; - } - - public function getResponse(): ResponseInterface - { - return $this->response; + public function __construct( + public readonly ResponseInterface $response, + ?\Throwable $throwable, + ) { + parent::__construct('Response error.', 0, $throwable); } } diff --git a/src/PayPo/Exception/PrepareRequestException.php b/src/PayPo/Exception/PrepareRequestException.php index a2655d2..c0ed538 100644 --- a/src/PayPo/Exception/PrepareRequestException.php +++ b/src/PayPo/Exception/PrepareRequestException.php @@ -8,16 +8,10 @@ class PrepareRequestException extends \RuntimeException { - private RequestInterface $request; - - public function __construct(RequestInterface $request, ?\Throwable $t) - { + public function __construct( + public readonly RequestInterface $request, + ?\Throwable $t, + ) { parent::__construct('Prepare request error.', 0, $t); - $this->request = $request; - } - - public function getRequest(): RequestInterface - { - return $this->request; } } diff --git a/src/PayPo/Exception/SignatureNotValidException.php b/src/PayPo/Exception/SignatureNotValidException.php index 174d0c6..32d18ad 100644 --- a/src/PayPo/Exception/SignatureNotValidException.php +++ b/src/PayPo/Exception/SignatureNotValidException.php @@ -6,24 +6,10 @@ class SignatureNotValidException extends \InvalidArgumentException { - private string $expectedSignature; - private ?string $providedSignature; - - public function __construct(string $expectedSignature, ?string $providedSignature) - { - $this->expectedSignature = $expectedSignature; - $this->providedSignature = $providedSignature; - + public function __construct( + public readonly string $expectedSignature, + public readonly ?string $providedSignature, + ) { parent::__construct('Signature is not valid'); } - - public function getExpectedSignature(): string - { - return $this->expectedSignature; - } - - public function getProvidedSignature(): ?string - { - return $this->providedSignature; - } } diff --git a/src/PayPo/Request/Transaction/CancelRequest.php b/src/PayPo/Request/Transaction/CancelRequest.php index 639ad15..8d48978 100644 --- a/src/PayPo/Request/Transaction/CancelRequest.php +++ b/src/PayPo/Request/Transaction/CancelRequest.php @@ -12,12 +12,10 @@ class CancelRequest implements RequestInterface private const ENDPOINT = '/transactions'; public string $status; - private string $transactionUuid; - public function __construct(string $transactionUuid) + public function __construct(private readonly string $transactionUuid) { - $this->status = OrderStatusEnum::CANCELED; - $this->transactionUuid = $transactionUuid; + $this->status = OrderStatusEnum::Canceled->value; } public function getHttpMethod(): string diff --git a/src/PayPo/Request/Transaction/ConfirmRequest.php b/src/PayPo/Request/Transaction/ConfirmRequest.php index f20d17c..c39b2ff 100644 --- a/src/PayPo/Request/Transaction/ConfirmRequest.php +++ b/src/PayPo/Request/Transaction/ConfirmRequest.php @@ -12,12 +12,10 @@ class ConfirmRequest implements RequestInterface private const ENDPOINT = '/transactions'; public string $status; - private string $transactionUuid; - public function __construct(string $transactionUuid) + public function __construct(private readonly string $transactionUuid) { - $this->status = OrderStatusEnum::COMPLETED; - $this->transactionUuid = $transactionUuid; + $this->status = OrderStatusEnum::Completed->value; } public function getHttpMethod(): string diff --git a/src/PayPo/Request/Transaction/CreateRequest.php b/src/PayPo/Request/Transaction/CreateRequest.php index 60c5dfc..72ce833 100644 --- a/src/PayPo/Request/Transaction/CreateRequest.php +++ b/src/PayPo/Request/Transaction/CreateRequest.php @@ -16,19 +16,13 @@ class CreateRequest implements RequestInterface public string $merchantId; public ?string $shopId = null; - public Order $order; - public Customer $customer; - public Configuration $configuration; public function __construct( - Order $order, - Customer $customer, - Configuration $configuration + public readonly Order $order, + public readonly Customer $customer, + public readonly Configuration $configuration, ) { $this->merchantId = PayPoConfiguration::getClientId(); - $this->order = $order; - $this->customer = $customer; - $this->configuration = $configuration; } public function getHttpMethod(): string diff --git a/src/PayPo/Request/Transaction/RefundRequest.php b/src/PayPo/Request/Transaction/RefundRequest.php index 3d9acf2..7f03b99 100644 --- a/src/PayPo/Request/Transaction/RefundRequest.php +++ b/src/PayPo/Request/Transaction/RefundRequest.php @@ -9,13 +9,10 @@ class RefundRequest implements RequestInterface private const HTTP_METHOD = 'POST'; private const ENDPOINT = '/transactions'; - private string $transactionUuid; - public int $amount; - - public function __construct(string $transactionUuid, int $amount) - { - $this->transactionUuid = $transactionUuid; - $this->amount = $amount; + public function __construct( + private readonly string $transactionUuid, + public readonly int $amount, + ) { } public function getHttpMethod(): string diff --git a/src/PayPo/Request/Transaction/StatusDetailsRequest.php b/src/PayPo/Request/Transaction/StatusDetailsRequest.php index 7e386b7..228957c 100644 --- a/src/PayPo/Request/Transaction/StatusDetailsRequest.php +++ b/src/PayPo/Request/Transaction/StatusDetailsRequest.php @@ -9,11 +9,8 @@ class StatusDetailsRequest implements RequestInterface private const HTTP_METHOD = 'GET'; private const ENDPOINT = '/transactions'; - private string $transactionId; - - public function __construct(string $transactionId) + public function __construct(private readonly string $transactionId) { - $this->transactionId = $transactionId; } public function getHttpMethod(): string diff --git a/src/PayPo/Response/Notify.php b/src/PayPo/Response/Notify.php index 9d854d8..066b36c 100644 --- a/src/PayPo/Response/Notify.php +++ b/src/PayPo/Response/Notify.php @@ -8,27 +8,19 @@ class Notify { - public string $merchantId; public ?string $shopId; - public string $referenceId; - public string $transactionId; - public OrderStatusEnum $transactionStatus; - public int $amount; - public \DateTimeImmutable $lastUpdate; + public readonly OrderStatusEnum $transactionStatus; + public readonly \DateTimeImmutable $lastUpdate; private function __construct( - string $merchantId, - string $referenceId, - string $transactionId, + public readonly string $merchantId, + public readonly string $referenceId, + public readonly string $transactionId, string $transactionStatus, - int $amount, - string $lastUpdate + public readonly int $amount, + string $lastUpdate, ) { - $this->merchantId = $merchantId; - $this->referenceId = $referenceId; - $this->transactionId = $transactionId; - $this->transactionStatus = OrderStatusEnum::get($transactionStatus); - $this->amount = $amount; + $this->transactionStatus = OrderStatusEnum::from($transactionStatus); $this->lastUpdate = new \DateTimeImmutable($lastUpdate); } diff --git a/src/PayPo/Response/Order/ConfirmResponse.php b/src/PayPo/Response/Order/ConfirmResponse.php index b0ace9c..44e7d2d 100644 --- a/src/PayPo/Response/Order/ConfirmResponse.php +++ b/src/PayPo/Response/Order/ConfirmResponse.php @@ -4,14 +4,11 @@ namespace Answear\PayPo\Response\Order; -class ConfirmResponse +readonly class ConfirmResponse { - public string $code; - public string $statusDescription; - - public function __construct(string $code, string $statusDescription) - { - $this->code = $code; - $this->statusDescription = $statusDescription; + public function __construct( + public string $code, + public string $statusDescription, + ) { } } diff --git a/src/PayPo/Response/Order/CreateResponse.php b/src/PayPo/Response/Order/CreateResponse.php index 3812314..11eea87 100644 --- a/src/PayPo/Response/Order/CreateResponse.php +++ b/src/PayPo/Response/Order/CreateResponse.php @@ -4,14 +4,11 @@ namespace Answear\PayPo\Response\Order; -class CreateResponse +readonly class CreateResponse { - public string $transactionId; - public string $redirectUrl; - - public function __construct(string $transactionId, string $redirectUrl) - { - $this->transactionId = $transactionId; - $this->redirectUrl = $redirectUrl; + public function __construct( + public string $transactionId, + public string $redirectUrl, + ) { } } diff --git a/src/PayPo/Response/Order/Response.php b/src/PayPo/Response/Order/Response.php index 9bd8fc6..5aa8789 100644 --- a/src/PayPo/Response/Order/Response.php +++ b/src/PayPo/Response/Order/Response.php @@ -4,14 +4,11 @@ namespace Answear\PayPo\Response\Order; -class Response +readonly class Response { - public string $code; - public string $message; - - public function __construct(string $code, string $message) - { - $this->code = $code; - $this->message = $message; + public function __construct( + public string $code, + public string $message, + ) { } } diff --git a/src/PayPo/Response/Order/StatusResponse.php b/src/PayPo/Response/Order/StatusResponse.php index 6ae6c49..8c7d1b8 100644 --- a/src/PayPo/Response/Order/StatusResponse.php +++ b/src/PayPo/Response/Order/StatusResponse.php @@ -7,34 +7,24 @@ use Answear\PayPo\Enum\OrderStatusEnum; use Answear\PayPo\Enum\SettlementStatusEnum; -class StatusResponse +readonly class StatusResponse { - public string $merchantId; - public string $referenceId; - public string $transactionId; public OrderStatusEnum $transactionStatus; - public ?string $transactionUrl = null; - public int $amount; public SettlementStatusEnum $settlementStatus; public \DateTimeImmutable $lastUpdate; public function __construct( - string $merchantId, - string $referenceId, - string $transactionId, + public string $merchantId, + public string $referenceId, + public string $transactionId, string $transactionStatus, - int $amount, + public int $amount, string $settlementStatus, string $lastUpdate, - ?string $transactionUrl = null + public ?string $transactionUrl = null, ) { - $this->merchantId = $merchantId; - $this->referenceId = $referenceId; - $this->transactionId = $transactionId; - $this->transactionStatus = OrderStatusEnum::get($transactionStatus); - $this->amount = $amount; - $this->settlementStatus = SettlementStatusEnum::get($settlementStatus); + $this->transactionStatus = OrderStatusEnum::from($transactionStatus); + $this->settlementStatus = SettlementStatusEnum::from($settlementStatus); $this->lastUpdate = new \DateTimeImmutable($lastUpdate); - $this->transactionUrl = $transactionUrl; } } diff --git a/src/PayPo/Service/Authorization.php b/src/PayPo/Service/Authorization.php index c001d61..692b171 100644 --- a/src/PayPo/Service/Authorization.php +++ b/src/PayPo/Service/Authorization.php @@ -6,16 +6,15 @@ use Answear\PayPo\Configuration\PayPoConfiguration; use Answear\PayPo\ValueObject\AccessToken; +use GuzzleHttp\ClientInterface; use GuzzleHttp\RequestOptions; class Authorization { private const AUTH_URI = '/oauth/tokens'; - private \GuzzleHttp\ClientInterface $client; - public function __construct(\GuzzleHttp\ClientInterface $client) + public function __construct(private ClientInterface $client) { - $this->client = $client; } public function authorize(): void diff --git a/src/PayPo/Service/Order.php b/src/PayPo/Service/Order.php index a068540..568e265 100644 --- a/src/PayPo/Service/Order.php +++ b/src/PayPo/Service/Order.php @@ -22,12 +22,10 @@ class Order { - private ?PayPoSerializer $serializer; - private PayPoClient $client; - - public function __construct(?PayPoClient $client = null, ?PayPoSerializer $serializer = null) - { - $this->serializer = $serializer; + public function __construct( + private ?PayPoClient $client = null, + private ?PayPoSerializer $serializer = null, + ) { $this->client = $client ?? new PayPoClient(); } diff --git a/src/PayPo/Service/PayPoClient.php b/src/PayPo/Service/PayPoClient.php index 101fc20..c3a90dd 100644 --- a/src/PayPo/Service/PayPoClient.php +++ b/src/PayPo/Service/PayPoClient.php @@ -8,6 +8,8 @@ use Answear\PayPo\Request\Transaction\RequestInterface; use Answear\PayPo\Util\AuthenticationUtil; use Answear\PayPo\ValueObject\AccessToken; +use GuzzleHttp\Client; +use GuzzleHttp\ClientInterface; use GuzzleHttp\Exception\GuzzleException; use GuzzleHttp\Psr7\Request; use GuzzleHttp\Psr7\Uri; @@ -17,16 +19,11 @@ class PayPoClient { private const CONNECTION_TIMEOUT = 10; private const TIMEOUT = 30; - - private ?\GuzzleHttp\ClientInterface $client; - private ?Authorization $authorizationService; public function __construct( - ?\GuzzleHttp\ClientInterface $client = null, - ?Authorization $authorizationService = null + private ?ClientInterface $client = null, + private ?Authorization $authorizationService = null, ) { - $this->client = $client; - $this->authorizationService = $authorizationService; } /** @@ -66,10 +63,10 @@ private function sendData(RequestInterface $request, ?string $body): ResponseInt ); } - private function getClient(): \GuzzleHttp\ClientInterface + private function getClient(): ClientInterface { if (null === $this->client) { - $this->client = new \GuzzleHttp\Client(['timeout' => self::TIMEOUT, 'connect_timeout' => self::CONNECTION_TIMEOUT]); + $this->client = new Client(['timeout' => self::TIMEOUT, 'connect_timeout' => self::CONNECTION_TIMEOUT]); } return $this->client; diff --git a/src/PayPo/Service/Validation.php b/src/PayPo/Service/Validation.php index 1ea7ece..d0a257b 100644 --- a/src/PayPo/Service/Validation.php +++ b/src/PayPo/Service/Validation.php @@ -5,14 +5,13 @@ namespace Answear\PayPo\Service; use Answear\PayPo\Configuration\PayPoConfiguration; +use GuzzleHttp\Client; +use GuzzleHttp\ClientInterface; class Validation { - private ?\GuzzleHttp\ClientInterface $client; - - public function __construct(?\GuzzleHttp\ClientInterface $client = null) + public function __construct(private ?ClientInterface $client = null) { - $this->client = $client; } public function isOnline(): bool @@ -26,10 +25,10 @@ public function isOnline(): bool return true; } - private function getClient(): \GuzzleHttp\ClientInterface + private function getClient(): ClientInterface { if (null === $this->client) { - $this->client = new \GuzzleHttp\Client(); + $this->client = new Client(); } return $this->client; diff --git a/src/PayPo/ValueObject/Address.php b/src/PayPo/ValueObject/Address.php index dee9f39..6ded717 100644 --- a/src/PayPo/ValueObject/Address.php +++ b/src/PayPo/ValueObject/Address.php @@ -6,26 +6,13 @@ class Address { - public string $street; - public ?string $building; - public ?string $flat; - public string $zip; - public string $city; - public ?string $country; - public function __construct( - string $street, - ?string $building, - ?string $flat, - string $zip, - string $city, - ?string $country = null + public string $street, + public ?string $building, + public ?string $flat, + public string $zip, + public string $city, + public ?string $country = null, ) { - $this->street = $street; - $this->building = $building; - $this->flat = $flat; - $this->zip = $zip; - $this->city = $city; - $this->country = $country; } } diff --git a/src/PayPo/ValueObject/Configuration.php b/src/PayPo/ValueObject/Configuration.php index 29c3b85..d82c133 100644 --- a/src/PayPo/ValueObject/Configuration.php +++ b/src/PayPo/ValueObject/Configuration.php @@ -6,14 +6,10 @@ class Configuration { - public string $returnUrl; - public string $notifyUrl; - public ?string $cancelUrl; - - public function __construct(string $returnUrl, string $notifyUrl, ?string $cancelUrl) - { - $this->returnUrl = $returnUrl; - $this->notifyUrl = $notifyUrl; - $this->cancelUrl = $cancelUrl; + public function __construct( + public string $returnUrl, + public string $notifyUrl, + public ?string $cancelUrl, + ) { } } diff --git a/src/PayPo/ValueObject/Customer.php b/src/PayPo/ValueObject/Customer.php index c097a93..903c308 100644 --- a/src/PayPo/ValueObject/Customer.php +++ b/src/PayPo/ValueObject/Customer.php @@ -6,16 +6,11 @@ class Customer { - public string $name; - public string $surname; - public string $email; - public string $phone; - - public function __construct(string $name, string $surname, string $email, string $phone) - { - $this->name = $name; - $this->surname = $surname; - $this->email = $email; - $this->phone = $phone; + public function __construct( + public string $name, + public string $surname, + public string $email, + public string $phone, + ) { } } diff --git a/src/PayPo/ValueObject/Order.php b/src/PayPo/ValueObject/Order.php index 504a5e4..bf83dd3 100644 --- a/src/PayPo/ValueObject/Order.php +++ b/src/PayPo/ValueObject/Order.php @@ -8,31 +8,21 @@ class Order { - public string $referenceId; public ?string $providerId = null; - public int $amount; - public ?string $description = null; public ?array $additionalInfo = null; public ?int $shipment = null; - public Address $billingAddress; - public Address $shippingAddress; public function __construct( - string $referenceId, - int $amount, - ?string $description, - Address $billingAddress, - Address $shippingAddress + public string $referenceId, + public int $amount, + public Address $billingAddress, + public Address $shippingAddress, + public ?string $description = null, ) { - $this->referenceId = $referenceId; - $this->amount = $amount; - $this->description = $description; - $this->billingAddress = $billingAddress; - $this->shippingAddress = $shippingAddress; } public function setShipment(ShipmentEnum $shipment): void { - $this->shipment = $shipment->getValue(); + $this->shipment = $shipment->value; } } diff --git a/tests/DataFixtures/.gitkeep b/tests/DataFixtures/.gitkeep deleted file mode 100755 index e69de29..0000000 diff --git a/tests/Integration/Request/Transaction/AbstractOrderTest.php b/tests/Integration/Request/Transaction/AbstractOrder.php similarity index 83% rename from tests/Integration/Request/Transaction/AbstractOrderTest.php rename to tests/Integration/Request/Transaction/AbstractOrder.php index 760ce25..efc0e29 100644 --- a/tests/Integration/Request/Transaction/AbstractOrderTest.php +++ b/tests/Integration/Request/Transaction/AbstractOrder.php @@ -9,9 +9,11 @@ use Answear\PayPo\Service\PayPoClient; use Answear\PayPo\ValueObject\AccessToken; use GuzzleHttp\Psr7\Response; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\TestCase; -abstract class AbstractOrderTest extends TestCase +abstract class AbstractOrder extends TestCase { protected function tearDown(): void { @@ -19,16 +21,13 @@ protected function tearDown(): void AccessToken::reset(); } - /** - * @test - * - * @dataProvider provideDataForRequest - */ + #[Test] + #[DataProvider('provideDataForRequest')] public function successfullySend($request, string $expectedRequest, array $apiResponse): void { - $this->setUpConfiguration(); + self::setUpConfiguration(); - $clientResponse = new Response(200, [], json_encode($apiResponse, JSON_THROW_ON_ERROR, 512)); + $clientResponse = new Response(200, [], json_encode($apiResponse, JSON_THROW_ON_ERROR)); $client = $this->createMock(\GuzzleHttp\Client::class); $client->expects(self::once()) @@ -71,15 +70,15 @@ protected function getOrderService(?PayPoClient $client): Order return new Order($client); } - abstract public function provideDataForRequest(): iterable; + abstract public static function provideDataForRequest(): iterable; abstract protected function sendAndAssert( PayPoClient $client, $request, - array $apiResponse + array $apiResponse, ): void; - protected function setUpConfiguration(): void + protected static function setUpConfiguration(): void { PayPoConfiguration::setForSandbox('e626aba7-598c-4746-9da7-03a9290bddfc', 'apiKey'); } diff --git a/tests/Integration/Request/Transaction/CancelTest.php b/tests/Integration/Request/Transaction/CancelTest.php index 90d9d58..c4a9c4d 100644 --- a/tests/Integration/Request/Transaction/CancelTest.php +++ b/tests/Integration/Request/Transaction/CancelTest.php @@ -8,16 +8,15 @@ use Answear\PayPo\Exception\ConfigurationException; use Answear\PayPo\Service\PayPoClient; use GuzzleHttp\Client; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\Test; -class CancelTest extends AbstractOrderTest +class CancelTest extends AbstractOrder { private const TRANSACTION_UUID = 'transaction-uuid'; - /** - * @test - * - * @dataProvider provideDataForRequest - */ + #[Test] + #[DataProvider('provideDataForRequest')] public function configurationNotSetException(string $transactionUuid): void { PayPoConfiguration::reset(); @@ -28,9 +27,9 @@ public function configurationNotSetException(string $transactionUuid): void $this->getOrderService(new PayPoClient($client))->cancel($transactionUuid); } - public function provideDataForRequest(): iterable + public static function provideDataForRequest(): iterable { - $this->setUpConfiguration(); + self::setUpConfiguration(); yield [ self::TRANSACTION_UUID, diff --git a/tests/Integration/Request/Transaction/ConfirmTest.php b/tests/Integration/Request/Transaction/ConfirmTest.php index efffe16..2b49cff 100644 --- a/tests/Integration/Request/Transaction/ConfirmTest.php +++ b/tests/Integration/Request/Transaction/ConfirmTest.php @@ -7,16 +7,15 @@ use Answear\PayPo\Configuration\PayPoConfiguration; use Answear\PayPo\Exception\ConfigurationException; use Answear\PayPo\Service\PayPoClient; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\Test; -class ConfirmTest extends AbstractOrderTest +class ConfirmTest extends AbstractOrder { private const TRANSACTION_UUID = 'transaction-uuid'; - /** - * @test - * - * @dataProvider provideDataForRequest - */ + #[Test] + #[DataProvider('provideDataForRequest')] public function configurationNotSetException(string $transactionUuid): void { PayPoConfiguration::reset(); @@ -27,9 +26,9 @@ public function configurationNotSetException(string $transactionUuid): void $this->getOrderService(new PayPoClient($client))->confirm($transactionUuid); } - public function provideDataForRequest(): iterable + public static function provideDataForRequest(): iterable { - $this->setUpConfiguration(); + self::setUpConfiguration(); yield [ self::TRANSACTION_UUID, diff --git a/tests/Integration/Request/Transaction/CreateTest.php b/tests/Integration/Request/Transaction/CreateTest.php index e05cb3b..1953154 100644 --- a/tests/Integration/Request/Transaction/CreateTest.php +++ b/tests/Integration/Request/Transaction/CreateTest.php @@ -12,14 +12,13 @@ use Answear\PayPo\ValueObject\Configuration; use Answear\PayPo\ValueObject\Customer; use Answear\PayPo\ValueObject\Order; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\Test; -class CreateTest extends AbstractOrderTest +class CreateTest extends AbstractOrder { - /** - * @test - * - * @dataProvider provideDataForRequest - */ + #[Test] + #[DataProvider('provideDataForRequest')] public function configurationNotSetException(CreateRequest $request): void { PayPoConfiguration::reset(); @@ -30,16 +29,15 @@ public function configurationNotSetException(CreateRequest $request): void $this->getOrderService(new PayPoClient($client))->create($request); } - public function provideDataForRequest(): iterable + public static function provideDataForRequest(): iterable { - $this->setUpConfiguration(); + self::setUpConfiguration(); yield [ new CreateRequest( new Order( 'ref-id-02', 2531, - 'Description of data', new Address( 'billing street', 'houseNumber', @@ -55,7 +53,8 @@ public function provideDataForRequest(): iterable 'postal', 'city', 'country' - ) + ), + 'Description of data', ), new Customer( 'name', @@ -69,7 +68,7 @@ public function provideDataForRequest(): iterable null ) ), - '{"merchantId":"e626aba7-598c-4746-9da7-03a9290bddfc","order":{"referenceId":"ref-id-02","amount":2531,"description":"Description of data","billingAddress":{"street":"billing street","building":"houseNumber","flat":"apartmentNumber","zip":"postal","city":"city","country":"country"},"shippingAddress":{"street":"shipping street","building":"houseNumber","flat":"apartmentNumber","zip":"postal","city":"city","country":"country"}},"customer":{"name":"name","surname":"surname","email":"email","phone":"phone"},"configuration":{"returnUrl":"returnUrl","notifyUrl":"notifyUrl"}}', + '{"merchantId":"e626aba7-598c-4746-9da7-03a9290bddfc","order":{"referenceId":"ref-id-02","amount":2531,"billingAddress":{"street":"billing street","building":"houseNumber","flat":"apartmentNumber","zip":"postal","city":"city","country":"country"},"shippingAddress":{"street":"shipping street","building":"houseNumber","flat":"apartmentNumber","zip":"postal","city":"city","country":"country"},"description":"Description of data"},"customer":{"name":"name","surname":"surname","email":"email","phone":"phone"},"configuration":{"returnUrl":"returnUrl","notifyUrl":"notifyUrl"}}', [ 'transactionId' => '201', 'redirectUrl' => 'https://redirect.url', diff --git a/tests/Integration/Request/Transaction/RefundTest.php b/tests/Integration/Request/Transaction/RefundTest.php index 1c75ae2..e3eb828 100644 --- a/tests/Integration/Request/Transaction/RefundTest.php +++ b/tests/Integration/Request/Transaction/RefundTest.php @@ -7,17 +7,16 @@ use Answear\PayPo\Configuration\PayPoConfiguration; use Answear\PayPo\Exception\ConfigurationException; use Answear\PayPo\Service\PayPoClient; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\Test; -class RefundTest extends AbstractOrderTest +class RefundTest extends AbstractOrder { private const TRANSACTION_ID = 'tranaction-id'; private const AMOUNT = 328264; - /** - * @test - * - * @dataProvider provideDataForRequest - */ + #[Test] + #[DataProvider('provideDataForRequest')] public function configurationNotSetException($request): void { PayPoConfiguration::reset(); @@ -28,9 +27,9 @@ public function configurationNotSetException($request): void $this->getOrderService(new PayPoClient($client))->refund(...$request); } - public function provideDataForRequest(): iterable + public static function provideDataForRequest(): iterable { - $this->setUpConfiguration(); + self::setUpConfiguration(); yield [ [ diff --git a/tests/Integration/Request/Transaction/StatusDetailsTest.php b/tests/Integration/Request/Transaction/StatusDetailsTest.php index 439ba43..d3fb1be 100644 --- a/tests/Integration/Request/Transaction/StatusDetailsTest.php +++ b/tests/Integration/Request/Transaction/StatusDetailsTest.php @@ -9,16 +9,15 @@ use Answear\PayPo\Enum\SettlementStatusEnum; use Answear\PayPo\Exception\ConfigurationException; use Answear\PayPo\Service\PayPoClient; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\Test; -class StatusDetailsTest extends AbstractOrderTest +class StatusDetailsTest extends AbstractOrder { private const TRANSACTION_UUID = 'transaction-uuid'; - /** - * @test - * - * @dataProvider provideDataForRequest - */ + #[Test] + #[DataProvider('provideDataForRequest')] public function configurationNotSetException(string $transactionUuid): void { PayPoConfiguration::reset(); @@ -29,9 +28,9 @@ public function configurationNotSetException(string $transactionUuid): void $this->getOrderService(new PayPoClient($client))->getStatusDetails($transactionUuid); } - public function provideDataForRequest(): iterable + public static function provideDataForRequest(): iterable { - $this->setUpConfiguration(); + self::setUpConfiguration(); yield [ self::TRANSACTION_UUID, @@ -58,9 +57,9 @@ protected function sendAndAssert(PayPoClient $client, $request, array $apiRespon self::assertSame($apiResponse['merchantId'], $response->merchantId); self::assertSame($apiResponse['referenceId'], $response->referenceId); self::assertSame($apiResponse['transactionId'], $response->transactionId); - self::assertTrue($response->transactionStatus->is(OrderStatusEnum::completed())); + self::assertSame($response->transactionStatus, OrderStatusEnum::Completed); self::assertSame($apiResponse['amount'], $response->amount); - self::assertTrue($response->settlementStatus->is(SettlementStatusEnum::paid())); + self::assertSame($response->settlementStatus, SettlementStatusEnum::Paid); self::assertSame( $apiResponse['lastUpdate'] . '+00:00', $response->lastUpdate->format(\DateTimeInterface::RFC3339)