From 5682afe7e9e1f582fe4fe20804802f41e4f41eb1 Mon Sep 17 00:00:00 2001 From: joyet simon <43644110+joyet-simon@users.noreply.github.com> Date: Fri, 7 Jun 2024 09:51:11 +0200 Subject: [PATCH 1/6] unit test refacto --- .DS_Store | Bin 0 -> 8196 bytes Dockerfile | 2 +- Taskfile.php.yml | 2 +- Taskfile.yml | 10 - phpunit.dist.legacy.xml | 2 +- phpunit.dist.xml | 4 +- src/Endpoints/Orders.php | 4 +- tests/Unit/{PHP8_1 => }/ArrayUtilsTest.php | 2 +- tests/Unit/{PHP8_1 => }/ClientContextTest.php | 2 +- .../ClientOptionsValidatorTest.php | 72 +- tests/Unit/Endpoints/InsuranceTest.php | 1039 +++++++++++++++++ .../{Legacy => }/Endpoints/OrdersTest.php | 52 +- .../{Legacy => }/Endpoints/PaymentsTest.php | 437 +++---- .../Unit/Entities/Insurance/ContractTest.php | 287 +++++ .../Entities/Insurance/FileTest.php | 4 +- .../Entities/Insurance/SubscriberTest.php | 4 +- .../Entities/Insurance/SubscriptionTest.php | 4 +- tests/Unit/Legacy/ArrayUtilsTest.php | 36 - tests/Unit/Legacy/ClientContextTest.php | 58 - .../Legacy/ClientOptionsValidatorTest.php | 155 --- tests/Unit/Legacy/Endpoints/InsuranceTest.php | 1000 ---------------- .../Entities/Insurance/ContractTest.php | 289 ----- tests/Unit/Legacy/RequestErrorTest.php | 59 - .../Unit/{Legacy => }/Lib/ArrayUtilsTest.php | 4 +- .../Lib/InsuranceValidatorTest.php | 21 +- tests/Unit/PHP7_0/ArrayUtilsTest.php | 36 - tests/Unit/PHP7_0/ClientContextTest.php | 58 - .../PHP7_0/ClientOptionsValidatorTest.php | 155 --- tests/Unit/PHP7_0/Endpoints/PaymentsTest.php | 511 -------- tests/Unit/PHP7_0/RequestErrorTest.php | 59 - tests/Unit/PHP7_2/ArrayUtilsTest.php | 36 - tests/Unit/PHP7_2/ClientContextTest.php | 58 - .../PHP7_2/ClientOptionsValidatorTest.php | 155 --- tests/Unit/PHP7_2/Endpoints/PaymentsTest.php | 511 -------- tests/Unit/PHP8_1/Endpoints/InsuranceTest.php | 144 --- tests/Unit/PHP8_1/Endpoints/PaymentsTest.php | 511 -------- tests/Unit/PHP8_1/RequestErrorTest.php | 59 - tests/Unit/{PHP7_2 => }/RequestErrorTest.php | 11 +- 38 files changed, 1614 insertions(+), 4239 deletions(-) create mode 100644 .DS_Store rename tests/Unit/{PHP8_1 => }/ArrayUtilsTest.php (95%) rename tests/Unit/{PHP8_1 => }/ClientContextTest.php (97%) rename tests/Unit/{PHP8_1 => }/ClientOptionsValidatorTest.php (78%) create mode 100644 tests/Unit/Endpoints/InsuranceTest.php rename tests/Unit/{Legacy => }/Endpoints/OrdersTest.php (79%) rename tests/Unit/{Legacy => }/Endpoints/PaymentsTest.php (55%) create mode 100644 tests/Unit/Entities/Insurance/ContractTest.php rename tests/Unit/{Legacy => }/Entities/Insurance/FileTest.php (95%) rename tests/Unit/{Legacy => }/Entities/Insurance/SubscriberTest.php (96%) rename tests/Unit/{Legacy => }/Entities/Insurance/SubscriptionTest.php (95%) delete mode 100644 tests/Unit/Legacy/ArrayUtilsTest.php delete mode 100644 tests/Unit/Legacy/ClientContextTest.php delete mode 100644 tests/Unit/Legacy/ClientOptionsValidatorTest.php delete mode 100644 tests/Unit/Legacy/Endpoints/InsuranceTest.php delete mode 100644 tests/Unit/Legacy/Entities/Insurance/ContractTest.php delete mode 100644 tests/Unit/Legacy/RequestErrorTest.php rename tests/Unit/{Legacy => }/Lib/ArrayUtilsTest.php (94%) rename tests/Unit/{Legacy => }/Lib/InsuranceValidatorTest.php (74%) delete mode 100644 tests/Unit/PHP7_0/ArrayUtilsTest.php delete mode 100644 tests/Unit/PHP7_0/ClientContextTest.php delete mode 100644 tests/Unit/PHP7_0/ClientOptionsValidatorTest.php delete mode 100644 tests/Unit/PHP7_0/Endpoints/PaymentsTest.php delete mode 100644 tests/Unit/PHP7_0/RequestErrorTest.php delete mode 100644 tests/Unit/PHP7_2/ArrayUtilsTest.php delete mode 100644 tests/Unit/PHP7_2/ClientContextTest.php delete mode 100644 tests/Unit/PHP7_2/ClientOptionsValidatorTest.php delete mode 100644 tests/Unit/PHP7_2/Endpoints/PaymentsTest.php delete mode 100644 tests/Unit/PHP8_1/Endpoints/InsuranceTest.php delete mode 100644 tests/Unit/PHP8_1/Endpoints/PaymentsTest.php delete mode 100644 tests/Unit/PHP8_1/RequestErrorTest.php rename tests/Unit/{PHP7_2 => }/RequestErrorTest.php (79%) diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..5ed85e1a9eb9d2f934e8d4a812e7946ec7c663f7 GIT binary patch literal 8196 zcmeHMU279T6upzC?S`}^h{YlZ3%;f?v3`LsX_}w~KcEqPP^sA@G;6mzA=xxaDdb)K z3;qS){U7>YeA07gre$}Nhz}wKXJF>c?%p#qd+wdx+zkn@uEs|F_; zHJyZ}lQ1(2lc5MTJ9w@#CsEaCTdROoU|Ipr-B*yak0?U!9?#!<)ZYzc+Y6)z8{Ssi zsHLB(pvNBtJn($5IO88uFJ=EFWxql@^bn&wp$F8UNAwg}q9f`gdE#1%w@PiS?Fio# zBxdQ-0Iav@NeWZU4}ZYqdu-ETiuohO%;KJW%n>E+G6(bQyz#JawEF7x1AiEm%il$2 zA-lM=>?}KZ=XJ9u$IYk}jfS<>;3XeDlQQtm`YrFd-yQE4F7L=NYWZPzpa_1a3zJtb z{IDa(H8~19L&a_C3r^0-?H8_|oZP*6r|53pD_2g7?n$LwDHq+XTenY7bI$tp8~6A2 z4}+sne#Giggn5Y4sy;q%KcRPi=f}-K7|4+CnC+M0v0Zqu0sl3rk<#TGEaI`T4sRiX z5Fa6QjA#?J2hVjmPT&C@Gs-485^>agjz!s8YNQgp=OY5%AtHh#S4B>odu57iyb6AR zwHzSw+w^|UXdF%P(F(sAZPscyrsDkk6n_RwMOd7bqdjQ8O?7$ phpunit.xml +# - sed 's/{MYVERSION}/{{ .PHPUNIT_VERSION }}/g' {{ .PHPUNIT_FILE }} > phpunit.xml - docker compose run {{ .COMPOSE_SERVICE }} composer exec phpunit --verbose -- --testsuite "Alma PHP Client Unit Test Suite" tests:integration: diff --git a/Taskfile.yml b/Taskfile.yml index 7f39fe45..3590b4f7 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -12,54 +12,44 @@ includes: vars: PHP_VERSION: "5.6" COMPOSE_SERVICE: php-legacy # Dockerfile needs specific APT configuration - PHPUNIT_VERSION: Legacy PHPUNIT_FILE: phpunit.dist.legacy.xml "7.0": taskfile: Taskfile.php.yml vars: PHP_VERSION: "7.0" COMPOSE_SERVICE: php-legacy # Dockerfile needs specific APT configuration - PHPUNIT_VERSION: PHP7_0 "7.1": taskfile: Taskfile.php.yml vars: PHP_VERSION: "7.1" - PHPUNIT_VERSION: PHP7_0 "7.2": taskfile: Taskfile.php.yml vars: PHP_VERSION: "7.2" - PHPUNIT_VERSION: PHP7_2 "7.3": taskfile: Taskfile.php.yml vars: PHP_VERSION: "7.3" - PHPUNIT_VERSION: PHP7_2 "7.4": taskfile: Taskfile.php.yml vars: PHP_VERSION: "7.4" - PHPUNIT_VERSION: PHP7_2 "8.0": taskfile: Taskfile.php.yml vars: PHP_VERSION: "8.0" - PHPUNIT_VERSION: PHP7_2 "8.1": taskfile: Taskfile.php.yml vars: PHP_VERSION: "8.1" - PHPUNIT_VERSION: PHP8_1 "8.2": taskfile: Taskfile.php.yml vars: PHP_VERSION: "8.2" - PHPUNIT_VERSION: PHP8_1 "8.3": taskfile: Taskfile.php.yml vars: PHP_VERSION: "8.3" - PHPUNIT_VERSION: PHP8_1 tasks: default: diff --git a/phpunit.dist.legacy.xml b/phpunit.dist.legacy.xml index c8b23594..0b12d7ad 100644 --- a/phpunit.dist.legacy.xml +++ b/phpunit.dist.legacy.xml @@ -13,7 +13,7 @@ - tests/Unit/{MYVERSION} + tests/Unit tests/Integration/{MYVERSION} diff --git a/phpunit.dist.xml b/phpunit.dist.xml index a8cc84a1..08cf52d7 100644 --- a/phpunit.dist.xml +++ b/phpunit.dist.xml @@ -1,8 +1,8 @@ - + - tests/Unit/{MYVERSION} + tests/Unit tests/Integration/{MYVERSION} diff --git a/src/Endpoints/Orders.php b/src/Endpoints/Orders.php index e693ff1e..c495a326 100644 --- a/src/Endpoints/Orders.php +++ b/src/Endpoints/Orders.php @@ -127,7 +127,7 @@ public function sendStatus($orderExternalId, $orderData = array()) 'is_shipped' => $orderData['is_shipped'], ))->post(); }catch (AlmaException $e) { - $this->logger->error('Error sending status'); + $this->logger->error('Error sending status'); throw new RequestException('Error sending status', $e); } @@ -150,7 +150,7 @@ public function validateStatusData($orderData = array()) try { $this->arrayUtils->checkMandatoryKeys(['status', 'is_shipped'], $orderData); } catch (MissingKeyException $e ) { - throw new ParametersException('Error in the required parameters (status, is_shipped) when calling orders.sendStatus',null, $e); + throw new ParametersException('Error in the required parameters (status, is_shipped) when calling orders.sendStatus',0, $e); } if(!is_bool($orderData['is_shipped'])) { diff --git a/tests/Unit/PHP8_1/ArrayUtilsTest.php b/tests/Unit/ArrayUtilsTest.php similarity index 95% rename from tests/Unit/PHP8_1/ArrayUtilsTest.php rename to tests/Unit/ArrayUtilsTest.php index cebc2e58..df4dcbd8 100644 --- a/tests/Unit/PHP8_1/ArrayUtilsTest.php +++ b/tests/Unit/ArrayUtilsTest.php @@ -1,6 +1,6 @@ [ + [ + 'api_root' => [ + 'something wrong' => Client::SANDBOX_API_URL, + 'something wronger' => Client::LIVE_API_URL + ], + ], + ], + 'invalid tls' => [ + [ + 'force_tls' => -1, + ], + ], + 'invalid mode' => [ + [ + 'mode' => 'sad', + ], + ], + 'invalid user_agent_component' => [ + [ + 'user_agent_component' => [ + 'I dont give a key:value pair', + ] + ], + ], + ]; + } + /** * @dataProvider getClientOptions * @return void @@ -107,41 +142,6 @@ public function testClientOptionsValidator($options, $expectedResult) $this->assertEquals($expectedResult, $validatedConfig); } - /** - * Return faulty options to test ClientOptionsValidator::validateOptions - * @return array - */ - public static function getInvalidClientOptions() - { - return [ - 'invalid api_root' => [ - [ - 'api_root' => [ - 'something wrong' => Client::SANDBOX_API_URL, - 'something wronger' => Client::LIVE_API_URL - ], - ], - ], - 'invalid tls' => [ - [ - 'force_tls' => -1, - ], - ], - 'invalid mode' => [ - [ - 'mode' => 'sad', - ], - ], - 'invalid user_agent_component' => [ - [ - 'user_agent_component' => [ - 'I dont give a key:value pair', - ] - ], - ], - ]; - } - /** * @dataProvider getInvalidClientOptions * @return void diff --git a/tests/Unit/Endpoints/InsuranceTest.php b/tests/Unit/Endpoints/InsuranceTest.php new file mode 100644 index 00000000..544c2f2d --- /dev/null +++ b/tests/Unit/Endpoints/InsuranceTest.php @@ -0,0 +1,1039 @@ +clientContext = Mockery::mock(ClientContext::class); + $this->responseMock = Mockery::mock(Response::class); + $this->responseMock->errorMessage = 'Exception Error message'; + $this->requestObject = Mockery::mock(Request::class); + $this->insuranceMock = Mockery::mock(Insurance::class)->makePartial(); + $this->insuranceValidatorMock = Mockery::mock(InsuranceValidator::class); + $this->insuranceMock->insuranceValidator = $this->insuranceValidatorMock; + + $this->arrayUtilsMock = Mockery::mock(ArrayUtils::class); + } + + protected function tearDown(): void + { + $this->clientContext = null; + $this->responseMock = null; + $this->requestObject = null; + $this->insuranceMock = null; + $this->insuranceValidatorMock = null; + Mockery::close(); + } + + /** + * @return array + */ + public static function nonArrayParamDataProvider() + { + return [ + 'Test with Null and payment id valid' => [ + null, + 'payment_xxx' + ], + 'Test with String and payment id valid' => [ + 'my string', + 'payment_xxx' + ], + 'Test with Object and payment id valid' => [ + new Subscription( + 'insurance_contract_6VU1zZ5AKfy6EejiNxmLXh', + 1235, + '19', + 1312, + new Subscriber( + self::TEST_EMAIL, + self::TEST_PHONENUMBER, + 'lastname', + 'firstname', + 'address1', + 'address2', + 'zipcode', + 'city', + 'country', + null + ), + 'cancelUrl' + ), + 'payment_xxx' + ] + ]; + } + + /** + * @return array[] + */ + public static function subscriptionDataProvider() + { + return [ + 'Test with right data and without payment id' => [ + [ + new Subscription( + 'insurance_contract_6VU1zZ5AKfy6EejiNxmLXh', + 1235, + '19', + 1312, + new Subscriber( + self::TEST_EMAIL, + self::TEST_PHONENUMBER, + 'lastname', + 'firstname', + 'address1', + 'address2', + 'zipcode', + 'city', + 'country', + null + ), + 'cancelUrl' + ), + new Subscription( + 'insurance_contract_3vt2jyvWWQc9wZCmWd1KtI', + 1568, + self::TEST_CMSREFERENCE, + 1312, + new Subscriber( + self::TEST_EMAIL, + self::TEST_PHONENUMBER, + 'last', + 'first', + 'adr1', + 'adr2', + 'zip', + 'city', + 'country', + self::TEST_BIRTHDATE + ), + 'cancelUrl' + ) + ], + null, + [ + 'subscriptions' => [ + [ + 'insurance_contract_id' => 'insurance_contract_6VU1zZ5AKfy6EejiNxmLXh', + 'amount' => 1235, + 'cms_reference' => '19', + 'product_price' => 1312, + 'cms_callback_url' => 'cancelUrl', + 'subscriber' => [ + 'email' => self::TEST_EMAIL, + 'phone_number' => self::TEST_PHONENUMBER, + 'last_name' => 'lastname', + 'first_name' => 'firstname', + 'birthdate' => null, + 'address' => [ + 'address_line_1' => 'address1', + 'address_line_2' => 'address2', + 'zip_code' => 'zipcode', + 'city' => 'city', + 'country' => 'country', + ] + ], + ], + [ + 'insurance_contract_id' => 'insurance_contract_3vt2jyvWWQc9wZCmWd1KtI', + 'amount' => 1568, + 'cms_reference' => self::TEST_CMSREFERENCE, + 'product_price' => 1312, + 'cms_callback_url' => 'cancelUrl', + 'subscriber' => [ + 'email' => self::TEST_EMAIL, + 'phone_number' => self::TEST_PHONENUMBER, + 'last_name' => 'last', + 'first_name' => 'first', + 'birthdate' => self::TEST_BIRTHDATE, + 'address' => [ + 'address_line_1' => 'adr1', + 'address_line_2' => 'adr2', + 'zip_code' => 'zip', + 'city' => 'city', + 'country' => 'country', + ] + ], + ] + ] + ] + ], + 'Test with right data and payment id' => [ + [ + new Subscription( + 'insurance_contract_6VU1zZ5AKfy6EejiNxmLXh', + 1235, + '19', + 1312, + new Subscriber( + self::TEST_EMAIL, + self::TEST_PHONENUMBER, + 'lastname', + 'firstname', + 'address1', + 'address2', + 'zipcode', + 'city', + 'country', + null + ), + 'cancelUrl' + ), + new Subscription( + 'insurance_contract_3vt2jyvWWQc9wZCmWd1KtI', + 1568, + self::TEST_CMSREFERENCE, + 1312, + new Subscriber( + self::TEST_EMAIL, + self::TEST_PHONENUMBER, + 'last', + 'first', + 'adr1', + 'adr2', + 'zip', + 'city', + 'country', + self::TEST_BIRTHDATE + ), + 'cancelUrl' + ) + ], + 'payment_11xlpX9QQYhd3xZVzNMrtdKw4myV7QET7X', + [ + 'subscriptions' => [ + [ + 'insurance_contract_id' => 'insurance_contract_6VU1zZ5AKfy6EejiNxmLXh', + 'amount' => 1235, + 'cms_reference' => '19', + 'product_price' => 1312, + 'cms_callback_url' => 'cancelUrl', + 'subscriber' => [ + 'email' => self::TEST_EMAIL, + 'phone_number' => self::TEST_PHONENUMBER, + 'last_name' => 'lastname', + 'first_name' => 'firstname', + 'birthdate' => null, + 'address' => [ + 'address_line_1' => 'address1', + 'address_line_2' => 'address2', + 'zip_code' => 'zipcode', + 'city' => 'city', + 'country' => 'country', + ] + ], + ], + [ + 'insurance_contract_id' => 'insurance_contract_3vt2jyvWWQc9wZCmWd1KtI', + 'amount' => 1568, + 'cms_reference' => self::TEST_CMSREFERENCE, + 'product_price' => 1312, + 'cms_callback_url' => 'cancelUrl', + 'subscriber' => [ + 'email' => self::TEST_EMAIL, + 'phone_number' => self::TEST_PHONENUMBER, + 'last_name' => 'last', + 'first_name' => 'first', + 'birthdate' => self::TEST_BIRTHDATE, + 'address' => [ + 'address_line_1' => 'adr1', + 'address_line_2' => 'adr2', + 'zip_code' => 'zip', + 'city' => 'city', + 'country' => 'country', + ] + ], + ] + ] + ] + ] + ]; + } + + /** + * @return array[] + */ + public static function requestDataProvider() + { + return [ + 'Throw exception with cms reference null' => [ + 'insuranceContractExternalId' => 'insurance_contract_6XxGHbjr51CE5Oly8E2Amx', + 'cmsReference' => null, + 'productPrice' => 10000 + ], + 'Throw exception with insurance_contract_external_id null and cms reference null' => [ + 'insuranceContractExternalId' => null, + 'cmsReference' => null, + 'productPrice' => 10000 + ], + 'Throw exception with cms reference array' => [ + 'insuranceContractExternalId' => 'insurance_contract_6XxGHbjr51CE5Oly8E2Amx', + 'cmsReference' => ['10', '13'], + 'productPrice' => 10000 + ], + 'Throw exception with cms reference class' => [ + 'insuranceContractExternalId' => 'insurance_contract_6XxGHbjr51CE5Oly8E2Amx', + 'cmsReference' => new \stdClass(), + 'productPrice' => 10000 + ], + 'Throw exception with cms reference bool' => [ + 'insuranceContractExternalId' => 'insurance_contract_6XxGHbjr51CE5Oly8E2Amx', + 'cmsReference' => true, + 'productPrice' => 10000 + ], + 'Throw exception with cms reference string and special characters' => [ + 'insuranceContractExternalId' => 'insurance_contract_6XxGHbjr51CE5Oly8E2Amx', + 'cmsReference' => 'Une Str|ng [Avec] des *', + 'productPrice' => 10000 + ], + 'Throw exception with cms reference string and spacial characters 2' => [ + 'insuranceContractExternalId' => 'insurance_contract_6XxGHbjr51CE5Oly8E2Amx', + 'cmsReference' => 'alma-%product', + 'productPrice' => 10000 + ], + 'Throw exception with cms reference empty string' => [ + 'insuranceContractExternalId' => 'insurance_contract_6XxGHbjr51CE5Oly8E2Amx', + 'cmsReference' => '', + 'productPrice' => 10000 + ] + ]; + } + + /** + * @return array[] + */ + public static function requestDataProviderRightParams() + { + return [ + 'call get with cms reference a string' => [ + 'insuranceContractExternalId' => 'insurance_contract_6XxGHbjr51CE5Oly8E2Amx', + 'cmsReference' => '1-2', + 'productPrice' => 10000 + ], + 'call get with cms reference an integer' => [ + 'insuranceContractExternalId' => 'insurance_contract_6XxGHbjr51CE5Oly8E2Amx', + 'cmsReference' => 18, + 'productPrice' => 10000 + ], + 'Call get with cms reference a string and space' => [ + 'insuranceContractExternalId' => 'insurance_contract_6XxGHbjr51CE5Oly8E2Amx', + 'cmsReference' => 'Alma insurance2 product', + 'productPrice' => 10000 + ], + 'Call get with cms reference a string and - ' => [ + 'insuranceContractExternalId' => 'insurance_contract_6XxGHbjr51CE5Oly8E2Amx', + 'cmsReference' => 'Alma01-insurance-product', + 'productPrice' => 10000 + ] + ]; + } + + /** + * @return array + */ + public static function nonArrayParamGetSubscriptionDataProvider() + { + return [ + 'Test with Null' => [ + null + ], + 'Test with String' => [ + 'my string' + ], + 'Test with Object' => [ + new \stdClass() + ], + 'Test with Integer' => [ + 10 + ], + 'Test with Boolean' => [ + true + ] + ]; + } + + /** + * @return array[] + */ + public static function getSubscriptionsRightParamDataProvider() + { + return [ + 'Test with 1 subscription id' => [ + ['id' => 'subscription_39lGsF0UdBfpjQ8UXdYvkX'], + '{ + "subscriptions": [ + { + "id": "subscription_39lGsF0UdBfpjQ8UXdYvkX", + "broker_subscription_id": "ec407087-65f0-410d-88d7-911178120887", + "subscriber": { + "email": "benjamin.freoua@getalma.eu", + "phone_number": "0613595410", + "first_name": "Freoua", + "last_name": "Benjamin", + "address_line_1": "13 boulevard de Picpus", + "address_line_2": "", + "zip_code": "75012", + "city": "Paris", + "country": "France" + }, + "contract_id": "insurance_contract_4D6UBXtagTd5DZlTGPpKuT", + "amount": 35000, + "state": "started", + "cms_reference": "1-1" + } + ] + }' + ], + 'Test with 2 subscription ids' => [ + [ + 'id' => 'subscription_39lGsF0UdBfpjQ8UXdYvkX', + 'id' => 'subscription_7I02iVfu8vmvDMxIlinXk1' + ], + '{ + "subscriptions": [ + { + "id": "subscription_39lGsF0UdBfpjQ8UXdYvkX", + "broker_subscription_id": "ec407087-65f0-410d-88d7-911178120887", + "subscriber": { + "email": "benjamin.freoua@getalma.eu", + "phone_number": "0613595410", + "first_name": "Freoua", + "last_name": "Benjamin", + "address_line_1": "13 boulevard de Picpus", + "address_line_2": "", + "zip_code": "75012", + "city": "Paris", + "country": "France" + }, + "contract_id": "insurance_contract_4D6UBXtagTd5DZlTGPpKuT", + "amount": 35000, + "state": "started", + "cms_reference": "1-1" + }, + { + "id": "subscription_7I02iVfu8vmvDMxIlinXk1", + "broker_subscription_id": "db774ddd-f50c-4e65-b5bc-5f073acef987", + "subscriber": { + "email": "benjamin.freoua@getalma.eu", + "phone_number": "0613595410", + "first_name": "Freoua", + "last_name": "Benjamin", + "address_line_1": "13 boulevard de Picpus", + "address_line_2": "", + "zip_code": "75012", + "city": "Paris", + "country": "France" + }, + "contract_id": "insurance_contract_4D6UBXtagTd5DZlTGPpKuT", + "amount": 35000, + "state": "started", + "cms_reference": "1-1" + } + ] + }' + ] + ]; + } + + /** + * @return array[] + */ + public static function subscriptionIdInvalidDataProvider() + { + return [ + 'Test with subscription id invalid' => [ + [ + 'id' => 'toto' + ], + '{ + "subscriptions": [] + }' + ] + ]; + } + + /** + * @return array + */ + public static function cancelSubscriptionErrorPayloadDataProvider() + { + return [ + 'Null payload' => [ + 'subscriptionIdsArray' => null + ], + 'empty string payload' => [ + 'subscriptionIdsArray' => '' + ], + 'empty array payload' => [ + 'subscriptionIdsArray' => [] + ], + 'Subscription Object payload' => [ + 'subscriptionIdsArray' => new Subscription( + 'insurance_contract_6VU1zZ5AKfy6EejiNxmLXh', + 1235, + '19', + 1312, + new Subscriber( + self::TEST_EMAIL, + self::TEST_PHONENUMBER, + 'lastname', + 'firstname', + 'address1', + 'address2', + 'zipcode', + 'city', + 'country', + null + ), + 'cancelUrl' + ) + ], + ]; + } + + /** + * @return void + */ + public function testInsuranceEligibilityMethodExist() + { + $insurance = new Insurance($this->clientContext); + $this->assertTrue(method_exists($insurance, 'getInsuranceContract')); + } + + /** + * @dataProvider requestDataProviderRightParams + * @param string $insuranceContractExternalId + * @param string $cmsReference + * @param int $productPrice + * @return void + * @throws MissingKeyException + * @throws ParametersException + * @throws RequestException + * @throws RequestError + */ + public function testGetRequestIsCalled($insuranceContractExternalId, $cmsReference, $productPrice) + { + + $this->responseMock->shouldReceive('isError')->once()->andReturn(false); + $this->requestObject->shouldReceive('get')->once()->andReturn($this->responseMock); + $this->requestObject->shouldReceive('setQueryParams')->once()->andReturn($this->requestObject); + $this->insuranceMock->shouldReceive('request') + ->with(self::INSURANCE_CONTRACTS_PATH . $insuranceContractExternalId) + ->once() + ->andReturn($this->requestObject); + $this->insuranceMock->shouldReceive('checkParameters') + ->once() + ->with($cmsReference, $insuranceContractExternalId, $productPrice); + + $this->insuranceMock->getInsuranceContract($insuranceContractExternalId, $cmsReference, $productPrice); + } + + /** + * @dataProvider requestDataProvider + * @param string $insuranceContractExternalId + * @param string $cmsReference + * @param int $productPrice + * @return void + * @throws MissingKeyException + * @throws ParametersException + * @throws RequestError + * @throws RequestException + */ + public function testThrowParametersExceptionWithWrongParams($insuranceContractExternalId, $cmsReference, $productPrice) + { + $this->requestObject->shouldNotReceive('get'); + $this->insuranceMock->shouldNotReceive('request'); + + $this->insuranceMock->shouldReceive('checkParameters')->once()->andThrow(ParametersException::class); + $this->expectException(ParametersException::class); + $this->insuranceMock->getInsuranceContract($insuranceContractExternalId, $cmsReference, $productPrice); + } + + /** + * @return void + * @throws MissingKeyException + * @throws ParametersException + * @throws RequestError + * @throws RequestException + */ + public function testApiResponseErrorThrowRequestException() + { + $insuranceContractExternalId = 'insurance_contract_6XxGHbjr51CE5Oly8E2Amx'; + $cmsReference = '18-24'; + $productPrice = 10000; + $this->responseMock->shouldReceive('isError')->once()->andReturn(true); + + $requestObject = Mockery::mock(Request::class)->shouldAllowMockingProtectedMethods(); + $requestObject->shouldReceive('get')->once()->andReturn($this->responseMock); + $requestObject->shouldReceive('setQueryParams')->once()->andReturn($requestObject); + + + $this->insuranceMock->shouldReceive('request') + ->with(self::INSURANCE_CONTRACTS_PATH . $insuranceContractExternalId) + ->once() + ->andReturn($requestObject); + + $this->insuranceMock->setClientContext($this->clientContext); + $this->insuranceMock->shouldReceive('checkParameters')->once(); + $this->expectException(RequestException::class); + $this->insuranceMock->getInsuranceContract($insuranceContractExternalId, $cmsReference, $productPrice); + } + + /** + * @dataProvider requestDataProviderRightParams + * @param string $insuranceContractExternalId + * @param string $cmsReference + * @param int $productPrice + * @return void + * @throws MissingKeyException + * @throws ParametersException + * @throws RequestError + * @throws RequestException + */ + public function testApiResponseInsuranceContract($insuranceContractExternalId, $cmsReference, $productPrice) + { + $files = [ + new File('Alma mobility 1 an (vol+casse+assistance) - Alma}', 'ipid-document', 'https://object-storage-s3-staging.s3.fr-par.scw.cloud/contracts/43acb66c-4b24-42d2-864a-24b4ade33e81/I6LK9O3XUNKNZPDTMH58IIK2HKBMRM2MIH-V0YGPECCD5Z20YIQUKXVCZYEU_TJD.pdf/OFXRU1UHY7J0CFO7X0Y24RSDMTG-W5BVB1GZRPPZFPSJRNIGGP2HXR2CEXIPBWZ-.pdf'), + new File('Alma mobility 1 an (vol+casse+assistance) - Alma}', 'fic-document', 'https://object-storage-s3-staging.s3.fr-par.scw.cloud/contracts/43acb66c-4b24-42d2-864a-24b4ade33e81/Y-PSWZG6-ADZ9MEY8PAZS2TMAUBXOLU6GYOLDWULMEAJB_VW0RGBKJTPMY7SPASN.pdf/UHSB9KVIGRLHP9DMXRZNCSWUGXCHS9VOW2EHAUNCYM_ANJIE7DOAKVLIH6EEOQYW.pdf'), + new File('Alma mobility 1 an (vol+casse+assistance) - Alma}', 'notice-document', 'https://object-storage-s3-staging.s3.fr-par.scw.cloud/contracts/43acb66c-4b24-42d2-864a-24b4ade33e81/JVPHA9RROHB6RPCG9K3VFG4EELBIMALK4QY2JVYEUTBFFT4SP1YN_ZUFXHOYRUSP.pdf/YTBTRJ6C9FFQFNW3234PHJJJT28VZR0FDOXVV0HV1SULI79S3UPSYRX7SZDNX1FX.pdf') + ]; + $contractExpected = new Contract( + "insurance_contract_6XxGHbjr51CE5Oly8E2Amx", + "Alma outillage thermique 3 ans (Vol + casse)", + 1095, + null, + null, + null, + null, + null, + 500, + $files + ); + $json = '{ + "id": "insurance_contract_6XxGHbjr51CE5Oly8E2Amx", + "name": "Alma outillage thermique 3 ans (Vol + casse)", + "protection_days": 1095, + "description": null, + "cover_area": null, + "compensation_area": null, + "exclusion_area": null, + "uncovered_area": null, + "price": 500, + "files": [ + { + "name": "Alma mobility 1 an (vol+casse+assistance) - Alma}", + "type": "ipid-document", + "public_url": "https://object-storage-s3-staging.s3.fr-par.scw.cloud/contracts/43acb66c-4b24-42d2-864a-24b4ade33e81/I6LK9O3XUNKNZPDTMH58IIK2HKBMRM2MIH-V0YGPECCD5Z20YIQUKXVCZYEU_TJD.pdf/OFXRU1UHY7J0CFO7X0Y24RSDMTG-W5BVB1GZRPPZFPSJRNIGGP2HXR2CEXIPBWZ-.pdf" + }, + { + "name": "Alma mobility 1 an (vol+casse+assistance) - Alma}", + "type": "fic-document", + "public_url": "https://object-storage-s3-staging.s3.fr-par.scw.cloud/contracts/43acb66c-4b24-42d2-864a-24b4ade33e81/Y-PSWZG6-ADZ9MEY8PAZS2TMAUBXOLU6GYOLDWULMEAJB_VW0RGBKJTPMY7SPASN.pdf/UHSB9KVIGRLHP9DMXRZNCSWUGXCHS9VOW2EHAUNCYM_ANJIE7DOAKVLIH6EEOQYW.pdf" + }, + { + "name": "Alma mobility 1 an (vol+casse+assistance) - Alma}", + "type": "notice-document", + "public_url": "https://object-storage-s3-staging.s3.fr-par.scw.cloud/contracts/43acb66c-4b24-42d2-864a-24b4ade33e81/JVPHA9RROHB6RPCG9K3VFG4EELBIMALK4QY2JVYEUTBFFT4SP1YN_ZUFXHOYRUSP.pdf/YTBTRJ6C9FFQFNW3234PHJJJT28VZR0FDOXVV0HV1SULI79S3UPSYRX7SZDNX1FX.pdf" + } + ] + }'; + + $this->responseMock->shouldReceive('isError')->once()->andReturn(false); + $this->responseMock->json = json_decode($json, true); + + $this->requestObject->shouldReceive('get')->once()->andReturn($this->responseMock); + $this->requestObject->shouldReceive('setQueryParams') + ->once() + ->andReturn($this->requestObject); + $this->insuranceMock->shouldReceive('request') + ->with(self::INSURANCE_CONTRACTS_PATH . $insuranceContractExternalId) + ->once() + ->andReturn($this->requestObject); + $this->insuranceMock->shouldReceive('checkParameters') + ->once() + ->with($cmsReference, $insuranceContractExternalId, $productPrice); + + $this->assertEquals( + $contractExpected, + $this->insuranceMock->getInsuranceContract($insuranceContractExternalId, $cmsReference, $productPrice) + ); + } + + /** + * @return void + */ + public function testInsuranceSubscriptionMethodExist() + { + $insurance = new Insurance($this->clientContext); + $this->assertTrue(method_exists($insurance, 'subscription')); + } + + /** + * @dataProvider nonArrayParamDataProvider + * @param $nonArrayParam + * @param $nonStringPaymentId + * @throws ParametersException + * @throws RequestError + * @throws RequestException + */ + public function testSubscriptionThrowExceptionIfNotArrayInParam($nonArrayParam, $nonStringPaymentId) + { + $insurance = new Insurance($this->clientContext); + $this->expectException(ParametersException::class); + $insurance->subscription($nonArrayParam, 'orderID', $nonStringPaymentId); + } + + /** + * @dataProvider subscriptionDataProvider + * @param $subscriptionArray + * @return void + * @throws ParametersException + * @throws RequestError + * @throws RequestException + */ + public function testSubscriptionThrowExceptionRequestError($subscriptionArray) + { + $this->responseMock->shouldReceive('isError')->once()->andReturn(true); + $this->responseMock->json = $subscriptionArray; + + $requestObject = Mockery::mock(Request::class); + $requestObject->shouldReceive('setRequestBody')->andReturn($requestObject); + $requestObject->shouldReceive('post')->once()->andReturn($this->responseMock); + + $insurance = Mockery::mock(Insurance::class)->shouldAllowMockingProtectedMethods()->makePartial(); + $insurance->shouldReceive('request') + ->with(self::INSURANCE_SUBSCRIPTIONS_PATH) + ->once() + ->andReturn($requestObject); + $insurance->setClientContext($this->clientContext); + $this->expectException(RequestException::class); + $insurance->subscription($subscriptionArray, 'orderId'); + } + + /** + * @dataProvider subscriptionDataProvider + * @param $subscriptionArray + * @param $paymentId + * @param $expectedSubscriptionPayload + * @throws ParametersException + * @throws RequestError + * @throws RequestException + */ + public function testSubscriptionGetRequestCall($subscriptionArray, $paymentId, $expectedSubscriptionPayload) + { + $expectedSubscriptionPayload['order_id'] = 'myOrderId'; + + if ($paymentId) { + $expectedSubscriptionPayload['payment_id'] = $paymentId; + } + $this->responseMock->shouldReceive('isError')->once()->andReturn(false); + $this->requestObject->shouldReceive('setRequestBody')->once() + ->with($expectedSubscriptionPayload) + ->andReturn($this->requestObject); + $this->requestObject->shouldReceive('post')->once()->andReturn($this->responseMock); + + $insurance = Mockery::mock(Insurance::class)->shouldAllowMockingProtectedMethods()->makePartial(); + $insurance->shouldReceive('request') + ->with(self::INSURANCE_SUBSCRIPTIONS_PATH) + ->once() + ->andReturn($this->requestObject); + $insurance->setClientContext($this->clientContext); + $insurance->subscription($subscriptionArray, 'myOrderId', $paymentId); + } + + /** + * @return void + */ + public function testSubscriptionMethodExist() + { + $insurance = new Insurance($this->clientContext); + $this->assertTrue(method_exists($insurance, 'getSubscription')); + } + + /** + * @dataProvider getSubscriptionsRightParamDataProvider + * @throws ParametersException + * @throws RequestError + * @throws RequestException + * @throws ResponseException + */ + public function testGetSubscriptionRequestIsCalled($subscriptionIds, $json) + { + $this->responseMock->json = json_decode($json, true); + $this->responseMock->shouldReceive('isError')->once()->andReturn(false); + $this->requestObject->shouldReceive('get')->once()->andReturn($this->responseMock); + $this->requestObject->shouldReceive('setQueryParams') + ->once() + ->with($subscriptionIds) + ->andReturn($this->requestObject); + $this->insuranceMock->shouldReceive('request') + ->with(self::INSURANCE_SUBSCRIPTIONS_PATH) + ->once() + ->andReturn($this->requestObject); + + $this->insuranceValidatorMock->shouldReceive('checkSubscriptionIds')->once(); + $this->insuranceMock->getSubscription($subscriptionIds); + } + + /** + * @dataProvider getSubscriptionsRightParamDataProvider + * @param $subscriptionIds + * @throws ParametersException + * @throws RequestError + * @throws RequestException + * @throws ResponseException + */ + public function testGetSubscriptionThrowExceptionIfResponseHasAnError($subscriptionIds) + { + $this->responseMock->shouldReceive('isError')->once()->andReturn(true); + $this->requestObject->shouldReceive('setQueryParams')->once()->andReturn($this->requestObject); + $this->requestObject->shouldReceive('get')->once()->andReturn($this->responseMock); + $this->insuranceMock->shouldReceive('request') + ->with(self::INSURANCE_SUBSCRIPTIONS_PATH) + ->once() + ->andReturn($this->requestObject); + + $this->insuranceValidatorMock->shouldReceive('checkSubscriptionIds') + ->once() + ->with($subscriptionIds); + + $this->expectException(RequestException::class); + $this->insuranceMock->getSubscription($subscriptionIds); + } + + /** + * @dataProvider nonArrayParamGetSubscriptionDataProvider + * @param $subscriptionIds + * @throws ParametersException + * @throws RequestError + * @throws RequestException + * @throws ResponseException + */ + public function testGetSubscriptionThrowExceptionIfWeDontSendAnArray($subscriptionIds) + { + $this->insuranceValidatorMock->shouldReceive('checkSubscriptionIds') + ->once() + ->with($subscriptionIds) + ->andThrow(ParametersException::class); + $this->expectException(ParametersException::class); + $this->insuranceMock->getSubscription($subscriptionIds); + } + + /** + * @dataProvider getSubscriptionsRightParamDataProvider + * @param $subscriptionIds + * @param $json + * @return void + * @throws ParametersException + * @throws RequestError + * @throws RequestException + */ + public function testGetSubscriptionsReturnApiResponse($subscriptionIds, $json) + { + $this->responseMock->json = json_decode($json, true); + $this->responseMock->shouldReceive('isError')->once()->andReturn(false); + $this->requestObject->shouldReceive('get')->once()->andReturn($this->responseMock); + $this->requestObject->shouldReceive('setQueryParams')->once()->andReturn($this->requestObject); + $this->insuranceMock->shouldReceive('request') + ->with(self::INSURANCE_SUBSCRIPTIONS_PATH) + ->once() + ->andReturn($this->requestObject); + $this->insuranceValidatorMock->shouldReceive('checkSubscriptionIds')->once(); + + $this->assertEquals($this->responseMock->json, $this->insuranceMock->getSubscription($subscriptionIds)); + } + + /** + * @return void + * @throws RequestError + */ + public function testGivenInvalidCmsReferenceArrayNoCallEndpointAndReturnFalse() + { + $this->insuranceValidatorMock->shouldReceive('checkCmsReference') + ->once() + ->andThrow(ParametersException::class); + $loggerMock = Mockery::mock(LoggerInterface::class); + $loggerMock->shouldReceive('error')->once(); + $this->clientContext->logger = $loggerMock; + $this->insuranceMock->setClientContext($this->clientContext); + $this->assertNull($this->insuranceMock->sendCustomerCart(['123', '456'], 42)); + } + + /** + * @return void + * @throws ParametersException + * @throws RequestError + * @throws RequestException + */ + public function testCancelSubscriptionCallRequestWithSubscriptionArrayPayloadAndNoThrowExceptionForResponse200() + { + $subscriptionCancelPayload = ' subscriptionId1 '; + $this->responseMock->shouldReceive('isError')->once()->andReturn(false); + $this->requestObject->shouldReceive('post')->once()->andReturn($this->responseMock); + $this->insuranceMock->shouldReceive('request') + ->with(self::INSURANCE_SUBSCRIPTIONS_PATH . '/subscriptionId1/void') + ->once() + ->andReturn($this->requestObject); + $this->insuranceMock->cancelSubscription($subscriptionCancelPayload); + } + + /** + * @return void + * @throws RequestError + */ + public function testSendCustomerCartCallApiPostCustomerCartWithCmsReferencesArray() + { + $cartId = 42; + $this->insuranceValidatorMock->shouldReceive('checkCmsReference') + ->once(); + $this->requestObject->shouldReceive('setRequestBody')->once()->with( + [ + 'cms_references' => ['123', '456'] + ] + )->andReturn($this->requestObject); + $this->insuranceMock->shouldReceive('request') + ->with(self::INSURANCE_CUSTOMER_CART_PATH) + ->once() + ->andReturn($this->requestObject); + $this->insuranceMock->shouldReceive('addCustomerSessionToRequest')->once()->with( + $this->requestObject, + null, + $cartId + ); + $this->requestObject->shouldReceive('post')->once(); + $this->assertNull($this->insuranceMock->sendCustomerCart(['123', '456'], $cartId)); + } + + /** + * @return void + * @throws InsuranceCancelPendingException + * @throws ParametersException + * @throws RequestError + * @throws RequestException + */ + public function testCancelSubscriptionCallRequestWithSubscriptionArrayPayloadAndThrowExceptionForResponseUpperThan400ButNo410() + { + $this->expectException(RequestException::class); + $subscriptionCancelPayload = 'subscriptionId1'; + + $this->responseMock->shouldReceive('isError')->once()->andReturn(true); + $this->requestObject->shouldReceive('post')->once()->andReturn($this->responseMock); + $this->insuranceMock->shouldReceive('request') + ->with(self::INSURANCE_SUBSCRIPTIONS_PATH . '/subscriptionId1/void') + ->once() + ->andReturn($this->requestObject); + $this->insuranceMock->cancelSubscription($subscriptionCancelPayload); + } + + /** + * @return void + * @throws InsuranceCancelPendingException + * @throws ParametersException + * @throws RequestError + * @throws RequestException + */ + public function testCancelSubscriptionCallRequestWithSubscriptionArrayPayloadAndThrowInsuranceCancelPendingExceptionForResponse410() + { + $this->expectException(InsuranceCancelPendingException::class); + $subscriptionCancelPayload = 'subscriptionId1'; + $this->responseMock->responseCode = 410; + $this->requestObject->shouldReceive('post')->once()->andReturn($this->responseMock); + $this->insuranceMock->shouldReceive('request') + ->with(self::INSURANCE_SUBSCRIPTIONS_PATH . '/subscriptionId1/void') + ->once() + ->andReturn($this->requestObject); + $this->insuranceMock->cancelSubscription($subscriptionCancelPayload); + } + + /** + * @dataProvider cancelSubscriptionErrorPayloadDataProvider + * @param $subscriptionIdsArray + * @return void + * @throws ParametersException + */ + public function testCheckSubscriptionIdFormatThrowParamsErrorForBadPayload($subscriptionIdsArray) + { + $this->expectException(ParametersException::class); + $this->insuranceMock->checkSubscriptionIdFormat($subscriptionIdsArray); + } + + + /** + * @dataProvider subscriptionIdInvalidDataProvider + * @param $subscriptionIdInvalid + * @param $jsonReturnRequest + * @return void + * @throws ParametersException + * @throws RequestError + * @throws RequestException + */ + public function testGetSubscriptionIfReturnZeroDataThrowException($subscriptionIdInvalid, $jsonReturnRequest) + { + $this->responseMock->json = json_decode($jsonReturnRequest, true); + $this->responseMock->shouldReceive('isError')->once()->andReturn(false); + $this->requestObject->shouldReceive('setQueryParams')->once()->andReturn($this->requestObject); + $this->requestObject->shouldReceive('get')->once()->andReturn($this->responseMock); + $this->insuranceMock->shouldReceive('request') + ->with(self::INSURANCE_SUBSCRIPTIONS_PATH) + ->once() + ->andReturn($this->requestObject); + + $this->insuranceValidatorMock->shouldReceive('checkSubscriptionIds') + ->once() + ->with($subscriptionIdInvalid); + + $this->expectException(ResponseException::class); + $this->insuranceMock->getSubscription($subscriptionIdInvalid); + } +} diff --git a/tests/Unit/Legacy/Endpoints/OrdersTest.php b/tests/Unit/Endpoints/OrdersTest.php similarity index 79% rename from tests/Unit/Legacy/Endpoints/OrdersTest.php rename to tests/Unit/Endpoints/OrdersTest.php index 636313c6..3383df4a 100644 --- a/tests/Unit/Legacy/Endpoints/OrdersTest.php +++ b/tests/Unit/Endpoints/OrdersTest.php @@ -1,6 +1,6 @@ clientContext = \Mockery::mock(ClientContext::class); - $this->orderEndpoint = \Mockery::mock(Orders::class)->makePartial(); - $this->arrayUtils = \Mockery::mock(ArrayUtils::class)->makePartial(); - $this->responseMock = \Mockery::mock(Response::class); - $this->requestObject = \Mockery::mock(Request::class); - $loggerMock = \Mockery::mock(LoggerInterface::class); + $this->clientContext = Mockery::mock(ClientContext::class); + $this->orderEndpoint = Mockery::mock(Orders::class)->makePartial(); + $this->arrayUtils = Mockery::mock(ArrayUtils::class)->makePartial(); + $this->responseMock = Mockery::mock(Response::class); + $this->responseMock->errorMessage = 'Exception Error message'; + $this->requestObject = Mockery::mock(Request::class); + $loggerMock = Mockery::mock(LoggerInterface::class); $loggerMock->shouldReceive('error'); $this->orderEndpoint->arrayUtils = $this->arrayUtils; @@ -40,6 +42,16 @@ public function setUp() $this->orderEndpoint->setClientContext($this->clientContext); } + + public function tearDown(): void + { + $this->orderEndpoint = null; + $this->arrayUtils = null; + $this->responseMock = null; + $this->requestObject = null; + Mockery::close(); + } + public function testValidateStatusDataNoOrderData() { $this->expectException(ParametersException::class); @@ -49,8 +61,8 @@ public function testValidateStatusDataNoOrderData() public function testValidateStatusDataMissingSomeOrderData() { - $orderEndpoint = \Mockery::mock(Orders::class)->makePartial(); - $arrayUtils = \Mockery::mock(ArrayUtils::class)->makePartial(); + $orderEndpoint = Mockery::mock(Orders::class)->makePartial(); + $arrayUtils = Mockery::mock(ArrayUtils::class)->makePartial(); $arrayUtils->shouldReceive('checkMandatoryKeys')->andThrow(new MissingKeyException()); $orderEndpoint->arrayUtils = $arrayUtils; @@ -61,8 +73,8 @@ public function testValidateStatusDataMissingSomeOrderData() public function testValidateStatusDataIsShippedNotBool() { - $orderEndpoint = \Mockery::mock(Orders::class)->makePartial(); - $arrayUtils = \Mockery::mock(ArrayUtils::class)->makePartial(); + $orderEndpoint = Mockery::mock(Orders::class)->makePartial(); + $arrayUtils = Mockery::mock(ArrayUtils::class)->makePartial(); $arrayUtils->shouldReceive('checkMandatoryKeys')->andReturn(null); $orderEndpoint->arrayUtils = $arrayUtils; @@ -77,8 +89,8 @@ public function testValidateStatusDataIsShippedNotBool() public function testValidateStatusDataStatusIsEmpty() { - $orderEndpoint = \Mockery::mock(Orders::class)->makePartial(); - $arrayUtils = \Mockery::mock(ArrayUtils::class)->makePartial(); + $orderEndpoint = Mockery::mock(Orders::class)->makePartial(); + $arrayUtils = Mockery::mock(ArrayUtils::class)->makePartial(); $arrayUtils->shouldReceive('checkMandatoryKeys')->andReturn(null); $orderEndpoint->arrayUtils = $arrayUtils; @@ -91,7 +103,7 @@ public function testValidateStatusDataStatusIsEmpty() )); } - public function testSendStatusOK() + public function testSendStatusOk() { $this->orderEndpoint->shouldReceive('validateStatusData')->andReturn(null); @@ -134,7 +146,7 @@ public function testSendStatusWithException() { $this->orderEndpoint->shouldReceive('validateStatusData')->andReturn(null); - $this->responseMock->shouldReceive('isError')->once()->andReturn(false); + $this->responseMock->shouldReceive('isError')->never(); $this->requestObject->shouldReceive('setRequestBody')->andReturn($this->requestObject); $this->requestObject->shouldReceive('post')->andThrow(new RequestException()); @@ -151,12 +163,4 @@ public function testSendStatusWithException() } - public function tearDown() - { - $this->orderEndpoint = null; - $this->arrayUtils = null; - $this->responseMock = null; - $this->requestObject = null; - } - } diff --git a/tests/Unit/Legacy/Endpoints/PaymentsTest.php b/tests/Unit/Endpoints/PaymentsTest.php similarity index 55% rename from tests/Unit/Legacy/Endpoints/PaymentsTest.php rename to tests/Unit/Endpoints/PaymentsTest.php index faccbb42..0e64a646 100644 --- a/tests/Unit/Legacy/Endpoints/PaymentsTest.php +++ b/tests/Unit/Endpoints/PaymentsTest.php @@ -1,6 +1,6 @@ assertEquals(true, method_exists($payments, 'partialRefund')); - $this->assertEquals(true, method_exists($payments, 'fullRefund')); - # ensure backward compatibility - $this->assertEquals(true, method_exists($payments, 'refund')); - } - - /** - * Mock ClientContext, Response and Request to allow us to test - * Payment without sending any requests - */ - private function mockServerRequest() - { - // ClientContext - $clientContext = Mockery::mock(ClientContext::class); - $clientContext->shouldReceive('urlFor'); - $clientContext->shouldReceive('getUserAgentString'); - $clientContext->shouldReceive('forcedTLSVersion'); - - // Response - $json = '{ + const SERVER_REQUEST_ERROR_RESPONSE_JON = '{ "payment_plan":[ { "customer_can_postpone":false, @@ -109,6 +80,128 @@ private function mockServerRequest() ] }'; + public function tearDown(): void + { + Mockery::close(); + } + + /** + * Return input to test testPartialRefund + * @return array[] + */ + public static function getPartialRefundData() + { + return [ + [[ + 'id' => "some_id", + 'amount' => 15000, + 'merchant_ref' => self::MERCHANT_REF, + 'comment' => "some comment" + ]], + [[ + 'id' => "some_id", + 'amount' => 15000, + 'merchant_ref' => self::MERCHANT_REF + ]], + [[ + 'id' => "some_id", + 'amount' => 15000 + ]] + ]; + } + + /** + * Return invalid input to test testPartialRefund + * @return array[] + */ + public static function getPartialRefundInvalidData() + { + return [ + [[ + 'id' => "negative_amount", + 'amount' => -1 + ], ParametersException::class], + [[ + 'id' => "", + 'amount' => 1500, + 'merchant_ref' => "no id", + ], ParametersException::class], + ]; + } + + /** + * Return input to test testFullRefund + * @return array[] + */ + public static function getFullRefundData() + { + return [ + [[ + 'id' => "some_id", + 'merchant_ref' => self::MERCHANT_REF, + 'comment' => "some comment" + ]], + [[ + 'id' => "some_id", + 'merchant_ref' => self::MERCHANT_REF + ]], + [[ + 'id' => "some_id", + ]] + ]; + } + + /** + * Return input to test testRefund + * @return array[] + */ + public static function getRefundData() + { + return [ + [[ + 'id' => "some_id", + 'amount' => 15000, + 'merchant_ref' => self::MERCHANT_REF, + ]], + [[ + 'id' => "some_id", + ]], + [[ + 'id' => "some_id", + 'amount' => 15000 + ]] + ]; + } + + /** + * Return invalid input to test testFullRefund + * @return array[] + */ + public static function getFullRefundInvalidData() + { + return [ + [[ + 'id' => "", + 'merchant_ref' => "no id", + ], ParametersException::class], + ]; + } + + /** + * Mock ClientContext, Response and Request to allow us to test + * Payment without sending any requests + */ + private function mockServerRequest() + { + // ClientContext + $clientContext = Mockery::mock(ClientContext::class); + $clientContext->shouldReceive('urlFor'); + $clientContext->shouldReceive('getUserAgentString'); + $clientContext->shouldReceive('forcedTLSVersion'); + + // Response + $json = self::SERVER_REQUEST_ERROR_RESPONSE_JON; + $responseMock = Mockery::mock(Response::class); $responseMock->shouldReceive('isError')->andReturn(false); $responseMock->json = json_decode($json, true); @@ -120,31 +213,6 @@ private function mockServerRequest() return $requestMock; } - /** - * Return input to test testPartialRefund - * @return array[] - */ - public function getPartialRefundData() - { - return [ - [[ - 'id' => "some_id", - 'amount' => 15000, - 'merchant_ref' => self::MERCHANT_REF, - 'comment' => "some comment" - ]], - [[ - 'id' => "some_id", - 'amount' => 15000, - 'merchant_ref' => self::MERCHANT_REF - ]], - [[ - 'id' => "some_id", - 'amount' => 15000 - ]] - ]; - } - /** * @param Payments $payments * @param $data @@ -164,11 +232,77 @@ private function callPartialRefund($payments, $data) } } + private function callFullRefund($payments, $data) + { + if (isset($data['merchant_ref']) && isset($data['comment'])) { + $payments->fullRefund($data['id'], $data['merchant_ref'], $data['comment']); + } elseif (isset($data['merchant_ref'])) { + $payments->fullRefund($data['id'], $data['merchant_ref']); + } elseif (isset($data['comment'])) { + $payments->fullRefund($data['id'], '', $data['comment']); + } else { + $payments->fullRefund($data['id']); + } + } + + private function callRefund($payments, $data) + { + if (isset($data['merchant_ref']) && isset($data['amount'])) { + $payments->refund($data['id'], $data['amount'], $data['merchant_ref']); + } elseif (isset($data['amount'])) { + $payments->refund($data['id'], $data['amount']); + } else { + $payments->refund($data['id']); + } + } + + /** + * Mock ClientContext, Response and Request to allow us to test + * Payment without sending any requests but returns an error + */ + private function mockServerRequestError() + { + // ClientContext + $clientContext = Mockery::mock(ClientContext::class); + $clientContext->shouldReceive('urlFor'); + $clientContext->shouldReceive('getUserAgentString'); + $clientContext->shouldReceive('forcedTLSVersion'); + + // Response + $json = self::SERVER_REQUEST_ERROR_RESPONSE_JON; + + $responseMock = Mockery::mock(Response::class); + $responseMock->shouldReceive('isError')->andReturn(true); + $responseMock->json = json_decode($json, true); + $responseMock->errorMessage = "a very important error message"; + + // Request + $requestMock = Mockery::mock(Request::class); + $requestMock->shouldReceive('setRequestBody'); + $requestMock->shouldReceive('post')->andReturn($responseMock); + return $requestMock; + } + + /** + * Ensure that the methods exists + */ + public function testRefundMethodExist() + { + $clientContext = Mockery::mock(ClientContext::class); + + $payments = new Payments($clientContext); + + $this->assertEquals(true, method_exists($payments, 'partialRefund')); + $this->assertEquals(true, method_exists($payments, 'fullRefund')); + # ensure backward compatibility + $this->assertEquals(true, method_exists($payments, 'refund')); + } + /** * Test the partialRefund method with valid datas * @dataProvider getPartialRefundData * @param $data - * @return voi + * @return void * @throws RequestException */ public function testPartialRefund($data) @@ -192,25 +326,6 @@ public function testPartialRefund($data) $this->callPartialRefund($payments, $data); } - /** - * Return invalid input to test testPartialRefund - * @return array[] - */ - public function getPartialRefundInvalidData() - { - return [ - [[ - 'id' => "negative_amount", - 'amount' => -1 - ], ParametersException::class], - [[ - 'id' => "", - 'amount' => 1500, - 'merchant_ref' => "no id", - ], ParametersException::class], - ]; - } - /** * Test the partialRefund method with valid datas * @dataProvider getPartialRefundInvalidData @@ -241,42 +356,6 @@ public function testInvalidPartialRefund($data, $expectedException) $this->callPartialRefund($payments, $data); } - - private function callFullRefund($payments, $data) - { - if (isset($data['merchant_ref']) && isset($data['comment'])) { - $payments->fullRefund($data['id'], $data['merchant_ref'], $data['comment']); - } elseif (isset($data['merchant_ref'])) { - $payments->fullRefund($data['id'], $data['merchant_ref']); - } elseif (isset($data['comment'])) { - $payments->fullRefund($data['id'], '', $data['comment']); - } else { - $payments->fullRefund($data['id']); - } - } - - /** - * Return input to test testFullRefund - * @return array[] - */ - public function getFullRefundData() - { - return [ - [[ - 'id' => "some_id", - 'merchant_ref' => self::MERCHANT_REF, - 'comment' => "some comment" - ]], - [[ - 'id' => "some_id", - 'merchant_ref' => self::MERCHANT_REF - ]], - [[ - 'id' => "some_id", - ]] - ]; - } - /** * Test the fullRefund method with valid datas * @dataProvider getFullRefundData @@ -303,39 +382,6 @@ public function testFullRefund($data) $this->callFullRefund($payments, $data); } - /** - * Return input to test testRefund - * @return array[] - */ - public function getRefundData() - { - return [ - [[ - 'id' => "some_id", - 'amount' => 15000, - 'merchant_ref' => self::MERCHANT_REF, - ]], - [[ - 'id' => "some_id", - ]], - [[ - 'id' => "some_id", - 'amount' => 15000 - ]] - ]; - } - - private function callRefund($payments, $data) - { - if (isset($data['merchant_ref']) && isset($data['amount'])) { - $payments->refund($data['id'], $data['amount'], $data['merchant_ref']); - } elseif (isset($data['amount'])) { - $payments->refund($data['id'], $data['amount']); - } else { - $payments->refund($data['id']); - } - } - /** * Test the fullRefund method with valid datas * Important to ensure we didn't break compatibility with 1.x.x versions @@ -363,20 +409,6 @@ public function testRefund($data) $this->callRefund($payments, $data); } - /** - * Return invalid input to test testFullRefund - * @return array[] - */ - public function getFullRefundInvalidData() - { - return [ - [[ - 'id' => "", - 'merchant_ref' => "no id", - ], ParametersException::class], - ]; - } - /** * Test the fullRefund method with valid datas * @dataProvider getFullRefundInvalidData @@ -404,93 +436,6 @@ public function testInvalidFullRefund($data, $expectedException) $this->callFullRefund($payments, $data); } - /** - * Mock ClientContext, Response and Request to allow us to test - * Payment without sending any requests but returns an error - */ - private function mockServerRequestError() - { - // ClientContext - $clientContext = Mockery::mock(ClientContext::class); - $clientContext->shouldReceive('urlFor'); - $clientContext->shouldReceive('getUserAgentString'); - $clientContext->shouldReceive('forcedTLSVersion'); - - // Response - $json = '{ - "payment_plan":[ - { - "customer_can_postpone":false, - "customer_fee":100, - "customer_interest":0, - "date_paid":1649672472, - "due_date":1649672451, - "id":"installment_11uPRjPgPJ5jxmEEXxIPPOvVA3Fh7cg13m", - "original_purchase_amount":11733, - "purchase_amount":11733, - "state":"paid" - }, - { - "customer_can_postpone":false, - "customer_fee":0, - "customer_interest":0, - "date_paid":null, - "due_date":1652264451, - "id":"installment_11uPRjP4a3cFQvoM1lehDnpxa2tYm2Hy0I", - "original_purchase_amount":11733, - "purchase_amount":0, - "state":"paid" - }, - { - "customer_can_postpone":false, - "customer_fee":0, - "customer_interest":0, - "date_paid":null, - "due_date":1654942851, - "id":"installment_11uPRjP79fG5QtHO54lSYsnDvyHb56oeCn", - "original_purchase_amount":11733, - "purchase_amount":0, - "state":"paid" - } - ], - "orders":[ - { - "comment":null, - "created":1649672451, - "customer_url":null, - "data":{}, - "id":"order_11uPRjP4L9Dgbttx3cFUKGFPppdZIlrR2V", - "merchant_reference":"00000206", - "merchant_url":null, - "payment":"payment_11uPRjP5FaIYygQao8WdMQFnKRMOV14frx" - } - ], - "refunds":[ - { - "amount":35299, - "created":1649770695, - "from_payment_cancellation":false, - "id":"refund_11uPrHz4TfHmQrD1OkYyWb4hPuq3673Vqm", - "merchant_reference":null, - "payment":"payment_11uPRjP5FaIYygQao8WdMQFnKRMOV14frx", - "payment_refund_amount":11833, - "rebate_amount":23466 - } - ] - }'; - - $responseMock = Mockery::mock(Response::class); - $responseMock->shouldReceive('isError')->andReturn(true); - $responseMock->json = json_decode($json, true); - $responseMock->errorMessage = "a very important error message"; - - // Request - $requestMock = Mockery::mock(Request::class); - $requestMock->shouldReceive('setRequestBody'); - $requestMock->shouldReceive('post')->andReturn($responseMock); - return $requestMock; - } - public function testFullRefundRequestError() { // Input diff --git a/tests/Unit/Entities/Insurance/ContractTest.php b/tests/Unit/Entities/Insurance/ContractTest.php new file mode 100644 index 00000000..b5c49c1d --- /dev/null +++ b/tests/Unit/Entities/Insurance/ContractTest.php @@ -0,0 +1,287 @@ +contractData = $this->getContractData(); + $this->contract = $this->createNewContract($this->contractData); + + } + + /** + * @return void + */ + public function testConstructObject() + { + $this->assertSame(Contract::class, get_class($this->contract)); + } + + /** + * @return void + */ + public function testGetIdReturnId() + { + $this->assertEquals($this->contract->getId(), $this->contractData['id']); + } + + /** + * @return void + */ + public function testGetReturnName() + { + $this->assertEquals($this->contract->getName(), $this->contractData['name']); + } + + /** + * @return void + */ + public function testGetReturnProtectionDays() + { + $this->assertEquals($this->contract->getProtectionDays(), $this->contractData['protection_days']); + } + + /** + * @return void + */ + public function testGetReturnDescription() + { + $this->assertEquals($this->contract->getDescription(), $this->contractData['description']); + } + + /** + * @return void + */ + public function testGetReturnCoverArea() + { + $this->assertEquals($this->contract->getCoverArea(), $this->contractData['cover_area']); + } + + /** + * @return void + */ + public function testGetReturnCompensationArea() + { + $this->assertEquals($this->contract->getCompensationArea(), $this->contractData['compensation_area']); + } + + /** + * @return void + */ + public function testGetReturnExclusionArea() + { + $this->assertEquals($this->contract->getExclusionArea(), $this->contractData['exclusion_area']); + } + + /** + * @return void + */ + public function testGetReturnUncoveredArea() + { + $this->assertEquals($this->contract->getUncoveredArea(), $this->contractData['uncovered_area']); + } + + /** + * @return void + */ + public function testGetReturnPrice() + { + $this->assertEquals($this->contract->getPrice(), $this->contractData['price']); + } + + /** + * @return void + */ + public function testGetReturnFiles() + { + $this->assertEquals($this->contract->getFiles(), $this->contractData['files']); + } + + /** + * @dataProvider contractDataProvider + * @param int $days + * @param int $years + * @return void + */ + public function testGetProtectionDurationInYear($days, $years) + { + $contractData = $this->getContractData(); + $contractData['protection_days'] = $days; + $contract = $this->createNewContract($contractData); + $this->assertEquals($years, $contract->getProtectionDurationInYear()); + } + + /** + * @dataProvider fileDataProvider + * @param string $type + * @param File $file + * @return void + */ + public function testGetFileByTypeReturnType($type, $file) + { + $contractData = $this->getContractData(); + $contract = $this->createNewContract($contractData); + $this->assertEquals($file, $contract->getFileByType($type)); + } + + /** + * @return array[] + */ + public static function contractDataProvider() + { + return [ + 'duration less than 1 year' => [ + 'days' => 364, + 'years' => 0 + ], + 'duration 1 year' => [ + 'days' => 365, + 'years' => 1 + ], + 'duration 1 leap year' => [ + 'days' => 366, + 'years' => 1 + ], + 'duration 2 years' => [ + 'days' => 730, + 'years' => 2 + ], + 'duration 3 years' => [ + 'days' => 1095, + 'years' => 3 + ], + 'duration 3 years and 2 days' => [ + 'days' => 1097, + 'years' => 3 + ] + ]; + } + + /** + * @return array[] + */ + public static function fileDataProvider() + { + $ipidFileData = new File( + 'Alma mobility 1 an (vol+casse+assistance) - Alma}', + 'ipid-document', + 'https://object-storage-s3-staging.s3.fr-par.scw.cloud/contracts/43acb66c-4b24-42d2-864a-24b4ade33e81/I6LK9O3XUNKNZPDTMH58IIK2HKBMRM2MIH-V0YGPECCD5Z20YIQUKXVCZYEU_TJD.pdf/OFXRU1UHY7J0CFO7X0Y24RSDMTG-W5BVB1GZRPPZFPSJRNIGGP2HXR2CEXIPBWZ-.pdf' + ); + $ipidFile = new File($ipidFileData->getName(), $ipidFileData->getType(), $ipidFileData->getPublicUrl()); + $ficFileData = new File( + 'Alma mobility 1 an (vol+casse+assistance) - Alma}', + 'fic-document', + 'https://object-storage-s3-staging.s3.fr-par.scw.cloud/contracts/43acb66c-4b24-42d2-864a-24b4ade33e81/Y-PSWZG6-ADZ9MEY8PAZS2TMAUBXOLU6GYOLDWULMEAJB_VW0RGBKJTPMY7SPASN.pdf/UHSB9KVIGRLHP9DMXRZNCSWUGXCHS9VOW2EHAUNCYM_ANJIE7DOAKVLIH6EEOQYW.pdf' + ); + $ficFile = new File($ficFileData->getName(), $ficFileData->getType(), $ficFileData->getPublicUrl()); + $noticeFileData = new File( + 'Alma mobility 1 an (vol+casse+assistance) - Alma}', + 'notice-document', + 'https://object-storage-s3-staging.s3.fr-par.scw.cloud/contracts/43acb66c-4b24-42d2-864a-24b4ade33e81/JVPHA9RROHB6RPCG9K3VFG4EELBIMALK4QY2JVYEUTBFFT4SP1YN_ZUFXHOYRUSP.pdf/YTBTRJ6C9FFQFNW3234PHJJJT28VZR0FDOXVV0HV1SULI79S3UPSYRX7SZDNX1FX.pdf' + ); + $noticeFile = new File($noticeFileData->getName(), $noticeFileData->getType(), $noticeFileData->getPublicUrl()); + + return [ + 'type is ipid-document' => [ + 'type' => 'ipid-document', + 'file' => $ipidFile + ], + 'type is fic-document' => [ + 'type' => 'fic-document', + 'file' => $ficFile + ], + 'type is notice-document' => [ + 'type' => 'notice-document', + 'file' => $noticeFile + ], + 'type is wrong string' => [ + 'type' => 'unknown-document', + 'file' => null + ], + 'type is object' => [ + 'type' => new \stdClass(), + 'file' => null + ], + 'type is empty' => [ + 'type' => '', + 'file' => null + ], + ]; + } + + /** + * @param array $contractData + * @return Contract + */ + private function createNewContract($contractData) + { + return new Contract( + $contractData['id'], + $contractData['name'], + $contractData['protection_days'], + $contractData['description'], + $contractData['cover_area'], + $contractData['compensation_area'], + $contractData['exclusion_area'], + $contractData['uncovered_area'], + $contractData['price'], + $contractData['files'] + ); + } + + /** + * @return array + */ + private static function getContractData() + { + return [ + 'id' => 'insurance_contract_3eWqr58LexAqxUAlNVKWEf', + 'name' => 'Insurance contract Name', + 'protection_days' => 365, + 'description' => 'description_value', + 'cover_area' => 'cover_area_value', + 'compensation_area' => 'compensation_area_value', + 'exclusion_area' => 'exclusion_area_value', + 'uncovered_area' => 'uncovered_area_value', + 'price' => 6000, //price in cent + 'files' => [ + new File( + 'Alma mobility 1 an (vol+casse+assistance) - Alma}', + 'ipid-document', + 'https://object-storage-s3-staging.s3.fr-par.scw.cloud/contracts/43acb66c-4b24-42d2-864a-24b4ade33e81/I6LK9O3XUNKNZPDTMH58IIK2HKBMRM2MIH-V0YGPECCD5Z20YIQUKXVCZYEU_TJD.pdf/OFXRU1UHY7J0CFO7X0Y24RSDMTG-W5BVB1GZRPPZFPSJRNIGGP2HXR2CEXIPBWZ-.pdf' + ), + new File( + 'Alma mobility 1 an (vol+casse+assistance) - Alma}', + 'fic-document', + 'https://object-storage-s3-staging.s3.fr-par.scw.cloud/contracts/43acb66c-4b24-42d2-864a-24b4ade33e81/Y-PSWZG6-ADZ9MEY8PAZS2TMAUBXOLU6GYOLDWULMEAJB_VW0RGBKJTPMY7SPASN.pdf/UHSB9KVIGRLHP9DMXRZNCSWUGXCHS9VOW2EHAUNCYM_ANJIE7DOAKVLIH6EEOQYW.pdf' + ), + new File( + 'Alma mobility 1 an (vol+casse+assistance) - Alma}', + 'notice-document', + 'https://object-storage-s3-staging.s3.fr-par.scw.cloud/contracts/43acb66c-4b24-42d2-864a-24b4ade33e81/JVPHA9RROHB6RPCG9K3VFG4EELBIMALK4QY2JVYEUTBFFT4SP1YN_ZUFXHOYRUSP.pdf/YTBTRJ6C9FFQFNW3234PHJJJT28VZR0FDOXVV0HV1SULI79S3UPSYRX7SZDNX1FX.pdf' + ) + ] + ]; + } + +} diff --git a/tests/Unit/Legacy/Entities/Insurance/FileTest.php b/tests/Unit/Entities/Insurance/FileTest.php similarity index 95% rename from tests/Unit/Legacy/Entities/Insurance/FileTest.php rename to tests/Unit/Entities/Insurance/FileTest.php index 41bb09dc..965f78fb 100644 --- a/tests/Unit/Legacy/Entities/Insurance/FileTest.php +++ b/tests/Unit/Entities/Insurance/FileTest.php @@ -1,6 +1,6 @@ fileData = $this->getFileData(); $this->file = $this->createNewFile($this->fileData); diff --git a/tests/Unit/Legacy/Entities/Insurance/SubscriberTest.php b/tests/Unit/Entities/Insurance/SubscriberTest.php similarity index 96% rename from tests/Unit/Legacy/Entities/Insurance/SubscriberTest.php rename to tests/Unit/Entities/Insurance/SubscriberTest.php index e0b3776b..ba5734ff 100644 --- a/tests/Unit/Legacy/Entities/Insurance/SubscriberTest.php +++ b/tests/Unit/Entities/Insurance/SubscriberTest.php @@ -1,6 +1,6 @@ subscriber = $this->createNewSubscriber(); } diff --git a/tests/Unit/Legacy/Entities/Insurance/SubscriptionTest.php b/tests/Unit/Entities/Insurance/SubscriptionTest.php similarity index 95% rename from tests/Unit/Legacy/Entities/Insurance/SubscriptionTest.php rename to tests/Unit/Entities/Insurance/SubscriptionTest.php index 12d5cf6a..b23e14ee 100644 --- a/tests/Unit/Legacy/Entities/Insurance/SubscriptionTest.php +++ b/tests/Unit/Entities/Insurance/SubscriptionTest.php @@ -1,6 +1,6 @@ subscription = $this->createNewSubscription(); } diff --git a/tests/Unit/Legacy/ArrayUtilsTest.php b/tests/Unit/Legacy/ArrayUtilsTest.php deleted file mode 100644 index 1c57b528..00000000 --- a/tests/Unit/Legacy/ArrayUtilsTest.php +++ /dev/null @@ -1,36 +0,0 @@ - 'a', "1" => 'b', "2" => 'c'], false], - [["1" => 'a', "0" => 'b', "2" => 'c'], false], - [["a" => 'a', "b" => 'b', "c" => 'c'], true], - ]; - } - - /** - * @dataProvider getTestArrays - * @return void - */ - public function testIsAssocArray($testArray, $expectedResult) - { - $result = ArrayUtils::isAssocArray($testArray); - $this->assertEquals($expectedResult, $result); - } -} diff --git a/tests/Unit/Legacy/ClientContextTest.php b/tests/Unit/Legacy/ClientContextTest.php deleted file mode 100644 index 8fdcb191..00000000 --- a/tests/Unit/Legacy/ClientContextTest.php +++ /dev/null @@ -1,58 +0,0 @@ - [[ - 'api_root' => [ - Client::TEST_MODE => self::FAKE_API_URI, - Client::LIVE_MODE => self::FAKE_API_URI - ], - 'force_tls' => 0, - 'mode' => Client::TEST_MODE, - 'logger' => new NullLogger() - ]], - 'user_agent_component' => [[ - 'api_root' => [ - Client::TEST_MODE => self::FAKE_API_URI, - Client::LIVE_MODE => self::FAKE_API_URI - ], - 'force_tls' => 0, - 'mode' => Client::TEST_MODE, - 'logger' => new NullLogger(), - 'user_agent_component' => ['Magento' => '12.3'] - ]], - ]; - } - - /** - * @dataProvider getClientconfigOptions - * @return void - * @throws ParamsError - */ - public function testClientContext($options) - { - $context = new ClientContext("sk_fake_api_key", $options); - - $this->assertInstanceOf(ClientContext::class, $context); - } -} diff --git a/tests/Unit/Legacy/ClientOptionsValidatorTest.php b/tests/Unit/Legacy/ClientOptionsValidatorTest.php deleted file mode 100644 index 7e2926ca..00000000 --- a/tests/Unit/Legacy/ClientOptionsValidatorTest.php +++ /dev/null @@ -1,155 +0,0 @@ - [ - Client::TEST_MODE => Client::SANDBOX_API_URL, - Client::LIVE_MODE => Client::LIVE_API_URL - ], - 'force_tls' => 2, - 'mode' => Client::LIVE_MODE, - 'logger' => new NullLogger() - ] - ], - [ - [ - 'api_root' => [ - Client::TEST_MODE => self::FAKE_API_URI, - Client::LIVE_MODE => self::FAKE_API_URI - ], - 'force_tls' => 0, - 'mode' => Client::TEST_MODE, - 'logger' => new NullLogger() - ], - [ - 'api_root' => [ - Client::TEST_MODE => self::FAKE_API_URI, - Client::LIVE_MODE => self::FAKE_API_URI - ], - 'force_tls' => 0, - 'mode' => Client::TEST_MODE, - 'logger' => new NullLogger() - ] - ], - [ - [ - 'api_root' => self::FAKE_API_URI, - 'force_tls' => true, - 'logger' => new NullLogger() - ], - [ - 'api_root' => [ - Client::TEST_MODE => self::FAKE_API_URI, - Client::LIVE_MODE => self::FAKE_API_URI - ], - 'force_tls' => 2, - 'mode' => Client::LIVE_MODE, - 'logger' => new NullLogger() - ] - ], - [ - [ - 'user_agent_component' => [ - 'PrestaShop' => 2.3, - 'Alma for PrestaShop' => 'v2.3', - ] - ], - [ - 'api_root' => [ - Client::TEST_MODE => Client::SANDBOX_API_URL, - Client::LIVE_MODE => Client::LIVE_API_URL - ], - 'force_tls' => 2, - 'mode' => Client::LIVE_MODE, - 'logger' => new NullLogger(), - 'user_agent_component' => [ - 'PrestaShop' => 2.3, - 'Alma for PrestaShop' => 'v2.3', - ] - ] - ] - ]; - } - - /** - * @dataProvider getClientOptions - * @return void - * @throws ParamsError - */ - public function testClientOptionsValidator($options, $expectedResult) - { - $validatedConfig = ClientOptionsValidator::validateOptions($options); - - $this->assertEquals($expectedResult, $validatedConfig); - } - - /** - * Return faulty options to test ClientOptionsValidator::validateOptions - * @return array - */ - public function getInvalidClientOptions() - { - return [ - 'invalid api_root' => [ - [ - 'api_root' => [ - 'something wrong' => Client::SANDBOX_API_URL, - 'something wronger' => Client::LIVE_API_URL - ], - ], - ], - 'invalid tls' => [ - [ - 'force_tls' => -1, - ], - ], - 'invalid mode' => [ - [ - 'mode' => 'sad', - ], - ], - 'invalid user_agent_component' => [ - [ - 'user_agent_component' => [ - 'I dont give a key:value pair', - ] - ], - ], - ]; - } - - /** - * @dataProvider getInvalidClientOptions - * @return void - * @throws ParamsError - */ - public function testFaultyClientOptionsValidator($options) - { - $this->expectException(ParamsError::class); - ClientOptionsValidator::validateOptions($options); - } -} diff --git a/tests/Unit/Legacy/Endpoints/InsuranceTest.php b/tests/Unit/Legacy/Endpoints/InsuranceTest.php deleted file mode 100644 index 2a041845..00000000 --- a/tests/Unit/Legacy/Endpoints/InsuranceTest.php +++ /dev/null @@ -1,1000 +0,0 @@ - [ - null, - 'payment_xxx' - ], - 'Test with String and payment id valid' => [ - 'my string', - 'payment_xxx' - ], - 'Test with Object and payment id valid' => [ - $this->createMock(Subscription::class), - 'payment_xxx' - ] - ]; - } - - /** - * @return array[] - */ - public function subscriptionDataProvider() - { - return [ - 'Test with right data and without payment id' => [ - [ - new Subscription( - 'insurance_contract_6VU1zZ5AKfy6EejiNxmLXh', - 1235, - '19', - 1312, - new Subscriber( - self::TEST_EMAIL, - self::TEST_PHONENUMBER, - 'lastname', - 'firstname', - 'address1', - 'address2', - 'zipcode', - 'city', - 'country', - null - ), - 'cancelUrl' - ), - new Subscription( - 'insurance_contract_3vt2jyvWWQc9wZCmWd1KtI', - 1568, - self::TEST_CMSREFERENCE, - 1312, - new Subscriber( - self::TEST_EMAIL, - self::TEST_PHONENUMBER, - 'last', - 'first', - 'adr1', - 'adr2', - 'zip', - 'city', - 'country', - self::TEST_BIRTHDATE - ), - 'cancelUrl' - ) - ], - null, - [ - 'subscriptions' => [ - [ - 'insurance_contract_id' => 'insurance_contract_6VU1zZ5AKfy6EejiNxmLXh', - 'amount' => 1235, - 'cms_reference' => '19', - 'product_price' => 1312, - 'cms_callback_url' => 'cancelUrl', - 'subscriber' => [ - 'email' => self::TEST_EMAIL, - 'phone_number' => self::TEST_PHONENUMBER, - 'last_name' => 'lastname', - 'first_name' => 'firstname', - 'birthdate' => null, - 'address' => [ - 'address_line_1' => 'address1', - 'address_line_2' => 'address2', - 'zip_code' => 'zipcode', - 'city' => 'city', - 'country' => 'country', - ] - ], - ], - [ - 'insurance_contract_id' => 'insurance_contract_3vt2jyvWWQc9wZCmWd1KtI', - 'amount' => 1568, - 'cms_reference' => self::TEST_CMSREFERENCE, - 'product_price' => 1312, - 'cms_callback_url' => 'cancelUrl', - 'subscriber' => [ - 'email' => self::TEST_EMAIL, - 'phone_number' => self::TEST_PHONENUMBER, - 'last_name' => 'last', - 'first_name' => 'first', - 'birthdate' => self::TEST_BIRTHDATE, - 'address' => [ - 'address_line_1' => 'adr1', - 'address_line_2' => 'adr2', - 'zip_code' => 'zip', - 'city' => 'city', - 'country' => 'country', - ] - ], - ] - ] - ] - ], - 'Test with right data and payment id' => [ - [ - new Subscription( - 'insurance_contract_6VU1zZ5AKfy6EejiNxmLXh', - 1235, - '19', - 1312, - new Subscriber( - self::TEST_EMAIL, - self::TEST_PHONENUMBER, - 'lastname', - 'firstname', - 'address1', - 'address2', - 'zipcode', - 'city', - 'country', - null - ), - 'cancelUrl' - ), - new Subscription( - 'insurance_contract_3vt2jyvWWQc9wZCmWd1KtI', - 1568, - self::TEST_CMSREFERENCE, - 1312, - new Subscriber( - self::TEST_EMAIL, - self::TEST_PHONENUMBER, - 'last', - 'first', - 'adr1', - 'adr2', - 'zip', - 'city', - 'country', - self::TEST_BIRTHDATE - ), - 'cancelUrl' - ) - ], - 'payment_id' => 'payment_11xlpX9QQYhd3xZVzNMrtdKw4myV7QET7X', - [ - 'subscriptions' => [ - [ - 'insurance_contract_id' => 'insurance_contract_6VU1zZ5AKfy6EejiNxmLXh', - 'amount' => 1235, - 'cms_reference' => '19', - 'product_price' => 1312, - 'cms_callback_url' => 'cancelUrl', - 'subscriber' => [ - 'email' => self::TEST_EMAIL, - 'phone_number' => self::TEST_PHONENUMBER, - 'last_name' => 'lastname', - 'first_name' => 'firstname', - 'birthdate' => null, - 'address' => [ - 'address_line_1' => 'address1', - 'address_line_2' => 'address2', - 'zip_code' => 'zipcode', - 'city' => 'city', - 'country' => 'country', - ] - ], - ], - [ - 'insurance_contract_id' => 'insurance_contract_3vt2jyvWWQc9wZCmWd1KtI', - 'amount' => 1568, - 'cms_reference' => self::TEST_CMSREFERENCE, - 'product_price' => 1312, - 'cms_callback_url' => 'cancelUrl', - 'subscriber' => [ - 'email' => self::TEST_EMAIL, - 'phone_number' => self::TEST_PHONENUMBER, - 'last_name' => 'last', - 'first_name' => 'first', - 'birthdate' => self::TEST_BIRTHDATE, - 'address' => [ - 'address_line_1' => 'adr1', - 'address_line_2' => 'adr2', - 'zip_code' => 'zip', - 'city' => 'city', - 'country' => 'country', - ] - ], - ] - ] - ] - ] - ]; - } - - /** - * @return array[] - */ - public static function requestDataProvider() - { - return [ - 'Throw exception with cms reference null' => [ - 'insurance_contract_external_id' => 'insurance_contract_6XxGHbjr51CE5Oly8E2Amx', - 'cms_reference' => null, - 'product_price' => 10000 - ], - 'Throw exception with insurance_contract_external_id null and cms reference null' => [ - 'insurance_contract_external_id' => null, - 'cms_reference' => null, - 'product_price' => 10000 - ], - 'Throw exception with cms reference array' => [ - 'insurance_contract_external_id' => 'insurance_contract_6XxGHbjr51CE5Oly8E2Amx', - 'cms_reference' => ['10', '13'], - 'product_price' => 10000 - ], - 'Throw exception with cms reference class' => [ - 'insurance_contract_external_id' => 'insurance_contract_6XxGHbjr51CE5Oly8E2Amx', - 'cms_reference' => new \stdClass(), - 'product_price' => 10000 - ], - 'Throw exception with cms reference bool' => [ - 'insurance_contract_external_id' => 'insurance_contract_6XxGHbjr51CE5Oly8E2Amx', - 'cms_reference' => true, - 'product_price' => 10000 - ], - 'Throw exception with cms reference string and special characters' => [ - 'insurance_contract_external_id' => 'insurance_contract_6XxGHbjr51CE5Oly8E2Amx', - 'cms_reference' => 'Une Str|ng [Avec] des *', - 'product_price' => 10000 - ], - 'Throw exception with cms reference string and spacial characters 2' => [ - 'insurance_contract_external_id' => 'insurance_contract_6XxGHbjr51CE5Oly8E2Amx', - 'cms_reference' => 'alma-%product', - 'product_price' => 10000 - ], - 'Throw exception with cms reference empty string' => [ - 'insurance_contract_external_id' => 'insurance_contract_6XxGHbjr51CE5Oly8E2Amx', - 'cms_reference' => '', - 'product_price' => 10000 - ] - ]; - } - - /** - * @return array[] - */ - public static function requestDataProviderRightParams() - { - return [ - 'call get with cms reference a string' => [ - 'insurance_contract_external_id' => 'insurance_contract_6XxGHbjr51CE5Oly8E2Amx', - 'cms_reference' => '1-2', - 'product_price' => 10000 - ], - 'call get with cms reference an integer' => [ - 'insurance_contract_external_id' => 'insurance_contract_6XxGHbjr51CE5Oly8E2Amx', - 'cms_reference' => 18, - 'product_price' => 10000 - ], - 'Call get with cms reference a string and space' => [ - 'insurance_contract_external_id' => 'insurance_contract_6XxGHbjr51CE5Oly8E2Amx', - 'cms_reference' => 'Alma insurance2 product', - 'product_price' => 10000 - ], - 'Call get with cms reference a string and - ' => [ - 'insurance_contract_external_id' => 'insurance_contract_6XxGHbjr51CE5Oly8E2Amx', - 'cms_reference' => 'Alma01-insurance-product', - 'product_price' => 10000 - ] - ]; - } - - /** - * @return array - */ - public function nonArrayParamGetSubscriptionDataProvider() - { - return [ - 'Test with Null' => [ - null - ], - 'Test with String' => [ - 'my string' - ], - 'Test with Object' => [ - $this->createMock(\stdClass::class) - ], - 'Test with Integer' => [ - 10 - ], - 'Test with Boolean' => [ - true - ] - ]; - } - - /** - * @return array[] - */ - public function getSubscriptionsRightParamDataProvider() - { - return [ - 'Test with 1 subscription id' => [ - ['id' => 'subscription_39lGsF0UdBfpjQ8UXdYvkX'], - '{ - "subscriptions": [ - { - "id": "subscription_39lGsF0UdBfpjQ8UXdYvkX", - "broker_subscription_id": "ec407087-65f0-410d-88d7-911178120887", - "subscriber": { - "email": "benjamin.freoua@getalma.eu", - "phone_number": "0613595410", - "first_name": "Freoua", - "last_name": "Benjamin", - "address_line_1": "13 boulevard de Picpus", - "address_line_2": "", - "zip_code": "75012", - "city": "Paris", - "country": "France" - }, - "contract_id": "insurance_contract_4D6UBXtagTd5DZlTGPpKuT", - "amount": 35000, - "state": "started", - "cms_reference": "1-1" - } - ] - }' - ], - 'Test with 2 subscription ids' => [ - [ - 'id' => 'subscription_39lGsF0UdBfpjQ8UXdYvkX', - 'id' => 'subscription_7I02iVfu8vmvDMxIlinXk1' - ], - '{ - "subscriptions": [ - { - "id": "subscription_39lGsF0UdBfpjQ8UXdYvkX", - "broker_subscription_id": "ec407087-65f0-410d-88d7-911178120887", - "subscriber": { - "email": "benjamin.freoua@getalma.eu", - "phone_number": "0613595410", - "first_name": "Freoua", - "last_name": "Benjamin", - "address_line_1": "13 boulevard de Picpus", - "address_line_2": "", - "zip_code": "75012", - "city": "Paris", - "country": "France" - }, - "contract_id": "insurance_contract_4D6UBXtagTd5DZlTGPpKuT", - "amount": 35000, - "state": "started", - "cms_reference": "1-1" - }, - { - "id": "subscription_7I02iVfu8vmvDMxIlinXk1", - "broker_subscription_id": "db774ddd-f50c-4e65-b5bc-5f073acef987", - "subscriber": { - "email": "benjamin.freoua@getalma.eu", - "phone_number": "0613595410", - "first_name": "Freoua", - "last_name": "Benjamin", - "address_line_1": "13 boulevard de Picpus", - "address_line_2": "", - "zip_code": "75012", - "city": "Paris", - "country": "France" - }, - "contract_id": "insurance_contract_4D6UBXtagTd5DZlTGPpKuT", - "amount": 35000, - "state": "started", - "cms_reference": "1-1" - } - ] - }' - ] - ]; - } - - /** - * @return array[] - */ - public function subscriptionIdInvalidDataProvider() - { - return [ - 'Test with subscription id invalid' => [ - [ - 'id' => 'toto' - ], - '{ - "subscriptions": [] - }' - ] - ]; - } - - /** - * @return void - */ - protected function setUp() - { - $this->clientContext = Mockery::mock(ClientContext::class); - $this->responseMock = Mockery::mock(Response::class); - $this->requestObject = Mockery::mock(Request::class); - $this->insuranceMock = Mockery::mock(Insurance::class)->makePartial(); - $this->insuranceValidatorMock = Mockery::mock(InsuranceValidator::class); - $this->insuranceMock->insuranceValidator = $this->insuranceValidatorMock; - - $this->arrayUtilsMock = Mockery::mock(ArrayUtils::class); - } - - protected function tearDown() - { - $this->clientContext = null; - $this->responseMock = null; - $this->requestObject = null; - $this->insuranceMock = null; - $this->insuranceValidatorMock = null; - Mockery::close(); - } - - /** - * @return void - */ - public function testInsuranceEligibilityMethodExist() - { - $insurance = new Insurance($this->clientContext); - $this->assertTrue(method_exists($insurance, 'getInsuranceContract')); - } - - /** - * @dataProvider requestDataProviderRightParams - * @param string $insuranceContractExternalId - * @param string $cmsReference - * @param int $productPrice - * @return void - * @throws MissingKeyException - * @throws ParametersException - * @throws RequestException - * @throws RequestError - */ - public function testGetRequestIsCalled($insuranceContractExternalId, $cmsReference, $productPrice) - { - - $this->responseMock->shouldReceive('isError')->once()->andReturn(false); - $this->requestObject->shouldReceive('get')->once()->andReturn($this->responseMock); - $this->requestObject->shouldReceive('setQueryParams')->once()->andReturn($this->requestObject); - $this->insuranceMock->shouldReceive('request') - ->with(self::INSURANCE_CONTRACTS_PATH . $insuranceContractExternalId) - ->once() - ->andReturn($this->requestObject); - $this->insuranceMock->shouldReceive('checkParameters') - ->once() - ->with($cmsReference, $insuranceContractExternalId, $productPrice); - - $this->insuranceMock->getInsuranceContract($insuranceContractExternalId, $cmsReference, $productPrice); - } - - /** - * @dataProvider requestDataProvider - * @param string $insuranceContractExternalId - * @param string $cmsReference - * @param int $productPrice - * @return void - * @throws MissingKeyException - * @throws ParametersException - * @throws RequestError - * @throws RequestException - */ - public function testThrowParametersExceptionWithWrongParams($insuranceContractExternalId, $cmsReference, $productPrice) - { - $this->requestObject->shouldNotReceive('get'); - $this->insuranceMock->shouldNotReceive('request'); - - $this->insuranceMock->shouldReceive('checkParameters')->once()->andThrow(ParametersException::class); - $this->expectException(ParametersException::class); - $this->insuranceMock->getInsuranceContract($insuranceContractExternalId, $cmsReference, $productPrice); - } - - /** - * @return void - * @throws MissingKeyException - * @throws ParametersException - * @throws RequestError - * @throws RequestException - */ - public function testApiResponseErrorThrowRequestException() - { - $insuranceContractExternalId = 'insurance_contract_6XxGHbjr51CE5Oly8E2Amx'; - $cmsReference = '18-24'; - $productPrice = 10000; - $this->responseMock->shouldReceive('isError')->once()->andReturn(true); - - $requestObject = Mockery::mock(Request::class)->shouldAllowMockingProtectedMethods(); - $requestObject->shouldReceive('get')->once()->andReturn($this->responseMock); - $requestObject->shouldReceive('setQueryParams')->once()->andReturn($requestObject); - - - $this->insuranceMock->shouldReceive('request') - ->with(self::INSURANCE_CONTRACTS_PATH . $insuranceContractExternalId) - ->once() - ->andReturn($requestObject); - - $this->insuranceMock->setClientContext($this->clientContext); - $this->insuranceMock->shouldReceive('checkParameters')->once(); - $this->expectException(RequestException::class); - $this->insuranceMock->getInsuranceContract($insuranceContractExternalId, $cmsReference, $productPrice); - } - - /** - * @dataProvider requestDataProviderRightParams - * @param string $insuranceContractExternalId - * @param string $cmsReference - * @param int $productPrice - * @return void - * @throws MissingKeyException - * @throws ParametersException - * @throws RequestError - * @throws RequestException - */ - public function testApiResponseInsuranceContract($insuranceContractExternalId, $cmsReference, $productPrice) - { - $files = [ - new File('Alma mobility 1 an (vol+casse+assistance) - Alma}', 'ipid-document', 'https://object-storage-s3-staging.s3.fr-par.scw.cloud/contracts/43acb66c-4b24-42d2-864a-24b4ade33e81/I6LK9O3XUNKNZPDTMH58IIK2HKBMRM2MIH-V0YGPECCD5Z20YIQUKXVCZYEU_TJD.pdf/OFXRU1UHY7J0CFO7X0Y24RSDMTG-W5BVB1GZRPPZFPSJRNIGGP2HXR2CEXIPBWZ-.pdf'), - new File('Alma mobility 1 an (vol+casse+assistance) - Alma}', 'fic-document', 'https://object-storage-s3-staging.s3.fr-par.scw.cloud/contracts/43acb66c-4b24-42d2-864a-24b4ade33e81/Y-PSWZG6-ADZ9MEY8PAZS2TMAUBXOLU6GYOLDWULMEAJB_VW0RGBKJTPMY7SPASN.pdf/UHSB9KVIGRLHP9DMXRZNCSWUGXCHS9VOW2EHAUNCYM_ANJIE7DOAKVLIH6EEOQYW.pdf'), - new File('Alma mobility 1 an (vol+casse+assistance) - Alma}', 'notice-document', 'https://object-storage-s3-staging.s3.fr-par.scw.cloud/contracts/43acb66c-4b24-42d2-864a-24b4ade33e81/JVPHA9RROHB6RPCG9K3VFG4EELBIMALK4QY2JVYEUTBFFT4SP1YN_ZUFXHOYRUSP.pdf/YTBTRJ6C9FFQFNW3234PHJJJT28VZR0FDOXVV0HV1SULI79S3UPSYRX7SZDNX1FX.pdf') - ]; - $contractExpected = new Contract( - "insurance_contract_6XxGHbjr51CE5Oly8E2Amx", - "Alma outillage thermique 3 ans (Vol + casse)", - 1095, - null, - null, - null, - null, - null, - 500, - $files - ); - $json = '{ - "id": "insurance_contract_6XxGHbjr51CE5Oly8E2Amx", - "name": "Alma outillage thermique 3 ans (Vol + casse)", - "protection_days": 1095, - "description": null, - "cover_area": null, - "compensation_area": null, - "exclusion_area": null, - "uncovered_area": null, - "price": 500, - "files": [ - { - "name": "Alma mobility 1 an (vol+casse+assistance) - Alma}", - "type": "ipid-document", - "public_url": "https://object-storage-s3-staging.s3.fr-par.scw.cloud/contracts/43acb66c-4b24-42d2-864a-24b4ade33e81/I6LK9O3XUNKNZPDTMH58IIK2HKBMRM2MIH-V0YGPECCD5Z20YIQUKXVCZYEU_TJD.pdf/OFXRU1UHY7J0CFO7X0Y24RSDMTG-W5BVB1GZRPPZFPSJRNIGGP2HXR2CEXIPBWZ-.pdf" - }, - { - "name": "Alma mobility 1 an (vol+casse+assistance) - Alma}", - "type": "fic-document", - "public_url": "https://object-storage-s3-staging.s3.fr-par.scw.cloud/contracts/43acb66c-4b24-42d2-864a-24b4ade33e81/Y-PSWZG6-ADZ9MEY8PAZS2TMAUBXOLU6GYOLDWULMEAJB_VW0RGBKJTPMY7SPASN.pdf/UHSB9KVIGRLHP9DMXRZNCSWUGXCHS9VOW2EHAUNCYM_ANJIE7DOAKVLIH6EEOQYW.pdf" - }, - { - "name": "Alma mobility 1 an (vol+casse+assistance) - Alma}", - "type": "notice-document", - "public_url": "https://object-storage-s3-staging.s3.fr-par.scw.cloud/contracts/43acb66c-4b24-42d2-864a-24b4ade33e81/JVPHA9RROHB6RPCG9K3VFG4EELBIMALK4QY2JVYEUTBFFT4SP1YN_ZUFXHOYRUSP.pdf/YTBTRJ6C9FFQFNW3234PHJJJT28VZR0FDOXVV0HV1SULI79S3UPSYRX7SZDNX1FX.pdf" - } - ] - }'; - - $this->responseMock->shouldReceive('isError')->once()->andReturn(false); - $this->responseMock->json = json_decode($json, true); - - $this->requestObject->shouldReceive('get')->once()->andReturn($this->responseMock); - $this->requestObject->shouldReceive('setQueryParams') - ->once() - ->andReturn($this->requestObject); - $this->insuranceMock->shouldReceive('request') - ->with(self::INSURANCE_CONTRACTS_PATH . $insuranceContractExternalId) - ->once() - ->andReturn($this->requestObject); - $this->insuranceMock->shouldReceive('checkParameters') - ->once() - ->with($cmsReference, $insuranceContractExternalId, $productPrice); - - $this->assertEquals( - $contractExpected, - $this->insuranceMock->getInsuranceContract($insuranceContractExternalId, $cmsReference, $productPrice) - ); - } - - /** - * @return void - */ - public function testInsuranceSubscriptionMethodExist() - { - $insurance = new Insurance($this->clientContext); - $this->assertTrue(method_exists($insurance, 'subscription')); - } - - /** - * @dataProvider nonArrayParamDataProvider - * @param $nonArrayParam - * @param $nonStringPaymentId - * @throws ParametersException - * @throws RequestError - * @throws RequestException - */ - public function testSubscriptionThrowExceptionIfNotArrayInParam($nonArrayParam, $nonStringPaymentId) - { - $insurance = new Insurance($this->clientContext); - $this->expectException(ParametersException::class); - $insurance->subscription($nonArrayParam, 'orderID', $nonStringPaymentId); - } - - /** - * @dataProvider subscriptionDataProvider - * @param $subscriptionArray - * @return void - * @throws ParametersException - * @throws RequestError - * @throws RequestException - */ - public function testSubscriptionThrowExceptionRequestError($subscriptionArray) - { - $this->responseMock->shouldReceive('isError')->once()->andReturn(true); - $this->responseMock->json = $subscriptionArray; - - $requestObject = Mockery::mock(Request::class); - $requestObject->shouldReceive('setRequestBody')->andReturn($requestObject); - $requestObject->shouldReceive('post')->once()->andReturn($this->responseMock); - - $insurance = Mockery::mock(Insurance::class)->shouldAllowMockingProtectedMethods()->makePartial(); - $insurance->shouldReceive('request') - ->with(self::INSURANCE_SUBSCRIPTIONS_PATH) - ->once() - ->andReturn($requestObject); - $insurance->setClientContext($this->clientContext); - $this->expectException(RequestException::class); - $insurance->subscription($subscriptionArray, 'orderId'); - } - - /** - * @dataProvider subscriptionDataProvider - * @param $subscriptionArray - * @param $paymentId - * @param $expectedSubscriptionPayload - * @throws ParametersException - * @throws RequestError - * @throws RequestException - */ - public function testSubscriptionGetRequestCall($subscriptionArray, $paymentId, $expectedSubscriptionPayload) - { - $expectedSubscriptionPayload['order_id'] = 'myOrderId'; - - if ($paymentId) { - $expectedSubscriptionPayload['payment_id'] = $paymentId; - } - $this->responseMock->shouldReceive('isError')->once()->andReturn(false); - $this->requestObject->shouldReceive('setRequestBody')->once() - ->with($expectedSubscriptionPayload) - ->andReturn($this->requestObject); - $this->requestObject->shouldReceive('post')->once()->andReturn($this->responseMock); - - $insurance = Mockery::mock(Insurance::class)->shouldAllowMockingProtectedMethods()->makePartial(); - $insurance->shouldReceive('request') - ->with(self::INSURANCE_SUBSCRIPTIONS_PATH) - ->once() - ->andReturn($this->requestObject); - $insurance->setClientContext($this->clientContext); - $insurance->subscription($subscriptionArray, 'myOrderId', $paymentId); - } - - /** - * @return void - */ - public function testSubscriptionMethodExist() - { - $insurance = new Insurance($this->clientContext); - $this->assertTrue(method_exists($insurance, 'getSubscription')); - } - - /** - * @dataProvider getSubscriptionsRightParamDataProvider - * @throws ParametersException - * @throws RequestError - * @throws RequestException - * @throws ResponseException - */ - public function testGetSubscriptionRequestIsCalled($subscriptionIds, $json) - { - $this->responseMock->json = json_decode($json, true); - $this->responseMock->shouldReceive('isError')->once()->andReturn(false); - $this->requestObject->shouldReceive('get')->once()->andReturn($this->responseMock); - $this->requestObject->shouldReceive('setQueryParams') - ->once() - ->with($subscriptionIds) - ->andReturn($this->requestObject); - $this->insuranceMock->shouldReceive('request') - ->with(self::INSURANCE_SUBSCRIPTIONS_PATH) - ->once() - ->andReturn($this->requestObject); - - $this->insuranceValidatorMock->shouldReceive('checkSubscriptionIds')->once(); - $this->insuranceMock->getSubscription($subscriptionIds); - } - - /** - * @dataProvider getSubscriptionsRightParamDataProvider - * @param $subscriptionIds - * @throws ParametersException - * @throws RequestError - * @throws RequestException - * @throws ResponseException - */ - public function testGetSubscriptionThrowExceptionIfResponseHasAnError($subscriptionIds) - { - $this->responseMock->shouldReceive('isError')->once()->andReturn(true); - $this->requestObject->shouldReceive('setQueryParams')->once()->andReturn($this->requestObject); - $this->requestObject->shouldReceive('get')->once()->andReturn($this->responseMock); - $this->insuranceMock->shouldReceive('request') - ->with(self::INSURANCE_SUBSCRIPTIONS_PATH) - ->once() - ->andReturn($this->requestObject); - - $this->insuranceValidatorMock->shouldReceive('checkSubscriptionIds') - ->once() - ->with($subscriptionIds); - - $this->expectException(RequestException::class); - $this->insuranceMock->getSubscription($subscriptionIds); - } - - /** - * @dataProvider nonArrayParamGetSubscriptionDataProvider - * @param $subscriptionIds - * @throws ParametersException - * @throws RequestError - * @throws RequestException - * @throws ResponseException - */ - public function testGetSubscriptionThrowExceptionIfWeDontSendAnArray($subscriptionIds) - { - $this->insuranceValidatorMock->shouldReceive('checkSubscriptionIds') - ->once() - ->with($subscriptionIds) - ->andThrow(ParametersException::class); - $this->expectException(ParametersException::class); - $this->insuranceMock->getSubscription($subscriptionIds); - } - - /** - * @dataProvider getSubscriptionsRightParamDataProvider - * @param $subscriptionIds - * @param $json - * @return void - * @throws ParametersException - * @throws RequestError - * @throws RequestException - */ - public function testGetSubscriptionsReturnApiResponse($subscriptionIds, $json) - { - $this->responseMock->json = json_decode($json, true); - $this->responseMock->shouldReceive('isError')->once()->andReturn(false); - $this->requestObject->shouldReceive('get')->once()->andReturn($this->responseMock); - $this->requestObject->shouldReceive('setQueryParams')->once()->andReturn($this->requestObject); - $this->insuranceMock->shouldReceive('request') - ->with(self::INSURANCE_SUBSCRIPTIONS_PATH) - ->once() - ->andReturn($this->requestObject); - $this->insuranceValidatorMock->shouldReceive('checkSubscriptionIds')->once(); - - $this->assertEquals($this->responseMock->json, $this->insuranceMock->getSubscription($subscriptionIds)); - } - - /** - * @return void - * @throws RequestError - */ - public function testGivenInvalidCmsReferenceArrayNoCallEndpointAndReturnFalse() - { - $this->insuranceValidatorMock->shouldReceive('checkCmsReference') - ->once() - ->andThrow(ParametersException::class); - $loggerMock = Mockery::mock(LoggerInterface::class); - $loggerMock->shouldReceive('error')->once(); - $this->clientContext->logger = $loggerMock; - $this->insuranceMock->setClientContext($this->clientContext); - $this->assertNull($this->insuranceMock->sendCustomerCart(['123','456'], 42)); - } - - /** - * @return void - * @throws ParametersException - * @throws RequestError - * @throws RequestException - */ - public function testCancelSubscriptionCallRequestWithSubscriptionArrayPayloadAndNoThrowExceptionForResponse200() - { - $subscriptionCancelPayload = ' subscriptionId1 '; - $this->responseMock->shouldReceive('isError')->once()->andReturn(false); - $this->requestObject->shouldReceive('post')->once()->andReturn($this->responseMock); - $this->insuranceMock->shouldReceive('request') - ->with(self::INSURANCE_SUBSCRIPTIONS_PATH . '/subscriptionId1/void') - ->once() - ->andReturn($this->requestObject); - $this->insuranceMock->cancelSubscription($subscriptionCancelPayload); - } - - /** - * @return void - * @throws RequestError - */ - public function testSendCustomerCartCallApiPostCustomerCartWithCmsReferencesArray() - { - $cartId = 42; - $this->insuranceValidatorMock->shouldReceive('checkCmsReference') - ->once(); - $this->requestObject->shouldReceive('setRequestBody')->once()->with( - [ - 'cms_references' => ['123','456'] - ] - )->andReturn($this->requestObject); - $this->insuranceMock->shouldReceive('request') - ->with(self::INSURANCE_CUSTOMER_CART_PATH) - ->once() - ->andReturn($this->requestObject); - $this->insuranceMock->shouldReceive('addCustomerSessionToRequest')->once()->with( - $this->requestObject, - null, - $cartId - ); - $this->requestObject->shouldReceive('post')->once(); - $this->assertNull($this->insuranceMock->sendCustomerCart(['123','456'], $cartId)); - } - - /** - * @return void - * @throws InsuranceCancelPendingException - * @throws ParametersException - * @throws RequestError - * @throws RequestException - */ - public function testCancelSubscriptionCallRequestWithSubscriptionArrayPayloadAndThrowExceptionForResponseUpperThan400ButNo410() - { - $this->expectException(RequestException::class); - $subscriptionCancelPayload = 'subscriptionId1'; - - $this->responseMock->shouldReceive('isError')->once()->andReturn(true); - $this->requestObject->shouldReceive('post')->once()->andReturn($this->responseMock); - $this->insuranceMock->shouldReceive('request') - ->with(self::INSURANCE_SUBSCRIPTIONS_PATH . '/subscriptionId1/void') - ->once() - ->andReturn($this->requestObject); - $this->insuranceMock->cancelSubscription($subscriptionCancelPayload); - } - - /** - * @return void - * @throws InsuranceCancelPendingException - * @throws ParametersException - * @throws RequestError - * @throws RequestException - */ - public function testCancelSubscriptionCallRequestWithSubscriptionArrayPayloadAndThrowInsuranceCancelPendingExceptionForResponse410() - { - $this->expectException(InsuranceCancelPendingException::class); - $subscriptionCancelPayload = 'subscriptionId1'; - $this->responseMock->responseCode = 410; - $this->requestObject->shouldReceive('post')->once()->andReturn($this->responseMock); - $this->insuranceMock->shouldReceive('request') - ->with(self::INSURANCE_SUBSCRIPTIONS_PATH . '/subscriptionId1/void') - ->once() - ->andReturn($this->requestObject); - $this->insuranceMock->cancelSubscription($subscriptionCancelPayload); - } - - /** - * @dataProvider cancelSubscriptionErrorPayloadDataProvider - * @param $payload - * @return void - * @throws ParametersException - */ - public function testCheckSubscriptionIdFormatThrowParamsErrorForBadPayload($payload) - { - $this->expectException(ParametersException::class); - $this->insuranceMock->checkSubscriptionIdFormat($payload); - } - - /** - * @return array - */ - public function cancelSubscriptionErrorPayloadDataProvider() - { - return [ - 'Null payload' => [ - 'subscriptionIdsArray' => null - ], - 'empty string payload' => [ - 'subscriptionIdsArray' => '' - ], - 'empty array payload' => [ - 'subscriptionIdsArray' => [] - ], - 'Subscription Object payload' => [ - 'subscriptionIdsArray' => $this->createMock(Subscription::class) - ], - ]; - } - - /** - * @dataProvider subscriptionIdInvalidDataProvider - * @param $subscriptionIdInvalid - * @param $jsonReturnRequest - * @return void - * @throws ParametersException - * @throws RequestError - * @throws RequestException - */ - public function testGetSubscriptionIfReturnZeroDataThrowException($subscriptionIdInvalid, $jsonReturnRequest) - { - $this->responseMock->json = json_decode($jsonReturnRequest, true); - $this->responseMock->shouldReceive('isError')->once()->andReturn(false); - $this->requestObject->shouldReceive('setQueryParams')->once()->andReturn($this->requestObject); - $this->requestObject->shouldReceive('get')->once()->andReturn($this->responseMock); - $this->insuranceMock->shouldReceive('request') - ->with(self::INSURANCE_SUBSCRIPTIONS_PATH) - ->once() - ->andReturn($this->requestObject); - - $this->insuranceValidatorMock->shouldReceive('checkSubscriptionIds') - ->once() - ->with($subscriptionIdInvalid); - - $this->expectException(ResponseException::class); - $this->insuranceMock->getSubscription($subscriptionIdInvalid); - } -} diff --git a/tests/Unit/Legacy/Entities/Insurance/ContractTest.php b/tests/Unit/Legacy/Entities/Insurance/ContractTest.php deleted file mode 100644 index 898b5f94..00000000 --- a/tests/Unit/Legacy/Entities/Insurance/ContractTest.php +++ /dev/null @@ -1,289 +0,0 @@ -contractData = $this->getContractData(); - $this->contract = $this->createNewContract($this->contractData); - - } - - /** - * @return void - */ - public function testConstructObject() - { - $this->assertSame(Contract::class, get_class($this->contract)); - } - - /** - * @return void - */ - public function testGetIdReturnId() - { - $this->assertEquals($this->contract->getId(), $this->contractData['id']); - } - - /** - * @return void - */ - public function testGetReturnName() - { - $this->assertEquals($this->contract->getName(), $this->contractData['name']); - } - - /** - * @return void - */ - public function testGetReturnProtectionDays() - { - $this->assertEquals($this->contract->getProtectionDays(), $this->contractData['protection_days']); - } - - /** - * @return void - */ - public function testGetReturnDescription() - { - $this->assertEquals($this->contract->getDescription(), $this->contractData['description']); - } - - /** - * @return void - */ - public function testGetReturnCoverArea() - { - $this->assertEquals($this->contract->getCoverArea(), $this->contractData['cover_area']); - } - - /** - * @return void - */ - public function testGetReturnCompensationArea() - { - $this->assertEquals($this->contract->getCompensationArea(), $this->contractData['compensation_area']); - } - - /** - * @return void - */ - public function testGetReturnExclusionArea() - { - $this->assertEquals($this->contract->getExclusionArea(), $this->contractData['exclusion_area']); - } - - /** - * @return void - */ - public function testGetReturnUncoveredArea() - { - $this->assertEquals($this->contract->getUncoveredArea(), $this->contractData['uncovered_area']); - } - - /** - * @return void - */ - public function testGetReturnPrice() - { - $this->assertEquals($this->contract->getPrice(), $this->contractData['price']); - } - - /** - * @return void - */ - public function testGetReturnFiles() - { - $this->assertEquals($this->contract->getFiles(), $this->contractData['files']); - } - - /** - * @dataProvider contractDataProvider - * @param int $days - * @param int $years - * @return void - */ - public function testGetProtectionDurationInYear($days, $years) - { - $contractData = $this->getContractData(); - $contractData['protection_days'] = $days; - $contract = $this->createNewContract($contractData); - $this->assertEquals($years, $contract->getProtectionDurationInYear()); - } - - /** - * @dataProvider fileDataProvider - * @param string $type - * @param File $file - * @return void - */ - public function testGetFileByTypeReturnType($type, $file) - { - $contractData = $this->getContractData(); - $contract = $this->createNewContract($contractData); - $this->assertEquals($file, $contract->getFileByType($type)); - } - - /** - * @return array[] - */ - public function contractDataProvider() - { - return [ - 'duration less than 1 year' => [ - 'days' => 364, - 'years' => 0 - ], - 'duration 1 year' => [ - 'days' => 365, - 'years' => 1 - ], - 'duration 1 leap year' => [ - 'days' => 366, - 'years' => 1 - ], - 'duration 2 years' => [ - 'days' => 730, - 'years' => 2 - ], - 'duration 3 years' => [ - 'days' => 1095, - 'years' => 3 - ], - 'duration 3 years and 2 days' => [ - 'days' => 1097, - 'years' => 3 - ] - ]; - } - - /** - * @return array[] - */ - public function fileDataProvider() - { - $ipidFileData = $this->getFileData('ipid-document'); - $ipidFile = new File($ipidFileData->getName(), $ipidFileData->getType(), $ipidFileData->getPublicUrl()); - $ficFileData = $this->getFileData('fic-document'); - $ficFile = new File($ficFileData->getName(), $ficFileData->getType(), $ficFileData->getPublicUrl()); - $noticeFileData = $this->getFileData('notice-document'); - $noticeFile = new File($noticeFileData->getName(), $noticeFileData->getType(), $noticeFileData->getPublicUrl()); - - return [ - 'type is ipid-document' => [ - 'type' => 'ipid-document', - 'data' => $ipidFile - ], - 'type is fic-document' => [ - 'type' => 'fic-document', - 'data' => $ficFile - ], - 'type is notice-document' => [ - 'type' => 'notice-document', - 'data' => $noticeFile - ], - 'type is wrong string' => [ - 'type' => 'unknown-document', - 'data' => null - ], - 'type is object' => [ - 'type' => new \stdClass(), - 'data' => null - ], - 'type is empty' => [ - 'type' => '', - 'data' => null - ], - ]; - } - - /** - * @param array $contractData - * @return Contract - */ - private function createNewContract($contractData) - { - return new Contract( - $contractData['id'], - $contractData['name'], - $contractData['protection_days'], - $contractData['description'], - $contractData['cover_area'], - $contractData['compensation_area'], - $contractData['exclusion_area'], - $contractData['uncovered_area'], - $contractData['price'], - $contractData['files'] - ); - } - - /** - * @return array - */ - private function getContractData() - { - return [ - 'id' => 'insurance_contract_3eWqr58LexAqxUAlNVKWEf', - 'name' => 'Insurance contract Name', - 'protection_days' => 365, - 'description' => 'description_value', - 'cover_area' => 'cover_area_value', - 'compensation_area' => 'compensation_area_value', - 'exclusion_area' => 'exclusion_area_value', - 'uncovered_area' => 'uncovered_area_value', - 'price' => 6000, //price in cent - 'files' => [ - $this->getFileData('ipid-document'), - $this->getFileData('fic-document'), - $this->getFileData('notice-document') - ] - ]; - } - - /** - * @param string $type - * @return File - */ - private function getFileData($type) - { - $files = [ - 'ipid-document' => new File( - 'Alma mobility 1 an (vol+casse+assistance) - Alma}', - 'ipid-document', - 'https://object-storage-s3-staging.s3.fr-par.scw.cloud/contracts/43acb66c-4b24-42d2-864a-24b4ade33e81/I6LK9O3XUNKNZPDTMH58IIK2HKBMRM2MIH-V0YGPECCD5Z20YIQUKXVCZYEU_TJD.pdf/OFXRU1UHY7J0CFO7X0Y24RSDMTG-W5BVB1GZRPPZFPSJRNIGGP2HXR2CEXIPBWZ-.pdf' - ), - 'fic-document' => new File( - 'Alma mobility 1 an (vol+casse+assistance) - Alma}', - 'fic-document', - 'https://object-storage-s3-staging.s3.fr-par.scw.cloud/contracts/43acb66c-4b24-42d2-864a-24b4ade33e81/Y-PSWZG6-ADZ9MEY8PAZS2TMAUBXOLU6GYOLDWULMEAJB_VW0RGBKJTPMY7SPASN.pdf/UHSB9KVIGRLHP9DMXRZNCSWUGXCHS9VOW2EHAUNCYM_ANJIE7DOAKVLIH6EEOQYW.pdf' - ), - 'notice-document' => new File( - 'Alma mobility 1 an (vol+casse+assistance) - Alma}', - 'notice-document', - 'https://object-storage-s3-staging.s3.fr-par.scw.cloud/contracts/43acb66c-4b24-42d2-864a-24b4ade33e81/JVPHA9RROHB6RPCG9K3VFG4EELBIMALK4QY2JVYEUTBFFT4SP1YN_ZUFXHOYRUSP.pdf/YTBTRJ6C9FFQFNW3234PHJJJT28VZR0FDOXVV0HV1SULI79S3UPSYRX7SZDNX1FX.pdf' - ) - ]; - - return $files[$type]; - } -} diff --git a/tests/Unit/Legacy/RequestErrorTest.php b/tests/Unit/Legacy/RequestErrorTest.php deleted file mode 100644 index 042b9932..00000000 --- a/tests/Unit/Legacy/RequestErrorTest.php +++ /dev/null @@ -1,59 +0,0 @@ -errorMessage = $validExpected; - - $noMessageExpected = 'error message hidden in response'; - $noMessageResponse = Mockery::mock(Response::class); - $noMessageResponse->errorMessage = null; - $noMessageResponse->json = [ - 'errors' => [ - 0 => [ - 'message' => $noMessageExpected - ] - ] - ]; - - return [ - 'valid example' => [ - null, $validResponse, $validExpected, - ], - 'error message hidden in response' => [ - null, $noMessageResponse, $noMessageExpected, - ] - ]; - } - - /** - * @dataProvider getErrorMessageProvider - * @return void - * @throws ParamsError - */ - public function testGetErrorMessage($req, $res, $expected) - { - $requestError = new RequestError($res->errorMessage, $req, $res); - - $this->assertEquals($expected, $requestError->getErrorMessage()); - } -} diff --git a/tests/Unit/Legacy/Lib/ArrayUtilsTest.php b/tests/Unit/Lib/ArrayUtilsTest.php similarity index 94% rename from tests/Unit/Legacy/Lib/ArrayUtilsTest.php rename to tests/Unit/Lib/ArrayUtilsTest.php index babc75c1..7d00132a 100644 --- a/tests/Unit/Legacy/Lib/ArrayUtilsTest.php +++ b/tests/Unit/Lib/ArrayUtilsTest.php @@ -1,6 +1,6 @@ arrayUtils = new ArrayUtils(); } diff --git a/tests/Unit/Legacy/Lib/InsuranceValidatorTest.php b/tests/Unit/Lib/InsuranceValidatorTest.php similarity index 74% rename from tests/Unit/Legacy/Lib/InsuranceValidatorTest.php rename to tests/Unit/Lib/InsuranceValidatorTest.php index 3fa266a8..e95d956f 100644 --- a/tests/Unit/Legacy/Lib/InsuranceValidatorTest.php +++ b/tests/Unit/Lib/InsuranceValidatorTest.php @@ -1,10 +1,11 @@ insuranceValidator = new InsuranceValidator(); } @@ -43,34 +44,34 @@ public function testCheckCmsReferenceWithValidPayload() /** * @return array */ - public function checkCmsReferenceInvalidPayloadDataProvider() + public static function checkCmsReferenceInvalidPayloadDataProvider() { return [ 'String payload' => [ - 'payload' => 'mb-024, mb-048' + 'invalidPayload' => 'mb-024, mb-048' ], 'Empty string payload' => [ - 'payload' => '' + 'invalidPayload' => '' ], 'Object payload' => [ - 'payload' => new \stdClass() + 'invalidPayload' => new stdClass() ], 'Empty array' => [ - 'payload' => [] + 'invalidPayload' => [] ], 'Int payload' => [ - 'payload' => 123 + 'invalidPayload' => 123 ], 'Bool payload' => [ - 'payload' => true + 'invalidPayload' => true ], 'Object payload in array' => [ - 'payload' => ['1236', new \stdClass()] + 'invalidPayload' => ['1236', new stdClass()] ], ]; } diff --git a/tests/Unit/PHP7_0/ArrayUtilsTest.php b/tests/Unit/PHP7_0/ArrayUtilsTest.php deleted file mode 100644 index 261954bb..00000000 --- a/tests/Unit/PHP7_0/ArrayUtilsTest.php +++ /dev/null @@ -1,36 +0,0 @@ - 'a', "1" => 'b', "2" => 'c'], false], - [["1" => 'a', "0" => 'b', "2" => 'c'], false], - [["a" => 'a', "b" => 'b', "c" => 'c'], true], - ]; - } - - /** - * @dataProvider getTestArrays - * @return void - */ - public function testIsAssocArray($testArray, $expectedResult) - { - $result = ArrayUtils::isAssocArray($testArray); - $this->assertEquals($expectedResult, $result); - } -} diff --git a/tests/Unit/PHP7_0/ClientContextTest.php b/tests/Unit/PHP7_0/ClientContextTest.php deleted file mode 100644 index 7f6542c4..00000000 --- a/tests/Unit/PHP7_0/ClientContextTest.php +++ /dev/null @@ -1,58 +0,0 @@ - [[ - 'api_root' => [ - Client::TEST_MODE => self::FAKE_API_URI, - Client::LIVE_MODE => self::FAKE_API_URI - ], - 'force_tls' => 0, - 'mode' => Client::TEST_MODE, - 'logger' => new NullLogger() - ]], - 'user_agent_component' => [[ - 'api_root' => [ - Client::TEST_MODE => self::FAKE_API_URI, - Client::LIVE_MODE => self::FAKE_API_URI - ], - 'force_tls' => 0, - 'mode' => Client::TEST_MODE, - 'logger' => new NullLogger(), - 'user_agent_component' => ['Magento' => '12.3'] - ]], - ]; - } - - /** - * @dataProvider getClientconfigOptions - * @return void - * @throws ParamsError - */ - public function testClientContext($options) - { - $context = new ClientContext("sk_fake_api_key", $options); - - $this->assertInstanceOf(ClientContext::class, $context); - } -} diff --git a/tests/Unit/PHP7_0/ClientOptionsValidatorTest.php b/tests/Unit/PHP7_0/ClientOptionsValidatorTest.php deleted file mode 100644 index 7314b340..00000000 --- a/tests/Unit/PHP7_0/ClientOptionsValidatorTest.php +++ /dev/null @@ -1,155 +0,0 @@ - [ - Client::TEST_MODE => Client::SANDBOX_API_URL, - Client::LIVE_MODE => Client::LIVE_API_URL - ], - 'force_tls' => 2, - 'mode' => Client::LIVE_MODE, - 'logger' => new NullLogger() - ] - ], - [ - [ - 'api_root' => [ - Client::TEST_MODE => self::FAKE_API_URI, - Client::LIVE_MODE => self::FAKE_API_URI - ], - 'force_tls' => 0, - 'mode' => Client::TEST_MODE, - 'logger' => new NullLogger() - ], - [ - 'api_root' => [ - Client::TEST_MODE => self::FAKE_API_URI, - Client::LIVE_MODE => self::FAKE_API_URI - ], - 'force_tls' => 0, - 'mode' => Client::TEST_MODE, - 'logger' => new NullLogger() - ] - ], - [ - [ - 'api_root' => self::FAKE_API_URI, - 'force_tls' => true, - 'logger' => new NullLogger() - ], - [ - 'api_root' => [ - Client::TEST_MODE => self::FAKE_API_URI, - Client::LIVE_MODE => self::FAKE_API_URI - ], - 'force_tls' => 2, - 'mode' => Client::LIVE_MODE, - 'logger' => new NullLogger() - ] - ], - [ - [ - 'user_agent_component' => [ - 'PrestaShop' => 2.3, - 'Alma for PrestaShop' => 'v2.3', - ] - ], - [ - 'api_root' => [ - Client::TEST_MODE => Client::SANDBOX_API_URL, - Client::LIVE_MODE => Client::LIVE_API_URL - ], - 'force_tls' => 2, - 'mode' => Client::LIVE_MODE, - 'logger' => new NullLogger(), - 'user_agent_component' => [ - 'PrestaShop' => 2.3, - 'Alma for PrestaShop' => 'v2.3', - ] - ] - ] - ]; - } - - /** - * @dataProvider getClientOptions - * @return void - * @throws ParamsError - */ - public function testClientOptionsValidator($options, $expectedResult) - { - $validatedConfig = ClientOptionsValidator::validateOptions($options); - - $this->assertEquals($expectedResult, $validatedConfig); - } - - /** - * Return faulty options to test ClientOptionsValidator::validateOptions - * @return array - */ - public function getInvalidClientOptions() - { - return [ - 'invalid api_root' => [ - [ - 'api_root' => [ - 'something wrong' => Client::SANDBOX_API_URL, - 'something wronger' => Client::LIVE_API_URL - ], - ], - ], - 'invalid tls' => [ - [ - 'force_tls' => -1, - ], - ], - 'invalid mode' => [ - [ - 'mode' => 'sad', - ], - ], - 'invalid user_agent_component' => [ - [ - 'user_agent_component' => [ - 'I dont give a key:value pair', - ] - ], - ], - ]; - } - - /** - * @dataProvider getInvalidClientOptions - * @return void - * @throws ParamsError - */ - public function testFaultyClientOptionsValidator($options) - { - $this->expectException(ParamsError::class); - ClientOptionsValidator::validateOptions($options); - } -} diff --git a/tests/Unit/PHP7_0/Endpoints/PaymentsTest.php b/tests/Unit/PHP7_0/Endpoints/PaymentsTest.php deleted file mode 100644 index ea4db9e2..00000000 --- a/tests/Unit/PHP7_0/Endpoints/PaymentsTest.php +++ /dev/null @@ -1,511 +0,0 @@ -assertEquals(true, method_exists($payments, 'partialRefund')); - $this->assertEquals(true, method_exists($payments, 'fullRefund')); - # ensure backward compatibility - $this->assertEquals(true, method_exists($payments, 'refund')); - } - - /** - * Mock ClientContext, Response and Request to allow us to test - * Payment without sending any requests - */ - private function mockServerRequest() - { - // ClientContext - $clientContext = Mockery::mock(ClientContext::class); - $clientContext->shouldReceive('urlFor'); - $clientContext->shouldReceive('getUserAgentString'); - $clientContext->shouldReceive('forcedTLSVersion'); - - // Response - $json = '{ - "payment_plan":[ - { - "customer_can_postpone":false, - "customer_fee":100, - "customer_interest":0, - "date_paid":1649672472, - "due_date":1649672451, - "id":"installment_11uPRjPgPJ5jxmEEXxIPPOvVA3Fh7cg13m", - "original_purchase_amount":11733, - "purchase_amount":11733, - "state":"paid" - }, - { - "customer_can_postpone":false, - "customer_fee":0, - "customer_interest":0, - "date_paid":null, - "due_date":1652264451, - "id":"installment_11uPRjP4a3cFQvoM1lehDnpxa2tYm2Hy0I", - "original_purchase_amount":11733, - "purchase_amount":0, - "state":"paid" - }, - { - "customer_can_postpone":false, - "customer_fee":0, - "customer_interest":0, - "date_paid":null, - "due_date":1654942851, - "id":"installment_11uPRjP79fG5QtHO54lSYsnDvyHb56oeCn", - "original_purchase_amount":11733, - "purchase_amount":0, - "state":"paid" - } - ], - "orders":[ - { - "comment":null, - "created":1649672451, - "customer_url":null, - "data":{}, - "id":"order_11uPRjP4L9Dgbttx3cFUKGFPppdZIlrR2V", - "merchant_reference":"00000206", - "merchant_url":null, - "payment":"payment_11uPRjP5FaIYygQao8WdMQFnKRMOV14frx" - } - ], - "refunds":[ - { - "amount":35299, - "created":1649770695, - "from_payment_cancellation":false, - "id":"refund_11uPrHz4TfHmQrD1OkYyWb4hPuq3673Vqm", - "merchant_reference":null, - "payment":"payment_11uPRjP5FaIYygQao8WdMQFnKRMOV14frx", - "payment_refund_amount":11833, - "rebate_amount":23466 - } - ] - }'; - - $responseMock = Mockery::mock(Response::class); - $responseMock->shouldReceive('isError')->andReturn(false); - $responseMock->json = json_decode($json, true); - - // Request - $requestMock = Mockery::mock(Request::class); - $requestMock->shouldReceive('setRequestBody'); - $requestMock->shouldReceive('post')->andReturn($responseMock); - return $requestMock; - } - - /** - * Return input to test testPartialRefund - * @return array[] - */ - public function getPartialRefundData() - { - return [ - [[ - 'id' => "some_id", - 'amount' => 15000, - 'merchant_ref' => self::MERCHANT_REF, - 'comment' => "some comment" - ]], - [[ - 'id' => "some_id", - 'amount' => 15000, - 'merchant_ref' => self::MERCHANT_REF - ]], - [[ - 'id' => "some_id", - 'amount' => 15000 - ]] - ]; - } - - private function callPartialRefund($payments, $data) - { - if (isset($data['merchant_ref']) && isset($data['comment'])) { - $payments->partialRefund($data['id'], $data['amount'], $data['merchant_ref'], $data['comment']); - } elseif (isset($data['merchant_ref'])) { - $payments->partialRefund($data['id'], $data['amount'], $data['merchant_ref']); - } elseif (isset($data['comment'])) { - $payments->partialRefund($data['id'], $data['amount'], '', $data['comment']); - } else { - $payments->partialRefund($data['id'], $data['amount']); - } - } - - /** - * Test the partialRefund method with valid datas - * @dataProvider getPartialRefundData - * @return void - */ - public function testPartialRefund($data) - { - $clientContext = Mockery::mock(ClientContext::class); - - // Payment - $payments = Mockery::mock(Payments::class) - ->shouldAllowMockingProtectedMethods() - ->makePartial() - ; - $id = $data['id']; - $payments->shouldReceive('request') - ->with("/v1/payments/$id/refund") - ->once() - ->andReturn($this->mockServerRequest()) - ; - $payments->setClientContext($clientContext); - - /* Test */ - $this->callPartialRefund($payments, $data); - } - - /** - * Return invalid input to test testPartialRefund - * @return array[] - */ - public function getPartialRefundInvalidData() - { - return [ - [[ - 'id' => "negative_amount", - 'amount' => -1 - ], ParamsError::class], - [[ - 'id' => "", - 'amount' => 1500, - 'merchant_ref' => "no id", - ], ParamsError::class], - ]; - } - - /** - * Test the partialRefund method with valid datas - * @dataProvider getPartialRefundInvalidData - * @return void - */ - public function testInvalidPartialRefund($data, $expectedException) - { - $clientContext = Mockery::mock(ClientContext::class); - - // Payment - $payments = Mockery::mock(Payments::class) - ->shouldAllowMockingProtectedMethods() - ->makePartial() - ; - $id = $data['id']; - $payments->shouldReceive('request') - ->with("/v1/payments/$id/refund") - ->andReturn($this->mockServerRequest()) - ; - $payments->setClientContext($clientContext); - - $this->expectException($expectedException); - - /* Test */ - $this->callPartialRefund($payments, $data); - } - - - private function callFullRefund($payments, $data) - { - if (isset($data['merchant_ref']) && isset($data['comment'])) { - $payments->fullRefund($data['id'], $data['merchant_ref'], $data['comment']); - } elseif (isset($data['merchant_ref'])) { - $payments->fullRefund($data['id'], $data['merchant_ref']); - } elseif (isset($data['comment'])) { - $payments->fullRefund($data['id'], '', $data['comment']); - } else { - $payments->fullRefund($data['id']); - } - } - - /** - * Return input to test testFullRefund - * @return array[] - */ - public function getFullRefundData() - { - return [ - [[ - 'id' => "some_id", - 'merchant_ref' => self::MERCHANT_REF, - 'comment' => "some comment" - ]], - [[ - 'id' => "some_id", - 'merchant_ref' => self::MERCHANT_REF - ]], - [[ - 'id' => "some_id", - ]] - ]; - } - - /** - * Test the fullRefund method with valid datas - * @dataProvider getFullRefundData - * @return void - */ - public function testFullRefund($data) - { - $clientContext = Mockery::mock(ClientContext::class); - - // Payment - $payments = Mockery::mock(Payments::class) - ->shouldAllowMockingProtectedMethods() - ->makePartial() - ; - $id = $data['id']; - $payments->shouldReceive('request') - ->with("/v1/payments/$id/refund") - ->once() - ->andReturn($this->mockServerRequest()) - ; - $payments->setClientContext($clientContext); - - /* Test */ - $this->callFullRefund($payments, $data); - } - - /** - * Return input to test testRefund - * @return array[] - */ - public function getRefundData() - { - return [ - [[ - 'id' => "some_id", - 'amount' => 15000, - 'merchant_ref' => self::MERCHANT_REF, - ]], - [[ - 'id' => "some_id", - ]], - [[ - 'id' => "some_id", - 'amount' => 15000 - ]] - ]; - } - - private function callRefund($payments, $data) - { - if (isset($data['merchant_ref']) && isset($data['amount'])) { - $payments->refund($data['id'], $data['amount'], $data['merchant_ref']); - } elseif (isset($data['amount'])) { - $payments->refund($data['id'], $data['amount']); - } else { - $payments->refund($data['id']); - } - } - - /** - * Test the fullRefund method with valid datas - * Important to ensure we didn't break compatibility with 1.x.x versions - * @dataProvider getRefundData - * @return void - */ - public function testRefund($data) - { - $clientContext = Mockery::mock(ClientContext::class); - - // Payment - $payments = Mockery::mock(Payments::class) - ->shouldAllowMockingProtectedMethods() - ->makePartial() - ; - $id = $data['id']; - $payments->shouldReceive('request') - ->with("/v1/payments/$id/refund") - ->once() - ->andReturn($this->mockServerRequest()) - ; - $payments->setClientContext($clientContext); - - /* Test */ - $this->callRefund($payments, $data); - } - - /** - * Return invalid input to test testFullRefund - * @return array[] - */ - public function getFullRefundInvalidData() - { - return [ - [[ - 'id' => "", - 'merchant_ref' => "no id", - ], ParamsError::class], - ]; - } - - /** - * Test the fullRefund method with valid datas - * @dataProvider getFullRefundInvalidData - * @return void - */ - public function testInvalidFullRefund($data, $expectedException) - { - $clientContext = Mockery::mock(ClientContext::class); - - // Payment - $payments = Mockery::mock(Payments::class) - ->shouldAllowMockingProtectedMethods() - ->makePartial() - ; - $id = $data['id']; - $payments->shouldReceive('request') - ->with("/v1/payments/$id/refund") - ->andReturn($this->mockServerRequest()) - ; - $payments->setClientContext($clientContext); - - $this->expectException($expectedException); - - /* Test */ - $this->callFullRefund($payments, $data); - } - - /** - * Mock ClientContext, Response and Request to allow us to test - * Payment without sending any requests but returns an error - */ - private function mockServerRequestError() - { - // ClientContext - $clientContext = Mockery::mock(ClientContext::class); - $clientContext->shouldReceive('urlFor'); - $clientContext->shouldReceive('getUserAgentString'); - $clientContext->shouldReceive('forcedTLSVersion'); - - // Response - $json = '{ - "payment_plan":[ - { - "customer_can_postpone":false, - "customer_fee":100, - "customer_interest":0, - "date_paid":1649672472, - "due_date":1649672451, - "id":"installment_11uPRjPgPJ5jxmEEXxIPPOvVA3Fh7cg13m", - "original_purchase_amount":11733, - "purchase_amount":11733, - "state":"paid" - }, - { - "customer_can_postpone":false, - "customer_fee":0, - "customer_interest":0, - "date_paid":null, - "due_date":1652264451, - "id":"installment_11uPRjP4a3cFQvoM1lehDnpxa2tYm2Hy0I", - "original_purchase_amount":11733, - "purchase_amount":0, - "state":"paid" - }, - { - "customer_can_postpone":false, - "customer_fee":0, - "customer_interest":0, - "date_paid":null, - "due_date":1654942851, - "id":"installment_11uPRjP79fG5QtHO54lSYsnDvyHb56oeCn", - "original_purchase_amount":11733, - "purchase_amount":0, - "state":"paid" - } - ], - "orders":[ - { - "comment":null, - "created":1649672451, - "customer_url":null, - "data":{}, - "id":"order_11uPRjP4L9Dgbttx3cFUKGFPppdZIlrR2V", - "merchant_reference":"00000206", - "merchant_url":null, - "payment":"payment_11uPRjP5FaIYygQao8WdMQFnKRMOV14frx" - } - ], - "refunds":[ - { - "amount":35299, - "created":1649770695, - "from_payment_cancellation":false, - "id":"refund_11uPrHz4TfHmQrD1OkYyWb4hPuq3673Vqm", - "merchant_reference":null, - "payment":"payment_11uPRjP5FaIYygQao8WdMQFnKRMOV14frx", - "payment_refund_amount":11833, - "rebate_amount":23466 - } - ] - }'; - - $responseMock = Mockery::mock(Response::class); - $responseMock->shouldReceive('isError')->andReturn(true); - $responseMock->json = json_decode($json, true); - $responseMock->errorMessage = "a very important error message"; - - // Request - $requestMock = Mockery::mock(Request::class); - $requestMock->shouldReceive('setRequestBody'); - $requestMock->shouldReceive('post')->andReturn($responseMock); - return $requestMock; - } - - public function testFullRefundRequestError() - { - // Input - $clientContext = Mockery::mock(ClientContext::class); - $id = "some_id"; - - // Payment - $payments = Mockery::mock(Payments::class) - ->shouldAllowMockingProtectedMethods() - ->makePartial() - ; - $payments->shouldReceive('request') - ->with("/v1/payments/$id/refund") - ->once() - ->andReturn($this->mockServerRequestError()) - ; - $payments->setClientContext($clientContext); - - $this->expectException(RequestError::class); - - /* Test */ - $payments->fullRefund($id); - } - - public function tearDown() - { - Mockery::close(); - } -} diff --git a/tests/Unit/PHP7_0/RequestErrorTest.php b/tests/Unit/PHP7_0/RequestErrorTest.php deleted file mode 100644 index 258f3c30..00000000 --- a/tests/Unit/PHP7_0/RequestErrorTest.php +++ /dev/null @@ -1,59 +0,0 @@ -errorMessage = $validExpected; - - $noMessageExpected = 'error message hidden in response'; - $noMessageResponse = Mockery::mock(Response::class); - $noMessageResponse->errorMessage = null; - $noMessageResponse->json = [ - 'errors' => [ - 0 => [ - 'message' => $noMessageExpected - ] - ] - ]; - - return [ - 'valid example' => [ - null, $validResponse, $validExpected, - ], - 'error message hidden in response' => [ - null, $noMessageResponse, $noMessageExpected, - ] - ]; - } - - /** - * @dataProvider getErrorMessageProvider - * @return void - * @throws ParamsError - */ - public function testGetErrorMessage($req, $res, $expected) - { - $requestError = new RequestError($res->errorMessage, $req, $res); - - $this->assertEquals($expected, $requestError->getErrorMessage()); - } -} diff --git a/tests/Unit/PHP7_2/ArrayUtilsTest.php b/tests/Unit/PHP7_2/ArrayUtilsTest.php deleted file mode 100644 index e7f7057a..00000000 --- a/tests/Unit/PHP7_2/ArrayUtilsTest.php +++ /dev/null @@ -1,36 +0,0 @@ - 'a', "1" => 'b', "2" => 'c'], false], - [["1" => 'a', "0" => 'b', "2" => 'c'], false], - [["a" => 'a', "b" => 'b', "c" => 'c'], true], - ]; - } - - /** - * @dataProvider getTestArrays - * @return void - */ - public function testIsAssocArray($testArray, $expectedResult) - { - $result = ArrayUtils::isAssocArray($testArray); - $this->assertEquals($expectedResult, $result); - } -} diff --git a/tests/Unit/PHP7_2/ClientContextTest.php b/tests/Unit/PHP7_2/ClientContextTest.php deleted file mode 100644 index 7492a82b..00000000 --- a/tests/Unit/PHP7_2/ClientContextTest.php +++ /dev/null @@ -1,58 +0,0 @@ - [[ - 'api_root' => [ - Client::TEST_MODE => self::FAKE_API_URI, - Client::LIVE_MODE => self::FAKE_API_URI - ], - 'force_tls' => 0, - 'mode' => Client::TEST_MODE, - 'logger' => new NullLogger() - ]], - 'user_agent_component' => [[ - 'api_root' => [ - Client::TEST_MODE => self::FAKE_API_URI, - Client::LIVE_MODE => self::FAKE_API_URI - ], - 'force_tls' => 0, - 'mode' => Client::TEST_MODE, - 'logger' => new NullLogger(), - 'user_agent_component' => ['Magento' => '12.3'] - ]], - ]; - } - - /** - * @dataProvider getClientconfigOptions - * @return void - * @throws ParamsError - */ - public function testClientContext($options) - { - $context = new ClientContext("sk_fake_api_key", $options); - - $this->assertInstanceOf(ClientContext::class, $context); - } -} diff --git a/tests/Unit/PHP7_2/ClientOptionsValidatorTest.php b/tests/Unit/PHP7_2/ClientOptionsValidatorTest.php deleted file mode 100644 index 36aab0a9..00000000 --- a/tests/Unit/PHP7_2/ClientOptionsValidatorTest.php +++ /dev/null @@ -1,155 +0,0 @@ - [ - Client::TEST_MODE => Client::SANDBOX_API_URL, - Client::LIVE_MODE => Client::LIVE_API_URL - ], - 'force_tls' => 2, - 'mode' => Client::LIVE_MODE, - 'logger' => new NullLogger() - ] - ], - [ - [ - 'api_root' => [ - Client::TEST_MODE => self::FAKE_API_URI, - Client::LIVE_MODE => self::FAKE_API_URI - ], - 'force_tls' => 0, - 'mode' => Client::TEST_MODE, - 'logger' => new NullLogger() - ], - [ - 'api_root' => [ - Client::TEST_MODE => self::FAKE_API_URI, - Client::LIVE_MODE => self::FAKE_API_URI - ], - 'force_tls' => 0, - 'mode' => Client::TEST_MODE, - 'logger' => new NullLogger() - ] - ], - [ - [ - 'api_root' => self::FAKE_API_URI, - 'force_tls' => true, - 'logger' => new NullLogger() - ], - [ - 'api_root' => [ - Client::TEST_MODE => self::FAKE_API_URI, - Client::LIVE_MODE => self::FAKE_API_URI - ], - 'force_tls' => 2, - 'mode' => Client::LIVE_MODE, - 'logger' => new NullLogger() - ] - ], - [ - [ - 'user_agent_component' => [ - 'PrestaShop' => 2.3, - 'Alma for PrestaShop' => 'v2.3', - ] - ], - [ - 'api_root' => [ - Client::TEST_MODE => Client::SANDBOX_API_URL, - Client::LIVE_MODE => Client::LIVE_API_URL - ], - 'force_tls' => 2, - 'mode' => Client::LIVE_MODE, - 'logger' => new NullLogger(), - 'user_agent_component' => [ - 'PrestaShop' => 2.3, - 'Alma for PrestaShop' => 'v2.3', - ] - ] - ] - ]; - } - - /** - * @dataProvider getClientOptions - * @return void - * @throws ParamsError - */ - public function testClientOptionsValidator($options, $expectedResult) - { - $validatedConfig = ClientOptionsValidator::validateOptions($options); - - $this->assertEquals($expectedResult, $validatedConfig); - } - - /** - * Return faulty options to test ClientOptionsValidator::validateOptions - * @return array - */ - public function getInvalidClientOptions() - { - return [ - 'invalid api_root' => [ - [ - 'api_root' => [ - 'something wrong' => Client::SANDBOX_API_URL, - 'something wronger' => Client::LIVE_API_URL - ], - ], - ], - 'invalid tls' => [ - [ - 'force_tls' => -1, - ], - ], - 'invalid mode' => [ - [ - 'mode' => 'sad', - ], - ], - 'invalid user_agent_component' => [ - [ - 'user_agent_component' => [ - 'I dont give a key:value pair', - ] - ], - ], - ]; - } - - /** - * @dataProvider getInvalidClientOptions - * @return void - * @throws ParamsError - */ - public function testFaultyClientOptionsValidator($options) - { - $this->expectException(ParamsError::class); - ClientOptionsValidator::validateOptions($options); - } -} diff --git a/tests/Unit/PHP7_2/Endpoints/PaymentsTest.php b/tests/Unit/PHP7_2/Endpoints/PaymentsTest.php deleted file mode 100644 index 1e2b31f7..00000000 --- a/tests/Unit/PHP7_2/Endpoints/PaymentsTest.php +++ /dev/null @@ -1,511 +0,0 @@ -assertEquals(true, method_exists($payments, 'partialRefund')); - $this->assertEquals(true, method_exists($payments, 'fullRefund')); - # ensure backward compatibility - $this->assertEquals(true, method_exists($payments, 'refund')); - } - - /** - * Mock ClientContext, Response and Request to allow us to test - * Payment without sending any requests - */ - private function mockServerRequest() - { - // ClientContext - $clientContext = Mockery::mock(ClientContext::class); - $clientContext->shouldReceive('urlFor'); - $clientContext->shouldReceive('getUserAgentString'); - $clientContext->shouldReceive('forcedTLSVersion'); - - // Response - $json = '{ - "payment_plan":[ - { - "customer_can_postpone":false, - "customer_fee":100, - "customer_interest":0, - "date_paid":1649672472, - "due_date":1649672451, - "id":"installment_11uPRjPgPJ5jxmEEXxIPPOvVA3Fh7cg13m", - "original_purchase_amount":11733, - "purchase_amount":11733, - "state":"paid" - }, - { - "customer_can_postpone":false, - "customer_fee":0, - "customer_interest":0, - "date_paid":null, - "due_date":1652264451, - "id":"installment_11uPRjP4a3cFQvoM1lehDnpxa2tYm2Hy0I", - "original_purchase_amount":11733, - "purchase_amount":0, - "state":"paid" - }, - { - "customer_can_postpone":false, - "customer_fee":0, - "customer_interest":0, - "date_paid":null, - "due_date":1654942851, - "id":"installment_11uPRjP79fG5QtHO54lSYsnDvyHb56oeCn", - "original_purchase_amount":11733, - "purchase_amount":0, - "state":"paid" - } - ], - "orders":[ - { - "comment":null, - "created":1649672451, - "customer_url":null, - "data":{}, - "id":"order_11uPRjP4L9Dgbttx3cFUKGFPppdZIlrR2V", - "merchant_reference":"00000206", - "merchant_url":null, - "payment":"payment_11uPRjP5FaIYygQao8WdMQFnKRMOV14frx" - } - ], - "refunds":[ - { - "amount":35299, - "created":1649770695, - "from_payment_cancellation":false, - "id":"refund_11uPrHz4TfHmQrD1OkYyWb4hPuq3673Vqm", - "merchant_reference":null, - "payment":"payment_11uPRjP5FaIYygQao8WdMQFnKRMOV14frx", - "payment_refund_amount":11833, - "rebate_amount":23466 - } - ] - }'; - - $responseMock = Mockery::mock(Response::class); - $responseMock->shouldReceive('isError')->andReturn(false); - $responseMock->json = json_decode($json, true); - - // Request - $requestMock = Mockery::mock(Request::class); - $requestMock->shouldReceive('setRequestBody'); - $requestMock->shouldReceive('post')->andReturn($responseMock); - return $requestMock; - } - - /** - * Return input to test testPartialRefund - * @return array[] - */ - public function getPartialRefundData() - { - return [ - [[ - 'id' => "some_id", - 'amount' => 15000, - 'merchant_ref' => self::MERCHANT_REF, - 'comment' => "some comment" - ]], - [[ - 'id' => "some_id", - 'amount' => 15000, - 'merchant_ref' => self::MERCHANT_REF - ]], - [[ - 'id' => "some_id", - 'amount' => 15000 - ]] - ]; - } - - private function callPartialRefund($payments, $data) - { - if (isset($data['merchant_ref']) && isset($data['comment'])) { - $payments->partialRefund($data['id'], $data['amount'], $data['merchant_ref'], $data['comment']); - } elseif (isset($data['merchant_ref'])) { - $payments->partialRefund($data['id'], $data['amount'], $data['merchant_ref']); - } elseif (isset($data['comment'])) { - $payments->partialRefund($data['id'], $data['amount'], '', $data['comment']); - } else { - $payments->partialRefund($data['id'], $data['amount']); - } - } - - /** - * Test the partialRefund method with valid datas - * @dataProvider getPartialRefundData - * @return void - */ - public function testPartialRefund($data) - { - $clientContext = Mockery::mock(ClientContext::class); - - // Payment - $payments = Mockery::mock(Payments::class) - ->shouldAllowMockingProtectedMethods() - ->makePartial() - ; - $id = $data['id']; - $payments->shouldReceive('request') - ->with("/v1/payments/$id/refund") - ->once() - ->andReturn($this->mockServerRequest()) - ; - $payments->setClientContext($clientContext); - - /* Test */ - $this->callPartialRefund($payments, $data); - } - - /** - * Return invalid input to test testPartialRefund - * @return array[] - */ - public function getPartialRefundInvalidData() - { - return [ - [[ - 'id' => "negative_amount", - 'amount' => -1 - ], ParamsError::class], - [[ - 'id' => "", - 'amount' => 1500, - 'merchant_ref' => "no id", - ], ParamsError::class], - ]; - } - - /** - * Test the partialRefund method with valid datas - * @dataProvider getPartialRefundInvalidData - * @return void - */ - public function testInvalidPartialRefund($data, $expectedException) - { - $clientContext = Mockery::mock(ClientContext::class); - - // Payment - $payments = Mockery::mock(Payments::class) - ->shouldAllowMockingProtectedMethods() - ->makePartial() - ; - $id = $data['id']; - $payments->shouldReceive('request') - ->with("/v1/payments/$id/refund") - ->andReturn($this->mockServerRequest()) - ; - $payments->setClientContext($clientContext); - - $this->expectException($expectedException); - - /* Test */ - $this->callPartialRefund($payments, $data); - } - - - private function callFullRefund($payments, $data) - { - if (isset($data['merchant_ref']) && isset($data['comment'])) { - $payments->fullRefund($data['id'], $data['merchant_ref'], $data['comment']); - } elseif (isset($data['merchant_ref'])) { - $payments->fullRefund($data['id'], $data['merchant_ref']); - } elseif (isset($data['comment'])) { - $payments->fullRefund($data['id'], '', $data['comment']); - } else { - $payments->fullRefund($data['id']); - } - } - - /** - * Return input to test testFullRefund - * @return array[] - */ - public static function getFullRefundData() - { - return [ - [[ - 'id' => "some_id", - 'merchant_ref' => self::MERCHANT_REF, - 'comment' => "some comment" - ]], - [[ - 'id' => "some_id", - 'merchant_ref' => self::MERCHANT_REF - ]], - [[ - 'id' => "some_id", - ]] - ]; - } - - /** - * Test the fullRefund method with valid datas - * @dataProvider getFullRefundData - * @return void - */ - public function testFullRefund($data) - { - $clientContext = Mockery::mock(ClientContext::class); - - // Payment - $payments = Mockery::mock(Payments::class) - ->shouldAllowMockingProtectedMethods() - ->makePartial() - ; - $id = $data['id']; - $payments->shouldReceive('request') - ->with("/v1/payments/$id/refund") - ->once() - ->andReturn($this->mockServerRequest()) - ; - $payments->setClientContext($clientContext); - - /* Test */ - $this->callFullRefund($payments, $data); - } - - /** - * Return input to test testRefund - * @return array[] - */ - public function getRefundData() - { - return [ - [[ - 'id' => "some_id", - 'amount' => 15000, - 'merchant_ref' => self::MERCHANT_REF, - ]], - [[ - 'id' => "some_id", - ]], - [[ - 'id' => "some_id", - 'amount' => 15000 - ]] - ]; - } - - private function callRefund($payments, $data) - { - if (isset($data['merchant_ref']) && isset($data['amount'])) { - $payments->refund($data['id'], $data['amount'], $data['merchant_ref']); - } elseif (isset($data['amount'])) { - $payments->refund($data['id'], $data['amount']); - } else { - $payments->refund($data['id']); - } - } - - /** - * Test the fullRefund method with valid datas - * Important to ensure we didn't break compatibility with 1.x.x versions - * @dataProvider getRefundData - * @return void - */ - public function testRefund($data) - { - $clientContext = Mockery::mock(ClientContext::class); - - // Payment - $payments = Mockery::mock(Payments::class) - ->shouldAllowMockingProtectedMethods() - ->makePartial() - ; - $id = $data['id']; - $payments->shouldReceive('request') - ->with("/v1/payments/$id/refund") - ->once() - ->andReturn($this->mockServerRequest()) - ; - $payments->setClientContext($clientContext); - - /* Test */ - $this->callRefund($payments, $data); - } - - /** - * Return invalid input to test testFullRefund - * @return array[] - */ - public function getFullRefundInvalidData() - { - return [ - [[ - 'id' => "", - 'merchant_ref' => "no id", - ], ParamsError::class], - ]; - } - - /** - * Test the fullRefund method with valid datas - * @dataProvider getFullRefundInvalidData - * @return void - */ - public function testInvalidFullRefund($data, $expectedException) - { - $clientContext = Mockery::mock(ClientContext::class); - - // Payment - $payments = Mockery::mock(Payments::class) - ->shouldAllowMockingProtectedMethods() - ->makePartial() - ; - $id = $data['id']; - $payments->shouldReceive('request') - ->with("/v1/payments/$id/refund") - ->andReturn($this->mockServerRequest()) - ; - $payments->setClientContext($clientContext); - - $this->expectException($expectedException); - - /* Test */ - $this->callFullRefund($payments, $data); - } - - /** - * Mock ClientContext, Response and Request to allow us to test - * Payment without sending any requests but returns an error - */ - private function mockServerRequestError() - { - // ClientContext - $clientContext = Mockery::mock(ClientContext::class); - $clientContext->shouldReceive('urlFor'); - $clientContext->shouldReceive('getUserAgentString'); - $clientContext->shouldReceive('forcedTLSVersion'); - - // Response - $json = '{ - "payment_plan":[ - { - "customer_can_postpone":false, - "customer_fee":100, - "customer_interest":0, - "date_paid":1649672472, - "due_date":1649672451, - "id":"installment_11uPRjPgPJ5jxmEEXxIPPOvVA3Fh7cg13m", - "original_purchase_amount":11733, - "purchase_amount":11733, - "state":"paid" - }, - { - "customer_can_postpone":false, - "customer_fee":0, - "customer_interest":0, - "date_paid":null, - "due_date":1652264451, - "id":"installment_11uPRjP4a3cFQvoM1lehDnpxa2tYm2Hy0I", - "original_purchase_amount":11733, - "purchase_amount":0, - "state":"paid" - }, - { - "customer_can_postpone":false, - "customer_fee":0, - "customer_interest":0, - "date_paid":null, - "due_date":1654942851, - "id":"installment_11uPRjP79fG5QtHO54lSYsnDvyHb56oeCn", - "original_purchase_amount":11733, - "purchase_amount":0, - "state":"paid" - } - ], - "orders":[ - { - "comment":null, - "created":1649672451, - "customer_url":null, - "data":{}, - "id":"order_11uPRjP4L9Dgbttx3cFUKGFPppdZIlrR2V", - "merchant_reference":"00000206", - "merchant_url":null, - "payment":"payment_11uPRjP5FaIYygQao8WdMQFnKRMOV14frx" - } - ], - "refunds":[ - { - "amount":35299, - "created":1649770695, - "from_payment_cancellation":false, - "id":"refund_11uPrHz4TfHmQrD1OkYyWb4hPuq3673Vqm", - "merchant_reference":null, - "payment":"payment_11uPRjP5FaIYygQao8WdMQFnKRMOV14frx", - "payment_refund_amount":11833, - "rebate_amount":23466 - } - ] - }'; - - $responseMock = Mockery::mock(Response::class); - $responseMock->shouldReceive('isError')->andReturn(true); - $responseMock->json = json_decode($json, true); - $responseMock->errorMessage = "a very important error message"; - - // Request - $requestMock = Mockery::mock(Request::class); - $requestMock->shouldReceive('setRequestBody'); - $requestMock->shouldReceive('post')->andReturn($responseMock); - return $requestMock; - } - - public function testFullRefundRequestError() - { - // Input - $clientContext = Mockery::mock(ClientContext::class); - $id = "some_id"; - - // Payment - $payments = Mockery::mock(Payments::class) - ->shouldAllowMockingProtectedMethods() - ->makePartial() - ; - $payments->shouldReceive('request') - ->with("/v1/payments/$id/refund") - ->once() - ->andReturn($this->mockServerRequestError()) - ; - $payments->setClientContext($clientContext); - - $this->expectException(RequestError::class); - - /* Test */ - $payments->fullRefund($id); - } - - public function tearDown() : void - { - Mockery::close(); - } -} diff --git a/tests/Unit/PHP8_1/Endpoints/InsuranceTest.php b/tests/Unit/PHP8_1/Endpoints/InsuranceTest.php deleted file mode 100644 index de3a2ba1..00000000 --- a/tests/Unit/PHP8_1/Endpoints/InsuranceTest.php +++ /dev/null @@ -1,144 +0,0 @@ -clientContext = $this->createMock(ClientContext::class); - - } - - public function testInsuranceEligibilityMethodExist(): void - { - $insurance = new Insurance($this->clientContext); - $this->assertTrue(method_exists($insurance, 'getInsuranceContract')); - } - - /** - * @dataProvider requestDataProviderRightParams - * @return void - * @throws ParamsException - */ - public function testGetRequestIsCalled($productId): void - { - - $responseMock = Mockery::mock(Response::class); - $responseMock->shouldReceive('isError')->once()->andReturn(false); - - $requestObject = Mockery::mock(Request::class); - $requestObject->shouldReceive('get')->once()->andReturn($responseMock); - - $insurance = Mockery::mock(Insurance::class)->shouldAllowMockingProtectedMethods()->makePartial(); - $insurance->shouldReceive('request') - ->with('/v1/insurance/insurance-contracts?cms_product_id='.$productId) - ->once() - ->andReturn($requestObject) - ; - $insurance->setClientContext($this->clientContext); - - $insurance->getInsuranceContract($productId); - Mockery::close(); - } - - - /** - * @dataProvider requestDataProvider - * @param $productId - * @return void - */ - public function testGetRequestWithWrongParams($productId):void - { - $requestObject = Mockery::mock(Request::class); - $requestObject->shouldNotReceive('get'); - - $insurance = Mockery::mock(Insurance::class)->shouldAllowMockingProtectedMethods()->makePartial(); - $insurance->shouldNotReceive('request'); - $insurance->setClientContext($this->clientContext); - $this->expectException(ParamsException::class); - $insurance->getInsuranceContract($productId); - Mockery::close(); - } - - public function testApiResponseErrorThrowRequestException() - { - $productId = '18-24'; - $responseMock = Mockery::mock(Response::class); - $responseMock->shouldReceive('isError')->once()->andReturn(true); - - $requestObject = Mockery::mock(Request::class)->shouldAllowMockingProtectedMethods(); - $requestObject->shouldReceive('get')->once()->andReturn($responseMock); - - $insurance = Mockery::mock(Insurance::class)->shouldAllowMockingProtectedMethods()->makePartial(); - $insurance->shouldReceive('request') - ->with('/v1/insurance/insurance-contracts?cms_product_id='.$productId) - ->once() - ->andReturn($requestObject) - ; - - $insurance->setClientContext($this->clientContext); - $this->expectException(RequestError::class); - $insurance->getInsuranceContract($productId); - Mockery::close(); - } - - public static function requestDataProvider(): array - { - return [ - 'Throw exception with null' => [ - 'product_id' => null - ], - 'Throw exception with array' => [ - 'product_id' => ['10','13'] - ], - 'Throw exception with class' => [ - 'product_id' => new \stdClass() - ], - 'Throw exception with bool' => [ - 'product_id' => true - ], - 'Throw exception with string and special characters' => [ - 'product_id' => 'Une Str|ng [Avec] des *' - ], - 'Throw exception with string and spacial characters 2' => [ - 'product_id' => 'alma-%product' - ], - 'Throw exception with empty string' => [ - 'product_id' => '' - ] - ]; - } - public static function requestDataProviderRightParams(): array - { - return [ - 'call get with a string' => [ - 'product_id' => '18' - ], - 'call get with an integer' => [ - 'product_id' => 18 - ], - 'Call get with a string and space' => [ - 'product_id' => 'Alma insurance2 product' - ], - 'Call get with a string and - ' => [ - 'product_id' => 'Alma01-insurance-product' - ] - ]; - } - -} diff --git a/tests/Unit/PHP8_1/Endpoints/PaymentsTest.php b/tests/Unit/PHP8_1/Endpoints/PaymentsTest.php deleted file mode 100644 index 4d63e1c9..00000000 --- a/tests/Unit/PHP8_1/Endpoints/PaymentsTest.php +++ /dev/null @@ -1,511 +0,0 @@ -assertEquals(true, method_exists($payments, 'partialRefund')); - $this->assertEquals(true, method_exists($payments, 'fullRefund')); - # ensure backward compatibility - $this->assertEquals(true, method_exists($payments, 'refund')); - } - - /** - * Mock ClientContext, Response and Request to allow us to test - * Payment without sending any requests - */ - private function mockServerRequest() - { - // ClientContext - $clientContext = Mockery::mock(ClientContext::class); - $clientContext->shouldReceive('urlFor'); - $clientContext->shouldReceive('getUserAgentString'); - $clientContext->shouldReceive('forcedTLSVersion'); - - // Response - $json = '{ - "payment_plan":[ - { - "customer_can_postpone":false, - "customer_fee":100, - "customer_interest":0, - "date_paid":1649672472, - "due_date":1649672451, - "id":"installment_11uPRjPgPJ5jxmEEXxIPPOvVA3Fh7cg13m", - "original_purchase_amount":11733, - "purchase_amount":11733, - "state":"paid" - }, - { - "customer_can_postpone":false, - "customer_fee":0, - "customer_interest":0, - "date_paid":null, - "due_date":1652264451, - "id":"installment_11uPRjP4a3cFQvoM1lehDnpxa2tYm2Hy0I", - "original_purchase_amount":11733, - "purchase_amount":0, - "state":"paid" - }, - { - "customer_can_postpone":false, - "customer_fee":0, - "customer_interest":0, - "date_paid":null, - "due_date":1654942851, - "id":"installment_11uPRjP79fG5QtHO54lSYsnDvyHb56oeCn", - "original_purchase_amount":11733, - "purchase_amount":0, - "state":"paid" - } - ], - "orders":[ - { - "comment":null, - "created":1649672451, - "customer_url":null, - "data":{}, - "id":"order_11uPRjP4L9Dgbttx3cFUKGFPppdZIlrR2V", - "merchant_reference":"00000206", - "merchant_url":null, - "payment":"payment_11uPRjP5FaIYygQao8WdMQFnKRMOV14frx" - } - ], - "refunds":[ - { - "amount":35299, - "created":1649770695, - "from_payment_cancellation":false, - "id":"refund_11uPrHz4TfHmQrD1OkYyWb4hPuq3673Vqm", - "merchant_reference":null, - "payment":"payment_11uPRjP5FaIYygQao8WdMQFnKRMOV14frx", - "payment_refund_amount":11833, - "rebate_amount":23466 - } - ] - }'; - - $responseMock = Mockery::mock(Response::class); - $responseMock->shouldReceive('isError')->andReturn(false); - $responseMock->json = json_decode($json, true); - - // Request - $requestMock = Mockery::mock(Request::class); - $requestMock->shouldReceive('setRequestBody'); - $requestMock->shouldReceive('post')->andReturn($responseMock); - return $requestMock; - } - - /** - * Return input to test testPartialRefund - * @return array[] - */ - public static function getPartialRefundData() - { - return [ - [[ - 'id' => "some_id", - 'amount' => 15000, - 'merchant_ref' => self::MERCHANT_REF, - 'comment' => "some comment" - ]], - [[ - 'id' => "some_id", - 'amount' => 15000, - 'merchant_ref' => self::MERCHANT_REF - ]], - [[ - 'id' => "some_id", - 'amount' => 15000 - ]] - ]; - } - - private function callPartialRefund($payments, $data) - { - if (isset($data['merchant_ref']) && isset($data['comment'])) { - $payments->partialRefund($data['id'], $data['amount'], $data['merchant_ref'], $data['comment']); - } elseif (isset($data['merchant_ref'])) { - $payments->partialRefund($data['id'], $data['amount'], $data['merchant_ref']); - } elseif (isset($data['comment'])) { - $payments->partialRefund($data['id'], $data['amount'], '', $data['comment']); - } else { - $payments->partialRefund($data['id'], $data['amount']); - } - } - - /** - * Test the partialRefund method with valid datas - * @dataProvider getPartialRefundData - * @return void - */ - public function testPartialRefund($data) - { - $clientContext = Mockery::mock(ClientContext::class); - - // Payment - $payments = Mockery::mock(Payments::class) - ->shouldAllowMockingProtectedMethods() - ->makePartial() - ; - $id = $data['id']; - $payments->shouldReceive('request') - ->with("/v1/payments/$id/refund") - ->once() - ->andReturn($this->mockServerRequest()) - ; - $payments->setClientContext($clientContext); - - /* Test */ - $this->callPartialRefund($payments, $data); - } - - /** - * Return invalid input to test testPartialRefund - * @return array[] - */ - public static function getPartialRefundInvalidData() - { - return [ - [[ - 'id' => "negative_amount", - 'amount' => -1 - ], ParamsError::class], - [[ - 'id' => "", - 'amount' => 1500, - 'merchant_ref' => "no id", - ], ParamsError::class], - ]; - } - - /** - * Test the partialRefund method with valid datas - * @dataProvider getPartialRefundInvalidData - * @return void - */ - public function testInvalidPartialRefund($data, $expectedException) - { - $clientContext = Mockery::mock(ClientContext::class); - - // Payment - $payments = Mockery::mock(Payments::class) - ->shouldAllowMockingProtectedMethods() - ->makePartial() - ; - $id = $data['id']; - $payments->shouldReceive('request') - ->with("/v1/payments/$id/refund") - ->andReturn($this->mockServerRequest()) - ; - $payments->setClientContext($clientContext); - - $this->expectException($expectedException); - - /* Test */ - $this->callPartialRefund($payments, $data); - } - - - private function callFullRefund($payments, $data) - { - if (isset($data['merchant_ref']) && isset($data['comment'])) { - $payments->fullRefund($data['id'], $data['merchant_ref'], $data['comment']); - } elseif (isset($data['merchant_ref'])) { - $payments->fullRefund($data['id'], $data['merchant_ref']); - } elseif (isset($data['comment'])) { - $payments->fullRefund($data['id'], '', $data['comment']); - } else { - $payments->fullRefund($data['id']); - } - } - - /** - * Return input to test testFullRefund - * @return array[] - */ - public static function getFullRefundData() - { - return [ - [[ - 'id' => "some_id", - 'merchant_ref' => self::MERCHANT_REF, - 'comment' => "some comment" - ]], - [[ - 'id' => "some_id", - 'merchant_ref' => self::MERCHANT_REF - ]], - [[ - 'id' => "some_id", - ]] - ]; - } - - /** - * Test the fullRefund method with valid datas - * @dataProvider getFullRefundData - * @return void - */ - public function testFullRefund($data) - { - $clientContext = Mockery::mock(ClientContext::class); - - // Payment - $payments = Mockery::mock(Payments::class) - ->shouldAllowMockingProtectedMethods() - ->makePartial() - ; - $id = $data['id']; - $payments->shouldReceive('request') - ->with("/v1/payments/$id/refund") - ->once() - ->andReturn($this->mockServerRequest()) - ; - $payments->setClientContext($clientContext); - - /* Test */ - $this->callFullRefund($payments, $data); - } - - /** - * Return input to test testRefund - * @return array[] - */ - public static function getRefundData() - { - return [ - [[ - 'id' => "some_id", - 'amount' => 15000, - 'merchant_ref' => self::MERCHANT_REF, - ]], - [[ - 'id' => "some_id", - ]], - [[ - 'id' => "some_id", - 'amount' => 15000 - ]] - ]; - } - - private function callRefund($payments, $data) - { - if (isset($data['merchant_ref']) && isset($data['amount'])) { - $payments->refund($data['id'], $data['amount'], $data['merchant_ref']); - } elseif (isset($data['amount'])) { - $payments->refund($data['id'], $data['amount']); - } else { - $payments->refund($data['id']); - } - } - - /** - * Test the fullRefund method with valid datas - * Important to ensure we didn't break compatibility with 1.x.x versions - * @dataProvider getRefundData - * @return void - */ - public function testRefund($data) - { - $clientContext = Mockery::mock(ClientContext::class); - - // Payment - $payments = Mockery::mock(Payments::class) - ->shouldAllowMockingProtectedMethods() - ->makePartial() - ; - $id = $data['id']; - $payments->shouldReceive('request') - ->with("/v1/payments/$id/refund") - ->once() - ->andReturn($this->mockServerRequest()) - ; - $payments->setClientContext($clientContext); - - /* Test */ - $this->callRefund($payments, $data); - } - - /** - * Return invalid input to test testFullRefund - * @return array[] - */ - public static function getFullRefundInvalidData() - { - return [ - [[ - 'id' => "", - 'merchant_ref' => "no id", - ], ParamsError::class], - ]; - } - - /** - * Test the fullRefund method with valid datas - * @dataProvider getFullRefundInvalidData - * @return void - */ - public function testInvalidFullRefund($data, $expectedException) - { - $clientContext = Mockery::mock(ClientContext::class); - - // Payment - $payments = Mockery::mock(Payments::class) - ->shouldAllowMockingProtectedMethods() - ->makePartial() - ; - $id = $data['id']; - $payments->shouldReceive('request') - ->with("/v1/payments/$id/refund") - ->andReturn($this->mockServerRequest()) - ; - $payments->setClientContext($clientContext); - - $this->expectException($expectedException); - - /* Test */ - $this->callFullRefund($payments, $data); - } - - /** - * Mock ClientContext, Response and Request to allow us to test - * Payment without sending any requests but returns an error - */ - private function mockServerRequestError() - { - // ClientContext - $clientContext = Mockery::mock(ClientContext::class); - $clientContext->shouldReceive('urlFor'); - $clientContext->shouldReceive('getUserAgentString'); - $clientContext->shouldReceive('forcedTLSVersion'); - - // Response - $json = '{ - "payment_plan":[ - { - "customer_can_postpone":false, - "customer_fee":100, - "customer_interest":0, - "date_paid":1649672472, - "due_date":1649672451, - "id":"installment_11uPRjPgPJ5jxmEEXxIPPOvVA3Fh7cg13m", - "original_purchase_amount":11733, - "purchase_amount":11733, - "state":"paid" - }, - { - "customer_can_postpone":false, - "customer_fee":0, - "customer_interest":0, - "date_paid":null, - "due_date":1652264451, - "id":"installment_11uPRjP4a3cFQvoM1lehDnpxa2tYm2Hy0I", - "original_purchase_amount":11733, - "purchase_amount":0, - "state":"paid" - }, - { - "customer_can_postpone":false, - "customer_fee":0, - "customer_interest":0, - "date_paid":null, - "due_date":1654942851, - "id":"installment_11uPRjP79fG5QtHO54lSYsnDvyHb56oeCn", - "original_purchase_amount":11733, - "purchase_amount":0, - "state":"paid" - } - ], - "orders":[ - { - "comment":null, - "created":1649672451, - "customer_url":null, - "data":{}, - "id":"order_11uPRjP4L9Dgbttx3cFUKGFPppdZIlrR2V", - "merchant_reference":"00000206", - "merchant_url":null, - "payment":"payment_11uPRjP5FaIYygQao8WdMQFnKRMOV14frx" - } - ], - "refunds":[ - { - "amount":35299, - "created":1649770695, - "from_payment_cancellation":false, - "id":"refund_11uPrHz4TfHmQrD1OkYyWb4hPuq3673Vqm", - "merchant_reference":null, - "payment":"payment_11uPRjP5FaIYygQao8WdMQFnKRMOV14frx", - "payment_refund_amount":11833, - "rebate_amount":23466 - } - ] - }'; - - $responseMock = Mockery::mock(Response::class); - $responseMock->shouldReceive('isError')->andReturn(true); - $responseMock->json = json_decode($json, true); - $responseMock->errorMessage = "a very important error message"; - - // Request - $requestMock = Mockery::mock(Request::class); - $requestMock->shouldReceive('setRequestBody'); - $requestMock->shouldReceive('post')->andReturn($responseMock); - return $requestMock; - } - - public function testFullRefundRequestError() - { - // Input - $clientContext = Mockery::mock(ClientContext::class); - $id = "some_id"; - - // Payment - $payments = Mockery::mock(Payments::class) - ->shouldAllowMockingProtectedMethods() - ->makePartial() - ; - $payments->shouldReceive('request') - ->with("/v1/payments/$id/refund") - ->once() - ->andReturn($this->mockServerRequestError()) - ; - $payments->setClientContext($clientContext); - - $this->expectException(RequestError::class); - - /* Test */ - $payments->fullRefund($id); - } - - public function tearDown() : void - { - Mockery::close(); - } -} diff --git a/tests/Unit/PHP8_1/RequestErrorTest.php b/tests/Unit/PHP8_1/RequestErrorTest.php deleted file mode 100644 index 5133ad08..00000000 --- a/tests/Unit/PHP8_1/RequestErrorTest.php +++ /dev/null @@ -1,59 +0,0 @@ -errorMessage = $validExpected; - - $noMessageExpected = 'error message hidden in response'; - $noMessageResponse = Mockery::mock(Response::class); - $noMessageResponse->errorMessage = null; - $noMessageResponse->json = [ - 'errors' => [ - 0 => [ - 'message' => $noMessageExpected - ] - ] - ]; - - return [ - 'valid example' => [ - null, $validResponse, $validExpected, - ], - 'error message hidden in response' => [ - null, $noMessageResponse, $noMessageExpected, - ] - ]; - } - - /** - * @dataProvider getErrorMessageProvider - * @return void - * @throws ParamsError - */ - public function testGetErrorMessage($req, $res, $expected) - { - $requestError = new RequestError((string) $res->errorMessage, $req, $res); - - $this->assertEquals($expected, $requestError->getErrorMessage()); - } -} diff --git a/tests/Unit/PHP7_2/RequestErrorTest.php b/tests/Unit/RequestErrorTest.php similarity index 79% rename from tests/Unit/PHP7_2/RequestErrorTest.php rename to tests/Unit/RequestErrorTest.php index 9e754239..2c58c62c 100644 --- a/tests/Unit/PHP7_2/RequestErrorTest.php +++ b/tests/Unit/RequestErrorTest.php @@ -1,12 +1,11 @@ errorMessage = null; + $noMessageResponse->errorMessage = 'error message hidden in response'; $noMessageResponse->json = [ 'errors' => [ 0 => [ @@ -37,10 +36,10 @@ public function getErrorMessageProvider() return [ 'valid example' => [ - null, $validResponse, $validExpected, + "valid example", $validResponse, $validExpected, ], 'error message hidden in response' => [ - null, $noMessageResponse, $noMessageExpected, + "error message hidden in response", $noMessageResponse, $noMessageExpected, ] ]; } From 9cc295ece925d3f6e4653e0e68a0601048fdc4cd Mon Sep 17 00:00:00 2001 From: joyet simon <43644110+joyet-simon@users.noreply.github.com> Date: Fri, 7 Jun 2024 17:18:25 +0200 Subject: [PATCH 2/6] introduce some const for string in unit tests --- tests/Unit/Endpoints/InsuranceTest.php | 14 ++++++++------ tests/Unit/Endpoints/PaymentsTest.php | 6 +++--- tests/Unit/Entities/Insurance/ContractTest.php | 13 +++++++------ tests/Unit/RequestErrorTest.php | 11 ++++++----- 4 files changed, 24 insertions(+), 20 deletions(-) diff --git a/tests/Unit/Endpoints/InsuranceTest.php b/tests/Unit/Endpoints/InsuranceTest.php index 544c2f2d..d0c8a6a1 100644 --- a/tests/Unit/Endpoints/InsuranceTest.php +++ b/tests/Unit/Endpoints/InsuranceTest.php @@ -31,6 +31,8 @@ class InsuranceTest extends TestCase const TEST_CMSREFERENCE = '17-35'; const TEST_BIRTHDATE = '1988-08-22'; const INSURANCE_CUSTOMER_CART_PATH = '/v1/insurance/customer-carts'; + const INSURANCE_FILE_NAME = 'Alma mobility 1 an (vol+casse+assistance) - Alma}'; + const VOID_URL = '/subscriptionId1/void'; /** * @var ClientContext */ @@ -644,9 +646,9 @@ public function testApiResponseErrorThrowRequestException() public function testApiResponseInsuranceContract($insuranceContractExternalId, $cmsReference, $productPrice) { $files = [ - new File('Alma mobility 1 an (vol+casse+assistance) - Alma}', 'ipid-document', 'https://object-storage-s3-staging.s3.fr-par.scw.cloud/contracts/43acb66c-4b24-42d2-864a-24b4ade33e81/I6LK9O3XUNKNZPDTMH58IIK2HKBMRM2MIH-V0YGPECCD5Z20YIQUKXVCZYEU_TJD.pdf/OFXRU1UHY7J0CFO7X0Y24RSDMTG-W5BVB1GZRPPZFPSJRNIGGP2HXR2CEXIPBWZ-.pdf'), - new File('Alma mobility 1 an (vol+casse+assistance) - Alma}', 'fic-document', 'https://object-storage-s3-staging.s3.fr-par.scw.cloud/contracts/43acb66c-4b24-42d2-864a-24b4ade33e81/Y-PSWZG6-ADZ9MEY8PAZS2TMAUBXOLU6GYOLDWULMEAJB_VW0RGBKJTPMY7SPASN.pdf/UHSB9KVIGRLHP9DMXRZNCSWUGXCHS9VOW2EHAUNCYM_ANJIE7DOAKVLIH6EEOQYW.pdf'), - new File('Alma mobility 1 an (vol+casse+assistance) - Alma}', 'notice-document', 'https://object-storage-s3-staging.s3.fr-par.scw.cloud/contracts/43acb66c-4b24-42d2-864a-24b4ade33e81/JVPHA9RROHB6RPCG9K3VFG4EELBIMALK4QY2JVYEUTBFFT4SP1YN_ZUFXHOYRUSP.pdf/YTBTRJ6C9FFQFNW3234PHJJJT28VZR0FDOXVV0HV1SULI79S3UPSYRX7SZDNX1FX.pdf') + new File(self::INSURANCE_FILE_NAME, 'ipid-document', 'https://object-storage-s3-staging.s3.fr-par.scw.cloud/contracts/43acb66c-4b24-42d2-864a-24b4ade33e81/I6LK9O3XUNKNZPDTMH58IIK2HKBMRM2MIH-V0YGPECCD5Z20YIQUKXVCZYEU_TJD.pdf/OFXRU1UHY7J0CFO7X0Y24RSDMTG-W5BVB1GZRPPZFPSJRNIGGP2HXR2CEXIPBWZ-.pdf'), + new File(self::INSURANCE_FILE_NAME, 'fic-document', 'https://object-storage-s3-staging.s3.fr-par.scw.cloud/contracts/43acb66c-4b24-42d2-864a-24b4ade33e81/Y-PSWZG6-ADZ9MEY8PAZS2TMAUBXOLU6GYOLDWULMEAJB_VW0RGBKJTPMY7SPASN.pdf/UHSB9KVIGRLHP9DMXRZNCSWUGXCHS9VOW2EHAUNCYM_ANJIE7DOAKVLIH6EEOQYW.pdf'), + new File(self::INSURANCE_FILE_NAME, 'notice-document', 'https://object-storage-s3-staging.s3.fr-par.scw.cloud/contracts/43acb66c-4b24-42d2-864a-24b4ade33e81/JVPHA9RROHB6RPCG9K3VFG4EELBIMALK4QY2JVYEUTBFFT4SP1YN_ZUFXHOYRUSP.pdf/YTBTRJ6C9FFQFNW3234PHJJJT28VZR0FDOXVV0HV1SULI79S3UPSYRX7SZDNX1FX.pdf') ]; $contractExpected = new Contract( "insurance_contract_6XxGHbjr51CE5Oly8E2Amx", @@ -922,7 +924,7 @@ public function testCancelSubscriptionCallRequestWithSubscriptionArrayPayloadAnd $this->responseMock->shouldReceive('isError')->once()->andReturn(false); $this->requestObject->shouldReceive('post')->once()->andReturn($this->responseMock); $this->insuranceMock->shouldReceive('request') - ->with(self::INSURANCE_SUBSCRIPTIONS_PATH . '/subscriptionId1/void') + ->with(self::INSURANCE_SUBSCRIPTIONS_PATH . self::VOID_URL) ->once() ->andReturn($this->requestObject); $this->insuranceMock->cancelSubscription($subscriptionCancelPayload); @@ -970,7 +972,7 @@ public function testCancelSubscriptionCallRequestWithSubscriptionArrayPayloadAnd $this->responseMock->shouldReceive('isError')->once()->andReturn(true); $this->requestObject->shouldReceive('post')->once()->andReturn($this->responseMock); $this->insuranceMock->shouldReceive('request') - ->with(self::INSURANCE_SUBSCRIPTIONS_PATH . '/subscriptionId1/void') + ->with(self::INSURANCE_SUBSCRIPTIONS_PATH . self::VOID_URL) ->once() ->andReturn($this->requestObject); $this->insuranceMock->cancelSubscription($subscriptionCancelPayload); @@ -990,7 +992,7 @@ public function testCancelSubscriptionCallRequestWithSubscriptionArrayPayloadAnd $this->responseMock->responseCode = 410; $this->requestObject->shouldReceive('post')->once()->andReturn($this->responseMock); $this->insuranceMock->shouldReceive('request') - ->with(self::INSURANCE_SUBSCRIPTIONS_PATH . '/subscriptionId1/void') + ->with(self::INSURANCE_SUBSCRIPTIONS_PATH . self::VOID_URL) ->once() ->andReturn($this->requestObject); $this->insuranceMock->cancelSubscription($subscriptionCancelPayload); diff --git a/tests/Unit/Endpoints/PaymentsTest.php b/tests/Unit/Endpoints/PaymentsTest.php index 0e64a646..c693a4ab 100644 --- a/tests/Unit/Endpoints/PaymentsTest.php +++ b/tests/Unit/Endpoints/PaymentsTest.php @@ -292,10 +292,10 @@ public function testRefundMethodExist() $payments = new Payments($clientContext); - $this->assertEquals(true, method_exists($payments, 'partialRefund')); - $this->assertEquals(true, method_exists($payments, 'fullRefund')); + $this->assertTrue(method_exists($payments, 'partialRefund')); + $this->assertTrue(method_exists($payments, 'fullRefund')); # ensure backward compatibility - $this->assertEquals(true, method_exists($payments, 'refund')); + $this->assertTrue(method_exists($payments, 'refund')); } /** diff --git a/tests/Unit/Entities/Insurance/ContractTest.php b/tests/Unit/Entities/Insurance/ContractTest.php index b5c49c1d..38354343 100644 --- a/tests/Unit/Entities/Insurance/ContractTest.php +++ b/tests/Unit/Entities/Insurance/ContractTest.php @@ -9,6 +9,7 @@ class ContractTest extends TestCase { + const CONTRACT_FILE_NAME = 'Alma mobility 1 an (vol+casse+assistance) - Alma}'; /** * @var Contract $contract */ @@ -183,19 +184,19 @@ public static function contractDataProvider() public static function fileDataProvider() { $ipidFileData = new File( - 'Alma mobility 1 an (vol+casse+assistance) - Alma}', + self::CONTRACT_FILE_NAME, 'ipid-document', 'https://object-storage-s3-staging.s3.fr-par.scw.cloud/contracts/43acb66c-4b24-42d2-864a-24b4ade33e81/I6LK9O3XUNKNZPDTMH58IIK2HKBMRM2MIH-V0YGPECCD5Z20YIQUKXVCZYEU_TJD.pdf/OFXRU1UHY7J0CFO7X0Y24RSDMTG-W5BVB1GZRPPZFPSJRNIGGP2HXR2CEXIPBWZ-.pdf' ); $ipidFile = new File($ipidFileData->getName(), $ipidFileData->getType(), $ipidFileData->getPublicUrl()); $ficFileData = new File( - 'Alma mobility 1 an (vol+casse+assistance) - Alma}', + self::CONTRACT_FILE_NAME, 'fic-document', 'https://object-storage-s3-staging.s3.fr-par.scw.cloud/contracts/43acb66c-4b24-42d2-864a-24b4ade33e81/Y-PSWZG6-ADZ9MEY8PAZS2TMAUBXOLU6GYOLDWULMEAJB_VW0RGBKJTPMY7SPASN.pdf/UHSB9KVIGRLHP9DMXRZNCSWUGXCHS9VOW2EHAUNCYM_ANJIE7DOAKVLIH6EEOQYW.pdf' ); $ficFile = new File($ficFileData->getName(), $ficFileData->getType(), $ficFileData->getPublicUrl()); $noticeFileData = new File( - 'Alma mobility 1 an (vol+casse+assistance) - Alma}', + self::CONTRACT_FILE_NAME, 'notice-document', 'https://object-storage-s3-staging.s3.fr-par.scw.cloud/contracts/43acb66c-4b24-42d2-864a-24b4ade33e81/JVPHA9RROHB6RPCG9K3VFG4EELBIMALK4QY2JVYEUTBFFT4SP1YN_ZUFXHOYRUSP.pdf/YTBTRJ6C9FFQFNW3234PHJJJT28VZR0FDOXVV0HV1SULI79S3UPSYRX7SZDNX1FX.pdf' ); @@ -266,17 +267,17 @@ private static function getContractData() 'price' => 6000, //price in cent 'files' => [ new File( - 'Alma mobility 1 an (vol+casse+assistance) - Alma}', + self::CONTRACT_FILE_NAME, 'ipid-document', 'https://object-storage-s3-staging.s3.fr-par.scw.cloud/contracts/43acb66c-4b24-42d2-864a-24b4ade33e81/I6LK9O3XUNKNZPDTMH58IIK2HKBMRM2MIH-V0YGPECCD5Z20YIQUKXVCZYEU_TJD.pdf/OFXRU1UHY7J0CFO7X0Y24RSDMTG-W5BVB1GZRPPZFPSJRNIGGP2HXR2CEXIPBWZ-.pdf' ), new File( - 'Alma mobility 1 an (vol+casse+assistance) - Alma}', + self::CONTRACT_FILE_NAME, 'fic-document', 'https://object-storage-s3-staging.s3.fr-par.scw.cloud/contracts/43acb66c-4b24-42d2-864a-24b4ade33e81/Y-PSWZG6-ADZ9MEY8PAZS2TMAUBXOLU6GYOLDWULMEAJB_VW0RGBKJTPMY7SPASN.pdf/UHSB9KVIGRLHP9DMXRZNCSWUGXCHS9VOW2EHAUNCYM_ANJIE7DOAKVLIH6EEOQYW.pdf' ), new File( - 'Alma mobility 1 an (vol+casse+assistance) - Alma}', + self::CONTRACT_FILE_NAME, 'notice-document', 'https://object-storage-s3-staging.s3.fr-par.scw.cloud/contracts/43acb66c-4b24-42d2-864a-24b4ade33e81/JVPHA9RROHB6RPCG9K3VFG4EELBIMALK4QY2JVYEUTBFFT4SP1YN_ZUFXHOYRUSP.pdf/YTBTRJ6C9FFQFNW3234PHJJJT28VZR0FDOXVV0HV1SULI79S3UPSYRX7SZDNX1FX.pdf' ) diff --git a/tests/Unit/RequestErrorTest.php b/tests/Unit/RequestErrorTest.php index 2c58c62c..ee276f39 100644 --- a/tests/Unit/RequestErrorTest.php +++ b/tests/Unit/RequestErrorTest.php @@ -12,8 +12,9 @@ */ class RequestErrorTest extends TestCase { + const ERROR_MESSAGE = 'error message hidden in response'; - /** + /** * Return faulty options to test ClientOptionsValidator::validateOptions * @return array */ @@ -23,9 +24,9 @@ public static function getErrorMessageProvider() $validResponse = Mockery::mock(Response::class); $validResponse->errorMessage = $validExpected; - $noMessageExpected = 'error message hidden in response'; + $noMessageExpected = self::ERROR_MESSAGE; $noMessageResponse = Mockery::mock(Response::class); - $noMessageResponse->errorMessage = 'error message hidden in response'; + $noMessageResponse->errorMessage = self::ERROR_MESSAGE; $noMessageResponse->json = [ 'errors' => [ 0 => [ @@ -38,8 +39,8 @@ public static function getErrorMessageProvider() 'valid example' => [ "valid example", $validResponse, $validExpected, ], - 'error message hidden in response' => [ - "error message hidden in response", $noMessageResponse, $noMessageExpected, + self::ERROR_MESSAGE => [ + self::ERROR_MESSAGE, $noMessageResponse, $noMessageExpected, ] ]; } From f450c00fac28c5c7d7ae8f0ef3df94848a46f7c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guillaume=20Desv=C3=A9?= Date: Fri, 14 Jun 2024 10:26:27 +0200 Subject: [PATCH 3/6] Replace ': void' before legacy code tests --- .github/workflows/ci.yml | 22 ++++++++-------------- Taskfile.php.yml | 12 ++++++++---- phpunit.ci.xml | 2 +- tests/legacy_tests.sh | 14 ++++++++++++++ 4 files changed, 31 insertions(+), 19 deletions(-) create mode 100755 tests/legacy_tests.sh diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 824eb1f9..2c713d78 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -21,25 +21,15 @@ jobs: matrix: php: - version: 5.6 - unittest-version: Legacy - version: 7.0 - unittest-version: PHP7_0 - version: 7.1 - unittest-version: PHP7_0 - version: 7.2 - unittest-version: PHP7_2 - version: 7.3 - unittest-version: PHP7_2 - version: 7.4 - unittest-version: PHP7_2 - version: 8.0 - unittest-version: PHP7_2 - version: 8.1 - unittest-version: PHP8_1 - version: 8.2 - unittest-version: PHP8_1 - version: 8.3 - unittest-version: PHP8_1 steps: - name: Checkout repository @@ -59,14 +49,18 @@ jobs: - name: Install dependencies run: composer install --prefer-dist --no-progress - - name: Prepare unittests configuration - run: sed -i 's/{MYVERSION}/${{ matrix.php.unittest-version }}/g' phpunit.ci.xml - - name: Ensure source code is linted run: composer exec phpcs -- src/ + - name: Remove uncompliant statements in legacy code + if: contains(fromJson('["5.6", "7.0"]'), matrix.php.version) + run: | + # Replace string in files + string=': void' + grep -r -l "$string" tests/ | xargs sed -i "s/$string//g" + - name: PHPUnit - run: composer exec phpunit -- -c phpunit.ci.xml --coverage-xml ./.coverage + run: composer exec phpunit -- --configuration phpunit.ci.xml --coverage-xml ./.coverage env: XDEBUG_MODE: coverage diff --git a/Taskfile.php.yml b/Taskfile.php.yml index bd318813..7f126582 100644 --- a/Taskfile.php.yml +++ b/Taskfile.php.yml @@ -23,15 +23,19 @@ tasks: deps: - docker:build cmds: -# - sed 's/{MYVERSION}/{{ .PHPUNIT_VERSION }}/g' {{ .PHPUNIT_FILE }} > phpunit.xml - - docker compose run {{ .COMPOSE_SERVICE }} composer exec phpunit --verbose -- --testsuite "Alma PHP Client Unit Test Suite" + - >- + {{ if eq .PHP_VERSION "5.6" "7.0" }} + docker compose run {{ .COMPOSE_SERVICE }} ./tests/legacy_tests.sh + {{ else }} + docker compose run {{ .COMPOSE_SERVICE }} composer exec phpunit --verbose -- --configuration phpunit.dist.xml --testsuite "Alma PHP Client Unit Test Suite" + {{ end }} tests:integration: desc: Execute intregration tests deps: - docker:build cmds: - - sed 's/{MYVERSION}/{{ .PHPUNIT_VERSION }}/g' {{ .PHPUNIT_FILE }} > phpunit.xml + - sed 's/{MYVERSION}/{{ .PHPUNIT_VERSION }}/g' phpunit.dist.xml > phpunit.xml - docker compose run {{ .COMPOSE_SERVICE }} composer exec phpunit --verbose -- --testsuite "Alma PHP Client Integration Test Suite" shell: @@ -39,5 +43,5 @@ tasks: deps: - docker:build cmds: - - sed 's/{MYVERSION}/{{ .PHPUNIT_VERSION }}/g' {{ .PHPUNIT_FILE }} > phpunit.xml + - sed 's/{MYVERSION}/{{ .PHPUNIT_VERSION }}/g' phpunit.dist.xml > phpunit.xml - docker compose run {{ .COMPOSE_SERVICE }} bash diff --git a/phpunit.ci.xml b/phpunit.ci.xml index 891c8802..966eea12 100644 --- a/phpunit.ci.xml +++ b/phpunit.ci.xml @@ -12,7 +12,7 @@ - tests/Unit/{MYVERSION} + tests/Unit diff --git a/tests/legacy_tests.sh b/tests/legacy_tests.sh new file mode 100755 index 00000000..b21daaf9 --- /dev/null +++ b/tests/legacy_tests.sh @@ -0,0 +1,14 @@ +#!/usr/bin/env bash + +set -ex + +# Copy folder to /tmp +cp -r . /tmp/alma-php-client +cd /tmp/alma-php-client + +# Replace string in files +string=': void' +grep -r -l "$string" tests/ | xargs sed -i "s/$string//g" + +# Run tests +composer exec phpunit --verbose -- --configuration phpunit.dist.xml --testsuite "Alma PHP Client Unit Test Suite" From f95b12c6f99d4fc347008fbe419839055dbc0903 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guillaume=20Desv=C3=A9?= Date: Fri, 14 Jun 2024 10:27:40 +0200 Subject: [PATCH 4/6] Fix php version in CI matrix --- .github/workflows/ci.yml | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2c713d78..ea652382 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -20,16 +20,16 @@ jobs: fail-fast: false matrix: php: - - version: 5.6 - - version: 7.0 - - version: 7.1 - - version: 7.2 - - version: 7.3 - - version: 7.4 - - version: 8.0 - - version: 8.1 - - version: 8.2 - - version: 8.3 + - "5.6" + - "7.0" + - "7.1" + - "7.2" + - "7.3" + - "7.4" + - "8.0" + - "8.1" + - "8.2" + - "8.3" steps: - name: Checkout repository @@ -40,7 +40,7 @@ jobs: - name: Setup PHP uses: shivammathur/setup-php@v2 with: - php-version: ${{ matrix.php.version }} + php-version: ${{ matrix.php }} tools: composer:v2 - name: Validate composer.json and composer.lock @@ -53,7 +53,7 @@ jobs: run: composer exec phpcs -- src/ - name: Remove uncompliant statements in legacy code - if: contains(fromJson('["5.6", "7.0"]'), matrix.php.version) + if: contains(fromJson('["5.6", "7.0"]'), matrix.php) run: | # Replace string in files string=': void' From 2eab88389d1e13c020f05e4c5cbd7c13c6922e13 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guillaume=20Desv=C3=A9?= Date: Fri, 14 Jun 2024 10:40:59 +0200 Subject: [PATCH 5/6] Specific composer version for PHP 7.1 --- Dockerfile | 3 ++- Taskfile.php.yml | 2 ++ Taskfile.yml | 1 + compose.yml | 1 + phpunit.ci.xml | 3 --- 5 files changed, 6 insertions(+), 4 deletions(-) diff --git a/Dockerfile b/Dockerfile index f25a7d40..12545aa0 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,7 @@ ARG PHP_VERSION +ARG COMPOSER_VERSION -FROM composer:2.2 as composer +FROM composer:${COMPOSER_VERSION} as composer FROM php:${PHP_VERSION}-fpm ENV DEBIAN_FRONTEND noninteractive diff --git a/Taskfile.php.yml b/Taskfile.php.yml index 7f126582..db7aae31 100644 --- a/Taskfile.php.yml +++ b/Taskfile.php.yml @@ -5,11 +5,13 @@ vars: PHP_VERSION: '{{ .PHP_VERSION }}' PHPUNIT_VERSION: '{{ .PHPUNIT_VERSION }}' # Defaulted variable + COMPOSER_VERSION: '{{ .COMPOSER_VERSION | default "2" }}' COMPOSE_SERVICE: '{{ .COMPOSE_SERVICE | default "php" }}' PHPUNIT_FILE: '{{ .PHPUNIT_FILE | default "phpunit.dist.xml" }}' env: PHP_VERSION: '{{ .PHP_VERSION }}' + COMPOSER_VERSION: '{{ .COMPOSER_VERSION }}' tasks: docker:build: diff --git a/Taskfile.yml b/Taskfile.yml index 3590b4f7..9c3534a0 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -22,6 +22,7 @@ includes: taskfile: Taskfile.php.yml vars: PHP_VERSION: "7.1" + COMPOSER_VERSION: "2.2" # Composer >2.2 deprecated PHP 7.1 "7.2": taskfile: Taskfile.php.yml vars: diff --git a/compose.yml b/compose.yml index 1f91129d..b73909d7 100644 --- a/compose.yml +++ b/compose.yml @@ -6,6 +6,7 @@ services: dockerfile: Dockerfile args: PHP_VERSION: ${PHP_VERSION} + COMPOSER_VERSION: ${COMPOSER_VERSION:-2} ports: - "8080:80" volumes: diff --git a/phpunit.ci.xml b/phpunit.ci.xml index 966eea12..1ef46110 100644 --- a/phpunit.ci.xml +++ b/phpunit.ci.xml @@ -18,9 +18,6 @@ ./src/* - - ./src/vendor/* - From d7d57a36774ae56d60a6e6f0f9607880c88825b7 Mon Sep 17 00:00:00 2001 From: joyet simon <43644110+joyet-simon@users.noreply.github.com> Date: Thu, 20 Jun 2024 15:53:47 +0200 Subject: [PATCH 6/6] remove .DS_Store --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 6d2a9612..bd35edbc 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,4 @@ dist/ phpunit.xml .phpunit.cache/ composer.lock +.DS_Store \ No newline at end of file