From f24fc106e81f3f63a7857c45481681b7769033ed Mon Sep 17 00:00:00 2001 From: Laurynas Date: Fri, 5 Apr 2024 12:21:18 +0300 Subject: [PATCH] Removed unused tests --- .../PaymentServiceCreateOrderTest.php | 225 ---------------- .../PaymentServiceGetOrderTest.php | 91 ------- .../PaymentServiceUpdateOrderTest.php | 201 -------------- .../Unit/Serializer/ObjectSerializerTest.php | 250 ------------------ 4 files changed, 767 deletions(-) delete mode 100644 tests/Unit/PaymentService/PaymentServiceCreateOrderTest.php delete mode 100644 tests/Unit/PaymentService/PaymentServiceGetOrderTest.php delete mode 100644 tests/Unit/PaymentService/PaymentServiceUpdateOrderTest.php delete mode 100644 tests/Unit/Serializer/ObjectSerializerTest.php diff --git a/tests/Unit/PaymentService/PaymentServiceCreateOrderTest.php b/tests/Unit/PaymentService/PaymentServiceCreateOrderTest.php deleted file mode 100644 index 7e82d11a8..000000000 --- a/tests/Unit/PaymentService/PaymentServiceCreateOrderTest.php +++ /dev/null @@ -1,225 +0,0 @@ -handleTestErrorsCreateOrder(400, $errorName, $errorCode); - } - - /** - * @dataProvider notAuthorizedErrorsProvider - * - * @throws InvalidRequestException|NotAuthorizedException|UnprocessableEntityException - */ - public function testNotAuthorizedErrorsCreateOrder($errorName, $errorCode) - { -// $this->handleTestErrorsCreateOrder(401, $errorName, $errorCode); - } - - /** - * @dataProvider unprocessableEntityErrorsProvider - * - * @throws InvalidRequestException|NotAuthorizedException|UnprocessableEntityException - */ - public function testUnprocessableEntityErrorsCreateOrder($errorName, $errorCode) - { -// $this->handleTestErrorsCreateOrder(422, $errorName, $errorCode); - } - - /** - * @param int $statusCode - * @param string $errorName - * @param int $errorCode - * - * @throws InvalidRequestException|NotAuthorizedException|UnprocessableEntityException - */ - private function handleTestErrorsCreateOrder($statusCode, $errorName, $errorCode) - { - switch ($statusCode) { - case 400: - $error = $this->getInvalidRequestError($errorName); - break; - case 401: - $error = $this->getNotAuthorizedError($errorName); - break; - case 422: - default: - $error = $this->getUnprocessableEntityError($errorName); - break; - } - - $requestMock = $this->createMock(RequestInterface::class); - $createRequestMock = $this->createMock(CreatePayPalOrderRequestInterface::class); - - $streamMock = $this->createMock(StreamInterface::class); - $streamMock->method('getContents')->willReturn(json_encode($error)); - - $responseMock = $this->createMock(ResponseInterface::class); - $responseMock->method('getStatusCode')->willReturn($statusCode); - $responseMock->method('getBody')->willReturn($streamMock); - - $clientMock = $this->createMock(CheckoutHttpClient::class); - $clientMock->method('createOrder')->willThrowException(new HttpException('An error occurred', $requestMock, $responseMock)); - - $this->expectExceptionCode($errorCode); - $paymentService = new PaymentService($clientMock, new ObjectSerializer()); - $paymentService->createOrder($createRequestMock); - } - - private function getInvalidRequestError($issueError) - { - return [ - 'name' => 'INVALID_REQUEST', - 'message' => 'Request is not well-formed, syntactically incorrect, or violates schema.', - 'debug_id' => 'b6b9a374802ea', - 'details' => [ - [ - 'field' => '', - 'value' => '', - 'location' => 'body', - 'issue' => $issueError, - 'description' => '', - ], - ], - 'links' => [ - [ - 'href' => 'https://developer.paypal.com/docs/api/orders/v2/#error-INVALID_PARAMETER_VALUE', - 'rel' => 'information_link', - 'encType' => 'application/json', - ], - ], - ]; - } - - private function getNotAuthorizedError($issueError) - { - return [ - 'name' => $issueError, - 'message' => 'Authentication failed due to invalid authentication credentials or a missing Authorization header.', - 'links' => [ - [ - 'href' => 'https://developer.paypal.com/docs/api/overview/#error', - 'rel' => 'information_link', - ], - ], - ]; - } - - private function getUnprocessableEntityError($issueError) - { - return [ - 'name' => 'UNPROCESSABLE_ENTITY', - 'details' => [ - [ - 'field' => '', - 'value' => '', - 'issue' => $issueError, - 'description' => '', - ], - ], - 'message' => 'The requested action could not be performed, semantically incorrect, or failed business validation.', - 'debug_id' => 'c9a75b43fc807', - 'links' => [ - [ - 'href' => 'https://developer.paypal.com/docs/api/orders/v2/#error-MAX_VALUE_EXCEEDED', - 'rel' => 'information_link', - 'method' => 'GET', - ], - ], - ]; - } - - public function invalidRequestErrorsProvider() - { - return [ - ['INVALID_ARRAY_MAX_ITEMS', InvalidRequestException::INVALID_ARRAY_MAX_ITEMS], - ['INVALID_ARRAY_MIN_ITEMS', InvalidRequestException::INVALID_ARRAY_MIN_ITEMS], - ['INVALID_COUNTRY_CODE', InvalidRequestException::INVALID_COUNTRY_CODE], - ['INVALID_PARAMETER_SYNTAX', InvalidRequestException::INVALID_PARAMETER_SYNTAX], - ['INVALID_STRING_LENGTH', InvalidRequestException::INVALID_STRING_LENGTH], - ['INVALID_PARAMETER_VALUE', InvalidRequestException::INVALID_PARAMETER_VALUE], - ['MISSING_REQUIRED_PARAMETER', InvalidRequestException::MISSING_REQUIRED_PARAMETER], - ['NOT_SUPPORTED', InvalidRequestException::NOT_SUPPORTED], - ['PAYPAL_REQUEST_ID_REQUIRED', InvalidRequestException::PAYPAL_REQUEST_ID_REQUIRED], - ['MALFORMED_REQUEST_JSON', InvalidRequestException::MALFORMED_REQUEST_JSON], - ]; - } - - public function notAuthorizedErrorsProvider() - { - return [ - ['PERMISSION_DENIED', NotAuthorizedException::PERMISSION_DENIED], - ['PERMISSION_DENIED_FOR_DONATION_ITEMS', NotAuthorizedException::PERMISSION_DENIED_FOR_DONATION_ITEMS], - ['MALFORMED_REQUEST', NotAuthorizedException::MALFORMED_REQUEST], - ]; - } - - public function unprocessableEntityErrorsProvider() - { - return [ - ['AMOUNT_MISMATCH', UnprocessableEntityException::AMOUNT_MISMATCH], - ['BILLING_ADDRESS_INVALID', UnprocessableEntityException::BILLING_ADDRESS_INVALID], - ['CANNOT_BE_NEGATIVE', UnprocessableEntityException::CANNOT_BE_NEGATIVE], - ['CANNOT_BE_ZERO_OR_NEGATIVE', UnprocessableEntityException::CANNOT_BE_ZERO_OR_NEGATIVE], - ['CARD_EXPIRED', UnprocessableEntityException::CARD_EXPIRED], - ['CITY_REQUIRED', UnprocessableEntityException::CITY_REQUIRED], - ['DECIMAL_PRECISION', UnprocessableEntityException::DECIMAL_PRECISION], - ['DONATION_ITEMS_NOT_SUPPORTED', UnprocessableEntityException::DONATION_ITEMS_NOT_SUPPORTED], - ['DUPLICATE_REFERENCE_ID', UnprocessableEntityException::DUPLICATE_REFERENCE_ID], - ['INVALID_CURRENCY_CODE', UnprocessableEntityException::INVALID_CURRENCY_CODE], - ['INVALID_PAYER_ID', UnprocessableEntityException::INVALID_PAYER_ID], - ['ITEM_TOTAL_MISMATCH', UnprocessableEntityException::ITEM_TOTAL_MISMATCH], - ['ITEM_TOTAL_REQUIRED', UnprocessableEntityException::ITEM_TOTAL_REQUIRED], - ['MAX_VALUE_EXCEEDED', UnprocessableEntityException::MAX_VALUE_EXCEEDED], - ['MISSING_PICKUP_ADDRESS', UnprocessableEntityException::MISSING_PICKUP_ADDRESS], - ['MULTI_CURRENCY_ORDER', UnprocessableEntityException::MULTI_CURRENCY_ORDER], - ['MULTIPLE_ITEM_CATEGORIES', UnprocessableEntityException::MULTIPLE_ITEM_CATEGORIES], - ['MULTIPLE_SHIPPING_ADDRESS_NOT_SUPPORTED', UnprocessableEntityException::MULTIPLE_SHIPPING_ADDRESS_NOT_SUPPORTED], - ['MULTIPLE_SHIPPING_TYPE_NOT_SUPPORTED', UnprocessableEntityException::MULTIPLE_SHIPPING_TYPE_NOT_SUPPORTED], - ['PAYEE_ACCOUNT_INVALID', UnprocessableEntityException::PAYEE_ACCOUNT_INVALID], - ['PAYEE_ACCOUNT_LOCKED_OR_CLOSED', UnprocessableEntityException::PAYEE_ACCOUNT_LOCKED_OR_CLOSED], - ['PAYEE_ACCOUNT_RESTRICTED', UnprocessableEntityException::PAYEE_ACCOUNT_RESTRICTED], - ['REFERENCE_ID_REQUIRED', UnprocessableEntityException::REFERENCE_ID_REQUIRED], - ['PAYMENT_SOURCE_CANNOT_BE_USED', UnprocessableEntityException::PAYMENT_SOURCE_CANNOT_BE_USED], - ['PAYMENT_SOURCE_DECLINED_BY_PROCESSOR', UnprocessableEntityException::PAYMENT_SOURCE_DECLINED_BY_PROCESSOR], - ['PAYMENT_SOURCE_INFO_CANNOT_BE_VERIFIED', UnprocessableEntityException::PAYMENT_SOURCE_INFO_CANNOT_BE_VERIFIED], - ['POSTAL_CODE_REQUIRED', UnprocessableEntityException::POSTAL_CODE_REQUIRED], - ['SHIPPING_ADDRESS_INVALID', UnprocessableEntityException::SHIPPING_ADDRESS_INVALID], - ['TAX_TOTAL_MISMATCH', UnprocessableEntityException::TAX_TOTAL_MISMATCH], - ['TAX_TOTAL_REQUIRED', UnprocessableEntityException::TAX_TOTAL_REQUIRED], - ['UNSUPPORTED_INTENT', UnprocessableEntityException::UNSUPPORTED_INTENT], - ['UNSUPPORTED_PAYMENT_INSTRUCTION', UnprocessableEntityException::UNSUPPORTED_PAYMENT_INSTRUCTION], - ['SHIPPING_TYPE_NOT_SUPPORTED_FOR_CLIENT', UnprocessableEntityException::SHIPPING_TYPE_NOT_SUPPORTED_FOR_CLIENT], - ['UNSUPPORTED_SHIPPING_TYPE', UnprocessableEntityException::UNSUPPORTED_SHIPPING_TYPE], - ['SHIPPING_OPTION_NOT_SELECTED', UnprocessableEntityException::SHIPPING_OPTION_NOT_SELECTED], - ['SHIPPING_OPTIONS_NOT_SUPPORTED', UnprocessableEntityException::SHIPPING_OPTIONS_NOT_SUPPORTED], - ['MULTIPLE_SHIPPING_OPTION_SELECTED', UnprocessableEntityException::MULTIPLE_SHIPPING_OPTION_SELECTED], - ['PREFERRED_SHIPPING_OPTION_AMOUNT_MISMATCH', UnprocessableEntityException::PREFERRED_SHIPPING_OPTION_AMOUNT_MISMATCH], - ['CARD_CLOSED', UnprocessableEntityException::CARD_CLOSED], - ['ORDER_CANNOT_BE_SAVED', UnprocessableEntityException::ORDER_CANNOT_BE_SAVED], - ['SAVE_ORDER_NOT_SUPPORTED', UnprocessableEntityException::SAVE_ORDER_NOT_SUPPORTED], - ['PUI_DUPLICATE_ORDER', UnprocessableEntityException::PUI_DUPLICATE_ORDER], - ]; - } -} diff --git a/tests/Unit/PaymentService/PaymentServiceGetOrderTest.php b/tests/Unit/PaymentService/PaymentServiceGetOrderTest.php deleted file mode 100644 index 400cd2d62..000000000 --- a/tests/Unit/PaymentService/PaymentServiceGetOrderTest.php +++ /dev/null @@ -1,91 +0,0 @@ -handleErrorsGetOrder(401, $errorName, $errorCode); - } - - /** - * @param int $statusCode - * @param string $errorName - * @param int $errorCode - * - * @throws InvalidRequestException|NotAuthorizedException|UnprocessableEntityException|PsCheckoutException - */ - private function handleErrorsGetOrder($statusCode, $errorName, $errorCode) - { - if ($errorName === 'invalid_token') { - $error = $this->getInvalidTokenError(); - } else { - $error = $this->getNotAuthorizedError($errorName); - } - - $requestMock = $this->createMock(RequestInterface::class); - - $streamMock = $this->createMock(StreamInterface::class); - $streamMock->method('getContents')->willReturn(json_encode($error)); - - $responseMock = $this->createMock(ResponseInterface::class); - $responseMock->method('getStatusCode')->willReturn($statusCode); - $responseMock->method('getBody')->willReturn($streamMock); - - $clientMock = $this->createMock(CheckoutHttpClient::class); - $clientMock->method('fetchOrder')->willThrowException(new HttpException('An error occurred', $requestMock, $responseMock)); - - $this->expectExceptionCode($errorCode); - $paymentService = new PaymentService($clientMock, new ObjectSerializer()); - $paymentService->getOrder('LUX8l091NV'); - } - - private function getNotAuthorizedError($issueError) - { - return [ - 'name' => $issueError, - 'message' => 'Authentication failed due to invalid authentication credentials or a missing Authorization header.', - 'links' => [ - [ - 'href' => 'https://developer.paypal.com/docs/api/overview/#error', - 'rel' => 'information_link', - ], - ], - ]; - } - - private function getInvalidTokenError() - { - return [ - 'error' => 'invalid_token', - 'error_description' => 'Current version only supports token for response_type', - ]; - } - - public function notAuthorizedErrorsProvider() - { - return [ - ['PERMISSION_DENIED', NotAuthorizedException::PERMISSION_DENIED], - ['invalid_token', NotAuthorizedException::INVALID_TOKEN], - ]; - } -} diff --git a/tests/Unit/PaymentService/PaymentServiceUpdateOrderTest.php b/tests/Unit/PaymentService/PaymentServiceUpdateOrderTest.php deleted file mode 100644 index 643bde370..000000000 --- a/tests/Unit/PaymentService/PaymentServiceUpdateOrderTest.php +++ /dev/null @@ -1,201 +0,0 @@ -handleErrorsUpdateOrder(400, $errorName, $errorCode); - } - - /** - * @dataProvider notAuthorizedErrorsProvider - * - * @throws InvalidRequestException|NotAuthorizedException|UnprocessableEntityException|PsCheckoutException - */ - public function testNotAuthorizedErrorsUpdateOrder($errorName, $errorCode) - { - $this->handleErrorsUpdateOrder(401, $errorName, $errorCode); - } - - /** - * @dataProvider unprocessableEntityErrorsProvider - * - * @throws InvalidRequestException|NotAuthorizedException|UnprocessableEntityException|PsCheckoutException - */ - public function testUnprocessableEntityErrorsUpdateOrder($errorName, $errorCode) - { - $this->handleErrorsUpdateOrder(422, $errorName, $errorCode); - } - - /** - * @param int $statusCode - * @param string $errorName - * @param int $errorCode - * - * @throws InvalidRequestException|NotAuthorizedException|UnprocessableEntityException|PsCheckoutException - */ - private function handleErrorsUpdateOrder($statusCode, $errorName, $errorCode) - { - switch ($statusCode) { - case 400: - $error = $this->getInvalidRequestError($errorName); - break; - case 401: - $error = $this->getNotAuthorizedError($errorName); - break; - case 422: - default: - $error = $this->getUnprocessableEntityError($errorName); - break; - } - - $requestMock = $this->createMock(RequestInterface::class); - $updateRequestMock = $this->createMock(UpdatePayPalOrderRequestInterface::class); - - $streamMock = $this->createMock(StreamInterface::class); - $streamMock->method('getContents')->willReturn(json_encode($error)); - - $responseMock = $this->createMock(ResponseInterface::class); - $responseMock->method('getStatusCode')->willReturn($statusCode); - $responseMock->method('getBody')->willReturn($streamMock); - - $clientMock = $this->createMock(CheckoutHttpClient::class); - $clientMock->method('updateOrder')->willThrowException(new HttpException('An error occurred', $requestMock, $responseMock)); - - $objectSerializer = new ObjectSerializer(); - - $this->expectExceptionCode($errorCode); - $paymentService = new PaymentService($clientMock, $objectSerializer); - $paymentService->updateOrder($updateRequestMock); - } - - private function getInvalidRequestError($issueError) - { - return [ - 'name' => 'INVALID_REQUEST', - 'message' => 'Request is not well-formed, syntactically incorrect, or violates schema.', - 'debug_id' => 'b6b9a374802ea', - 'details' => [ - [ - 'field' => '', - 'value' => '', - 'location' => 'body', - 'issue' => $issueError, - 'description' => '', - ], - ], - 'links' => [ - [ - 'href' => 'https://developer.paypal.com/docs/api/orders/v2/#error-INVALID_PARAMETER_VALUE', - 'rel' => 'information_link', - 'encType' => 'application/json', - ], - ], - ]; - } - - private function getNotAuthorizedError($issueError) - { - return [ - 'name' => $issueError, - 'message' => 'Authentication failed due to invalid authentication credentials or a missing Authorization header.', - 'links' => [ - [ - 'href' => 'https://developer.paypal.com/docs/api/overview/#error', - 'rel' => 'information_link', - ], - ], - ]; - } - - private function getUnprocessableEntityError($issueError) - { - return [ - 'name' => 'UNPROCESSABLE_ENTITY', - 'details' => [ - [ - 'field' => '', - 'value' => '', - 'issue' => $issueError, - 'description' => '', - ], - ], - 'message' => 'The requested action could not be performed, semantically incorrect, or failed business validation.', - 'debug_id' => 'c9a75b43fc807', - 'links' => [ - [ - 'href' => 'https://developer.paypal.com/docs/api/orders/v2/#error-MAX_VALUE_EXCEEDED', - 'rel' => 'information_link', - 'method' => 'GET', - ], - ], - ]; - } - - public function invalidRequestErrorsProvider() - { - return [ - ['FIELD_NOT_PATCHABLE', InvalidRequestException::FIELD_NOT_PATCHABLE], - ['INVALID_ARRAY_MAX_ITEMS', InvalidRequestException::INVALID_ARRAY_MAX_ITEMS], - ['INVALID_PARAMETER_SYNTAX', InvalidRequestException::INVALID_PARAMETER_SYNTAX], - ['INVALID_STRING_LENGTH', InvalidRequestException::INVALID_STRING_LENGTH], - ['INVALID_PARAMETER_VALUE', InvalidRequestException::INVALID_PARAMETER_VALUE], - ['MISSING_REQUIRED_PARAMETER', InvalidRequestException::MISSING_REQUIRED_PARAMETER], - ['AMOUNT_NOT_PATCHABLE', InvalidRequestException::AMOUNT_NOT_PATCHABLE], - ['INVALID_PATCH_OPERATION', InvalidRequestException::INVALID_PATCH_OPERATION], - ['ERROR_CURRENTLY_UNKNOWN', InvalidRequestException::UNKNOWN], - ]; - } - - public function notAuthorizedErrorsProvider() - { - return [ - ['PERMISSION_DENIED', NotAuthorizedException::PERMISSION_DENIED], - ['PAYEE_ACCOUNT_NOT_SUPPORTED', NotAuthorizedException::PAYEE_ACCOUNT_NOT_SUPPORTED], - ['PAYEE_ACCOUNT_NOT_VERIFIED', NotAuthorizedException::PAYEE_ACCOUNT_NOT_VERIFIED], - ['PAYEE_NOT_CONSENTED', NotAuthorizedException::PAYEE_NOT_CONSENTED], - ['ERROR_CURRENTLY_UNKNOWN', NotAuthorizedException::UNKNOWN], - ]; - } - - public function unprocessableEntityErrorsProvider() - { - return [ - ['INVALID_JSON_POINTER_FORMAT', UnprocessableEntityException::INVALID_JSON_POINTER_FORMAT], - ['INVALID_PARAMETER', UnprocessableEntityException::INVALID_PARAMETER], - ['NOT_PATCHABLE', UnprocessableEntityException::NOT_PATCHABLE], - ['UNSUPPORTED_PATCH_PARAMETER_VALUE', UnprocessableEntityException::UNSUPPORTED_PATCH_PARAMETER_VALUE], - ['PATCH_VALUE_REQUIRED', UnprocessableEntityException::PATCH_VALUE_REQUIRED], - ['PATCH_PATH_REQUIRED', UnprocessableEntityException::PATCH_PATH_REQUIRED], - ['REFERENCE_ID_NOT_FOUND', UnprocessableEntityException::REFERENCE_ID_NOT_FOUND], - ['MULTI_CURRENCY_ORDER', UnprocessableEntityException::MULTI_CURRENCY_ORDER], - ['SHIPPING_OPTION_NOT_SELECTED', UnprocessableEntityException::SHIPPING_OPTION_NOT_SELECTED], - ['SHIPPING_OPTIONS_NOT_SUPPORTED', UnprocessableEntityException::SHIPPING_OPTIONS_NOT_SUPPORTED], - ['MULTIPLE_SHIPPING_OPTION_SELECTED', UnprocessableEntityException::MULTIPLE_SHIPPING_OPTION_SELECTED], - ['ORDER_ALREADY_COMPLETED', UnprocessableEntityException::ORDER_ALREADY_COMPLETED], - ['PREFERRED_SHIPPING_OPTION_AMOUNT_MISMATCH', UnprocessableEntityException::PREFERRED_SHIPPING_OPTION_AMOUNT_MISMATCH], - ['ERROR_CURRENTLY_UNKNOWN', UnprocessableEntityException::UNKNOWN], - ]; - } -} diff --git a/tests/Unit/Serializer/ObjectSerializerTest.php b/tests/Unit/Serializer/ObjectSerializerTest.php deleted file mode 100644 index 5099ffc39..000000000 --- a/tests/Unit/Serializer/ObjectSerializerTest.php +++ /dev/null @@ -1,250 +0,0 @@ - - * @copyright Since 2007 PrestaShop SA and Contributors - * @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0 - */ - -namespace Serializer; - -use PHPUnit\Framework\TestCase; -use PrestaShop\Module\PrestashopCheckout\FundingSource\FundingSourceEntity; -use PrestaShop\Module\PrestashopCheckout\PayPal\Order\DTO\CardResponse; -use PrestaShop\Module\PrestashopCheckout\PayPal\Order\DTO\CreatePayPalOrderResponse; -use PrestaShop\Module\PrestashopCheckout\PayPal\Order\DTO\LinkDescription; -use PrestaShop\Module\PrestashopCheckout\PayPal\Order\DTO\PaymentSourceResponse; -use PrestaShop\Module\PrestashopCheckout\Serializer\ObjectSerializer; -use Symfony\Component\Serializer\Encoder\JsonEncoder; - -class ObjectSerializerTest extends TestCase -{ - /** - * @var ObjectSerializer - */ - private $serializer; - - public function __construct($name = null, array $data = [], $dataName = '') - { - parent::__construct($name, $data, $dataName); - $this->serializer = new ObjectSerializer(); - } - - /** - * @dataProvider objectProvider - */ - public function testSerializeWithoutEmptyValues($object, $expectedJson) - { - $json = $this->serializer->serialize($object, JsonEncoder::FORMAT, true); - $this->assertEquals($expectedJson, $json); - } - - /** - * @dataProvider objectWithEmptyValuesProvider - */ - public function testSerializeWithEmptyValues($object, $expectedJson) - { - $json = $this->serializer->serialize($object, JsonEncoder::FORMAT); - $this->assertEquals($expectedJson, $json); - } - - /** - * @dataProvider objectProvider - */ - public function testDeserialize($expectedObject, $json) - { - $newObject = $this->serializer->deserialize($json, FundingSourceEntity::class, JsonEncoder::FORMAT); - $this->assertEquals($expectedObject, $newObject); - } - - /** - * @dataProvider createPayPalOrderResponseSerializeObjectProvider - */ - public function testSerializePayPalOrderResponse($object, $expectedJson) - { - $json = $this->serializer->serialize($object, JsonEncoder::FORMAT, true, true); - $this->assertEquals($expectedJson, $json); - } - - /** - * @dataProvider createPayPalOrderResponseDeserializeObjectProvider - */ - public function testDeserializePayPalOrderResponse($expectedObject, $json) - { - $newObject = $this->serializer->deserialize($json, CreatePayPalOrderResponse::class, JsonEncoder::FORMAT); - $this->assertEquals($expectedObject, $newObject); - } - - /** - * @dataProvider arrayProvider - */ - public function testToArray($object, $expectedArray, $skipNullValues, $convertToSnakeCase) - { - $newArray = $this->serializer->toArray($object, $skipNullValues, $convertToSnakeCase); - $this->assertEquals($expectedArray, $newArray); - } - - public function objectProvider() - { - $fundingSourceEntity = new FundingSourceEntity('paypal'); - $fundingSourceEntity->setCountries(['US', 'FR']); - $fundingSourceEntity->setPosition(0); - - return [ - [ - new FundingSourceEntity('paypal'), - '{"name":"paypal","countries":[],"isEnabled":true,"isToggleable":true}', - ], - [ - $fundingSourceEntity, - '{"name":"paypal","position":0,"countries":["US","FR"],"isEnabled":true,"isToggleable":true}', - ], - ]; - } - - public function objectWithEmptyValuesProvider() - { - $fundingSourceEntity = new FundingSourceEntity('paypal'); - $fundingSourceEntity->setCountries(['US', 'FR']); - $fundingSourceEntity->setPosition(0); - - return [ - [ - new FundingSourceEntity('paypal'), - '{"name":"paypal","position":null,"countries":[],"isEnabled":true,"isToggleable":true}', - ], - [ - $fundingSourceEntity, - '{"name":"paypal","position":0,"countries":["US","FR"],"isEnabled":true,"isToggleable":true}', - ], - ]; - } - - public function createPayPalOrderResponseSerializeObjectProvider() - { - return [ - [ - (new CreatePayPalOrderResponse()) - ->setId('SOME_ID') - ->setLinks([new LinkDescription(['href' => 'HREF', 'rel' => 'REL', 'method' => 'METHOD'])]), - '{"id":"SOME_ID","links":[{"href":"HREF","rel":"REL","method":"METHOD"}]}', - ], - [ - (new CreatePayPalOrderResponse()) - ->setId('SOME_ID') - ->setLinks([new LinkDescription(['href' => 'HREF', 'rel' => 'REL', 'method' => 'METHOD'])]) - ->setPaymentSource(new PaymentSourceResponse(['card' => new CardResponse(['name' => 'AMEX'])])), - '{"id":"SOME_ID","payment_source":{"card":{"name":"AMEX"}},"links":[{"href":"HREF","rel":"REL","method":"METHOD"}]}', - ], - ]; - } - - public function createPayPalOrderResponseDeserializeObjectProvider() - { - return [ - [ - (new CreatePayPalOrderResponse()) - ->setId('SOME_ID') - ->setLinks([new LinkDescription(['href' => 'HREF', 'rel' => 'REL', 'method' => 'METHOD'])]), - '{"id":"SOME_ID","links":[{"href":"HREF","rel":"REL","method":"METHOD"}]}', - ], - [ - (new CreatePayPalOrderResponse()) - ->setId('SOME_ID') - ->setLinks([new LinkDescription(['href' => 'HREF', 'rel' => 'REL', 'method' => 'METHOD'])]) - ->setPaymentSource(new PaymentSourceResponse(['card' => new CardResponse(['name' => 'AMEX'])])), - '{"id":"SOME_ID","payment_source":{"card":{"name":"AMEX"}},"links":[{"href":"HREF","rel":"REL","method":"METHOD"}]}', - ], - [ - (new CreatePayPalOrderResponse()) - ->setId('SOME_ID') - ->setLinks([new LinkDescription(['href' => 'HREF', 'rel' => 'REL', 'method' => 'METHOD'])]) - ->setPaymentSource(new PaymentSourceResponse(['card' => new CardResponse(['name' => 'AMEX'])])), - '{"id": "SOME_ID","cart_id":"RANDOM_CART_ID","payment_source":{"card":{"name":"AMEX"}},"links":[{"href":"HREF","rel":"REL","method":"METHOD"}]}', - ], - ]; - } - - public function arrayProvider() - { - return [ - [ - (new CreatePayPalOrderResponse()) - ->setId('SOME_ID') - ->setLinks([new LinkDescription(['href' => 'HREF', 'rel' => 'REL', 'method' => 'METHOD'])]) - ->setPaymentSource(new PaymentSourceResponse(['card' => new CardResponse(['name' => 'AMEX'])])), - [ - 'id' => 'SOME_ID', - 'create_time' => null, - 'update_time' => null, - 'payment_source' => [ - 'card' => [ - 'name' => 'AMEX', - 'last_digits' => null, - 'brand' => null, - 'available_networks' => null, - 'type' => null, - 'authentication_result' => null, - 'attributes' => null, - 'from_request' => null, - 'expiry' => null, - 'bin_details' => null, - ], - 'paypal' => null, - 'bancontact' => null, - 'blik' => null, - 'eps' => null, - 'giropay' => null, - 'ideal' => null, - 'mybank' => null, - 'p24' => null, - 'sofort' => null, - 'trustly' => null, - 'venmo' => null, - ], - 'intent' => null, - 'processing_instruction' => null, - 'payer' => null, - 'purchase_units' => null, - 'status' => null, - 'links' => [ - ['href' => 'HREF', 'rel' => 'REL', 'method' => 'METHOD'], - ], - ], - false, - true, - ], - [ - (new CreatePayPalOrderResponse()) - ->setId('SOME_ID') - ->setLinks([new LinkDescription(['href' => 'HREF', 'rel' => 'REL', 'method' => 'METHOD'])]) - ->setPaymentSource(new PaymentSourceResponse(['card' => new CardResponse(['name' => 'AMEX'])])), - [ - 'id' => 'SOME_ID', - 'payment_source' => [ - 'card' => [ - 'name' => 'AMEX', - ], - ], - 'links' => [ - ['href' => 'HREF', 'rel' => 'REL', 'method' => 'METHOD'], - ], - ], - true, - true, - ], - ]; - } -}