diff --git a/.circleci/config.yml b/.circleci/config.yml deleted file mode 100644 index a421a85..0000000 --- a/.circleci/config.yml +++ /dev/null @@ -1,33 +0,0 @@ -# PHP CircleCI 2.0 configuration file -# -# Check https://circleci.com/docs/2.0/language-php/ for more details -# -version: 2 -jobs: - build: - docker: - # Specify the version you desire here - - image: circleci/php:7.1-jessie-node-browsers - - steps: - - checkout - - # Download and cache dependencies - - # composer cache - - restore_cache: - keys: - # "composer.lock" can be used if it is committed to the repo - - v1-dependencies-{{ checksum "composer.json" }} - # fallback to using the latest cache if no exact match is found - - v1-dependencies- - - - run: composer install -n --prefer-dist - - - save_cache: - key: composer-v1-{{ checksum "composer.lock" }} - paths: - - vendor - - # run tests with phpunit or codecept - - run: ./vendor/bin/phpunit diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml new file mode 100644 index 0000000..c9b363c --- /dev/null +++ b/.github/workflows/test.yaml @@ -0,0 +1,54 @@ +name: Test + +on: + push: + branches-ignore: + - 'master' + tags-ignore: + - '**' + +jobs: + setup: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: shivammathur/setup-php@v2 + with: + php-version: 7.4 + coverage: none + - uses: actions/cache@v2 + with: + path: vendor + key: php-7.4-vendor-${{ hashFiles('**/composer.json') }} + restore-keys: php-7.4-vendor- + - run: composer install --no-interaction --no-ansi + - id: set-php-versions + run: echo "::set-output name=php-versions::$(vendor/bin/devtools list:php-versions)" + - id: set-tools + run: echo "::set-output name=tools::$(vendor/bin/devtools list:enabled-tools)" + outputs: + php-versions: ${{ steps.set-php-versions.outputs.php-versions }} + tools: ${{ steps.set-tools.outputs.tools }} + + test: + needs: setup + runs-on: ubuntu-latest + strategy: + matrix: + php-version: ${{ fromJson(needs.setup.outputs.php-versions) }} + tool: ${{ fromJson(needs.setup.outputs.tools) }} + fail-fast: false + steps: + - uses: actions/checkout@v2 + - uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php-version }} + ini-values: date.timezone=Europe/Amsterdam, assert.exception=1, zend.assertions=1 + - uses: actions/cache@v2 + with: + path: vendor + key: php-${{ matrix.php-version }}-vendor-${{ hashFiles('**/composer.json') }} + restore-keys: php-${{ matrix.php-version }}-vendor- + - run: composer install --no-interaction --no-ansi + + - run: vendor/bin/devtools ${{ matrix.tool }} diff --git a/.gitignore b/.gitignore index 10500ea..9fd7856 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,7 @@ +.DS_Store .idea +.phpunit.result.cache vendor composer.lock phpunit.xml +/.phpcs-cache diff --git a/.scrutinizer.yml b/.scrutinizer.yml deleted file mode 100644 index 97ea95a..0000000 --- a/.scrutinizer.yml +++ /dev/null @@ -1,14 +0,0 @@ -filter: - excluded_paths: [tests/*] -build: - tests: - override: - - - command: 'vendor/bin/phpunit --coverage-clover=coverage.clover' - coverage: - file: 'coverage.clover' - format: 'clover' -checks: - php: - code_rating: true - duplication: true diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index b701942..0000000 --- a/.travis.yml +++ /dev/null @@ -1,8 +0,0 @@ -language: php -php: - - '7.0' - - '7.1' - - '7.2' -before_script: - - composer self-update - - composer install --prefer-source diff --git a/README.md b/README.md index 580d40f..7bb8a47 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,6 @@ +# NO LONGER MAINTAINED +This repository is no longer being maintained. + # Omnipay: Klarna Checkout [![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE) [![Scrutinizer Build](https://img.shields.io/scrutinizer/build/g/MyOnlineStore/omnipay-klarna-checkout.svg?style=flat-square)](https://github.com/MyOnlineStore/omnipay-klarna-checkout) diff --git a/composer.json b/composer.json index 1e9a446..e1f9ac3 100644 --- a/composer.json +++ b/composer.json @@ -12,16 +12,21 @@ } }, "require": { - "php": "^7.0", - "omnipay/common": "~3", + "php": "^7.4 | ^8.0", + "omnipay/common": "^3.1", "ext-json": "*" }, "require-dev": { - "myonlinestore/coding-standard": "^1.0", - "omnipay/tests": "~3" + "myonlinestore/coding-standard": "^3.1", + "myonlinestore/php-devtools": "^0.2", + "omnipay/tests": "^4.1", + "vimeo/psalm": "^4.18" }, "config": { - "vendor-dir": "vendor", - "sort-packages": true + "sort-packages": true, + "allow-plugins": { + "dealerdirect/phpcodesniffer-composer-installer": true, + "composer/package-versions-deprecated": true + } } } diff --git a/phpcs.xml.dist b/phpcs.xml.dist index 2984ee9..b6a7f57 100644 --- a/phpcs.xml.dist +++ b/phpcs.xml.dist @@ -2,10 +2,21 @@ - ./ - - + + + + + + + src + tests - + + + + + + + diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 535809e..4bbedd5 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,22 +1,18 @@ - + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd" +> + + + src + + + ./tests/ - - - ./src - - diff --git a/psalm-baseline.xml b/psalm-baseline.xml new file mode 100644 index 0000000..7fb9cc4 --- /dev/null +++ b/psalm-baseline.xml @@ -0,0 +1,146 @@ + + + + + $request->getSecret() + $request->getUsername() + + + + + $this + + + authorize + capture + refund + setBaseUrl + void + + + self + + + + + setMerchantData + setTaxRate + setTotalAmount + setTotalDiscountAmount + setTotalTaxAmount + setType + + + + + ItemInterface[] + + + add + + + $item + + + + + getAmount + + + + + Money|null + + + setLocale + setTaxAmount + + + $items + + + + + AcknowledgeRequest + + + + + $response->getBody() + + + AuthorizeRequest + + + + + getRedirectData + getRedirectUrl + + + $data + $renderUrl + + + $this->renderUrl + null + + + + + CaptureRequest + + + + + ExtendAuthorizationRequest + + + + + $responseData + + + FetchTransactionRequest + + + + + RefundRequest + + + + + getArrayCopy + getArrayCopy + + + UpdateCustomerAddressRequest + + + + + (int) $statusCode + + + + + UpdateMerchantReferencesRequest + + + + + UpdateTransactionRequest + + + + + VoidRequest + + + + + public function initialize(array $parameters = []) + + + diff --git a/psalm.xml.dist b/psalm.xml.dist new file mode 100644 index 0000000..f3073df --- /dev/null +++ b/psalm.xml.dist @@ -0,0 +1,16 @@ + + + + + + + + + diff --git a/src/AuthenticationRequestHeaderProvider.php b/src/AuthenticationRequestHeaderProvider.php index e9bfd06..b36af44 100644 --- a/src/AuthenticationRequestHeaderProvider.php +++ b/src/AuthenticationRequestHeaderProvider.php @@ -10,10 +10,10 @@ final class AuthenticationRequestHeaderProvider public function getHeaders(AbstractRequest $request): array { return [ - 'Authorization' => sprintf( + 'Authorization' => \sprintf( 'Basic %s', - base64_encode( - sprintf( + \base64_encode( + \sprintf( '%s:%s', $request->getUsername(), $request->getSecret() diff --git a/src/Customer.php b/src/Customer.php index 600baa4..9942c30 100644 --- a/src/Customer.php +++ b/src/Customer.php @@ -17,6 +17,6 @@ public static function fromArray(array $data): Customer 'type' => 'person', ]; - return new self(array_merge($defaults, array_intersect_key($data, $defaults))); + return new self(\array_merge($defaults, \array_intersect_key($data, $defaults))); } } diff --git a/src/Gateway.php b/src/Gateway.php index 89aebfa..4ca96f5 100644 --- a/src/Gateway.php +++ b/src/Gateway.php @@ -18,13 +18,13 @@ final class Gateway extends AbstractGateway implements GatewayInterface { - const API_VERSION_EUROPE = 'EU'; - const API_VERSION_NORTH_AMERICA = 'NA'; + public const API_VERSION_EUROPE = 'EU'; + public const API_VERSION_NORTH_AMERICA = 'NA'; - const EU_BASE_URL = 'https://api.klarna.com'; - const EU_TEST_BASE_URL = 'https://api.playground.klarna.com'; - const NA_BASE_URL = 'https://api-na.klarna.com'; - const NA_TEST_BASE_URL = 'https://api-na.playground.klarna.com'; + public const EU_BASE_URL = 'https://api.klarna.com'; + public const EU_TEST_BASE_URL = 'https://api.playground.klarna.com'; + public const NA_BASE_URL = 'https://api-na.klarna.com'; + public const NA_TEST_BASE_URL = 'https://api-na.playground.klarna.com'; /** * @inheritdoc @@ -87,25 +87,16 @@ public function getDefaultParameters(): array ]; } - /** - * @inheritDoc - */ public function getName(): string { return 'KlarnaCheckout'; } - /** - * @return string - */ public function getSecret(): string { return $this->getParameter('secret'); } - /** - * @return string - */ public function getUsername(): string { return $this->getParameter('username'); @@ -167,9 +158,9 @@ public function setUsername(string $username): self return $this; } - public function setTestMode($testMode): self + public function setTestMode($value): self { - parent::setTestMode($testMode); + parent::setTestMode($value); $this->setBaseUrl(); diff --git a/src/ItemBag.php b/src/ItemBag.php index 4b00e90..78da7cf 100644 --- a/src/ItemBag.php +++ b/src/ItemBag.php @@ -5,7 +5,6 @@ /** * @final - * * @method ItemInterface[] getIterator() */ class ItemBag extends \Omnipay\Common\ItemBag diff --git a/src/Message/AbstractOrderRequest.php b/src/Message/AbstractOrderRequest.php index 2cf8a01..002949e 100644 --- a/src/Message/AbstractOrderRequest.php +++ b/src/Message/AbstractOrderRequest.php @@ -186,7 +186,7 @@ protected function getOrderData(): array ]; if (null !== $locale = $this->getLocale()) { - $data['locale'] = str_replace('_', '-', $locale); + $data['locale'] = \str_replace('_', '-', $locale); } if (null !== $shippingCountries = $this->getShippingCountries()) { diff --git a/src/Message/AbstractRequest.php b/src/Message/AbstractRequest.php index 7c5d8c1..b145720 100644 --- a/src/Message/AbstractRequest.php +++ b/src/Message/AbstractRequest.php @@ -139,9 +139,6 @@ public function setItems($items) return $this->setParameter('items', $items); } - /** - * @param string $locale - */ public function setLocale(string $locale) { $this->setParameter('locale', $locale); @@ -234,15 +231,15 @@ protected function sendRequest(string $method, string $url, $data): ResponseInte if ('GET' === $method) { return $this->httpClient->request( $method, - $this->getBaseUrl().$url, + $this->getBaseUrl() . $url, $headers ); } return $this->httpClient->request( $method, - $this->getBaseUrl().$url, - array_merge( + $this->getBaseUrl() . $url, + \array_merge( ['Content-Type' => 'application/json'], $headers ), diff --git a/src/Message/AbstractResponse.php b/src/Message/AbstractResponse.php index fe7befa..9662e43 100644 --- a/src/Message/AbstractResponse.php +++ b/src/Message/AbstractResponse.php @@ -29,12 +29,8 @@ public function getTransactionReference() return $this->data['order_id'] ?? null; } - /** - * @inheritDoc - */ public function isSuccessful(): bool { return !isset($this->data['error_code']); } } - diff --git a/src/Message/AcknowledgeRequest.php b/src/Message/AcknowledgeRequest.php index 54c3cb8..d25daf2 100644 --- a/src/Message/AcknowledgeRequest.php +++ b/src/Message/AcknowledgeRequest.php @@ -31,7 +31,7 @@ public function sendData($data) { $response = $this->sendRequest( 'POST', - sprintf( + \sprintf( '/ordermanagement/v1/orders/%s/acknowledge', $this->getTransactionReference() ), diff --git a/src/Message/AcknowledgeResponse.php b/src/Message/AcknowledgeResponse.php index b8ef570..962f5e4 100644 --- a/src/Message/AcknowledgeResponse.php +++ b/src/Message/AcknowledgeResponse.php @@ -7,9 +7,7 @@ final class AcknowledgeResponse extends AbstractResponse { - /** - * @var int - */ + /** @var int */ private $statusCode; /** @@ -24,17 +22,11 @@ public function __construct(RequestInterface $request, $data, $statusCode) $this->statusCode = $statusCode; } - /** - * @return int - */ public function getStatusCode(): int { return $this->statusCode; } - /** - * @inheritDoc - */ public function isSuccessful(): bool { return parent::isSuccessful() && 204 === $this->getStatusCode(); diff --git a/src/Message/AuthorizeRequest.php b/src/Message/AuthorizeRequest.php index da3a5bb..b0d47a7 100644 --- a/src/Message/AuthorizeRequest.php +++ b/src/Message/AuthorizeRequest.php @@ -55,7 +55,7 @@ public function getRenderUrl() public function sendData($data) { $response = $this->getTransactionReference() ? - $this->sendRequest('GET', '/checkout/v3/orders/'.$this->getTransactionReference(), $data) : + $this->sendRequest('GET', '/checkout/v3/orders/' . $this->getTransactionReference(), $data) : $this->sendRequest('POST', '/checkout/v3/orders', $data); if ($response->getStatusCode() >= 400) { diff --git a/src/Message/AuthorizeResponse.php b/src/Message/AuthorizeResponse.php index f4f3411..3efd123 100644 --- a/src/Message/AuthorizeResponse.php +++ b/src/Message/AuthorizeResponse.php @@ -8,9 +8,7 @@ final class AuthorizeResponse extends AbstractResponse implements RedirectResponseInterface { - /** - * @var string|null - */ + /** @var string|null */ private $renderUrl; /** @@ -38,17 +36,11 @@ public function getRedirectUrl() return $this->renderUrl; } - /** - * @inheritDoc - */ public function isRedirect(): bool { return null !== $this->renderUrl; } - /** - * @inheritDoc - */ public function isSuccessful(): bool { // Authorize is only successful once it has been acknowledged diff --git a/src/Message/CaptureRequest.php b/src/Message/CaptureRequest.php index 85de0de..56457e6 100644 --- a/src/Message/CaptureRequest.php +++ b/src/Message/CaptureRequest.php @@ -39,7 +39,7 @@ public function sendData($data) { $response = $this->sendRequest( 'POST', - sprintf( + \sprintf( '/ordermanagement/v1/orders/%s/captures', $this->getTransactionReference() ), diff --git a/src/Message/CaptureResponse.php b/src/Message/CaptureResponse.php index d3d4b8f..bd160f6 100644 --- a/src/Message/CaptureResponse.php +++ b/src/Message/CaptureResponse.php @@ -7,14 +7,10 @@ final class CaptureResponse extends AbstractResponse { - /** - * @var int - */ + /** @var int */ private $statusCode; - /** - * @var string - */ + /** @var string */ private $transactionReference; /** @@ -31,9 +27,6 @@ public function __construct(RequestInterface $request, $data, $transactionRefere $this->statusCode = $statusCode; } - /** - * @return int - */ public function getStatusCode(): int { return $this->statusCode; @@ -47,9 +40,6 @@ public function getTransactionReference() return $this->transactionReference; } - /** - * @inheritDoc - */ public function isSuccessful(): bool { return parent::isSuccessful() && 201 === $this->statusCode; diff --git a/src/Message/ExtendAuthorizationRequest.php b/src/Message/ExtendAuthorizationRequest.php index 1e26afe..672a6cd 100644 --- a/src/Message/ExtendAuthorizationRequest.php +++ b/src/Message/ExtendAuthorizationRequest.php @@ -34,7 +34,7 @@ public function sendData($data): ExtendAuthorizationResponse $responseBody = $this->getResponseBody( $this->sendRequest( 'POST', - sprintf('/ordermanagement/v1/orders/%s/extend-authorization-time', $this->getTransactionReference()), + \sprintf('/ordermanagement/v1/orders/%s/extend-authorization-time', $this->getTransactionReference()), $data ) ); diff --git a/src/Message/FetchTransactionRequest.php b/src/Message/FetchTransactionRequest.php index d99dbd6..b1906b5 100644 --- a/src/Message/FetchTransactionRequest.php +++ b/src/Message/FetchTransactionRequest.php @@ -31,19 +31,20 @@ public function sendData($data) { $response = $this->sendRequest( 'GET', - '/checkout/v3/orders/'.$this->getTransactionReference(), + '/checkout/v3/orders/' . $this->getTransactionReference(), $data ); $responseData['checkout'] = $this->getResponseBody($response); - if ((isset($responseData['checkout']['status']) && 'checkout_complete' === $responseData['checkout']['status']) || - 404 === $response->getStatusCode() + if ( + (isset($responseData['checkout']['status']) && 'checkout_complete' === $responseData['checkout']['status']) + || 404 === $response->getStatusCode() ) { $responseData['management'] = $this->getResponseBody( $this->sendRequest( 'GET', - '/ordermanagement/v1/orders/'.$this->getTransactionReference(), + '/ordermanagement/v1/orders/' . $this->getTransactionReference(), $data ) ); diff --git a/src/Message/FetchTransactionResponse.php b/src/Message/FetchTransactionResponse.php index 9d7c8ff..3b09406 100644 --- a/src/Message/FetchTransactionResponse.php +++ b/src/Message/FetchTransactionResponse.php @@ -13,9 +13,6 @@ public function getTransactionReference() return $this->data['checkout']['order_id'] ?? $this->data['management']['order_id']; } - /** - * @inheritDoc - */ public function isSuccessful(): bool { return parent::isSuccessful() && diff --git a/src/Message/RefundRequest.php b/src/Message/RefundRequest.php index 61ca2d8..19aa34f 100644 --- a/src/Message/RefundRequest.php +++ b/src/Message/RefundRequest.php @@ -42,7 +42,7 @@ public function sendData($data) { $response = $this->sendRequest( 'POST', - sprintf('/ordermanagement/v1/orders/%s/refunds', $this->getTransactionReference()), + \sprintf('/ordermanagement/v1/orders/%s/refunds', $this->getTransactionReference()), $data ); diff --git a/src/Message/RefundResponse.php b/src/Message/RefundResponse.php index 833543e..4467431 100644 --- a/src/Message/RefundResponse.php +++ b/src/Message/RefundResponse.php @@ -7,9 +7,7 @@ final class RefundResponse extends AbstractResponse { - /** - * @var int - */ + /** @var int */ private $statusCode; /** @@ -24,17 +22,11 @@ public function __construct(RequestInterface $request, $data, $statusCode) $this->statusCode = $statusCode; } - /** - * @return int - */ public function getStatusCode(): int { return $this->statusCode; } - /** - * @inheritDoc - */ public function isSuccessful(): bool { return parent::isSuccessful() && 201 === $this->statusCode; diff --git a/src/Message/UpdateCustomerAddressRequest.php b/src/Message/UpdateCustomerAddressRequest.php index e344208..8494133 100644 --- a/src/Message/UpdateCustomerAddressRequest.php +++ b/src/Message/UpdateCustomerAddressRequest.php @@ -34,7 +34,7 @@ public function sendData($data) { $response = $this->sendRequest( 'PATCH', - sprintf('/ordermanagement/v1/orders/%s/customer-details', $this->getTransactionReference()), + \sprintf('/ordermanagement/v1/orders/%s/customer-details', $this->getTransactionReference()), $data ); diff --git a/src/Message/UpdateCustomerAddressResponse.php b/src/Message/UpdateCustomerAddressResponse.php index 9224098..f231848 100644 --- a/src/Message/UpdateCustomerAddressResponse.php +++ b/src/Message/UpdateCustomerAddressResponse.php @@ -7,9 +7,7 @@ final class UpdateCustomerAddressResponse extends AbstractResponse { - /** - * @var int - */ + /** @var int */ private $statusCode; /** @@ -24,9 +22,6 @@ public function __construct(RequestInterface $request, $data, $statusCode) $this->statusCode = (int) $statusCode; } - /** - * @inheritDoc - */ public function isSuccessful(): bool { return parent::isSuccessful() && 204 === $this->statusCode; diff --git a/src/Message/UpdateMerchantReferencesRequest.php b/src/Message/UpdateMerchantReferencesRequest.php index b4152e2..334cb29 100644 --- a/src/Message/UpdateMerchantReferencesRequest.php +++ b/src/Message/UpdateMerchantReferencesRequest.php @@ -22,7 +22,7 @@ public function sendData($data) $this->getResponseBody( $this->sendRequest( 'PATCH', - sprintf('/ordermanagement/v1/orders/%s/merchant-references', $this->getTransactionReference()), + \sprintf('/ordermanagement/v1/orders/%s/merchant-references', $this->getTransactionReference()), $data ) ) diff --git a/src/Message/UpdateTransactionRequest.php b/src/Message/UpdateTransactionRequest.php index ffbd43f..553b20d 100644 --- a/src/Message/UpdateTransactionRequest.php +++ b/src/Message/UpdateTransactionRequest.php @@ -40,30 +40,15 @@ public function getData() */ public function sendData($data) { - $responseData = $this->getResponseBody( - $this->sendRequest( - 'POST', - sprintf('/checkout/v3/orders/%s', $this->getTransactionReference()), - $data + return new UpdateTransactionResponse( + $this, + $this->getResponseBody( + $this->sendRequest( + 'POST', + \sprintf('/checkout/v3/orders/%s', $this->getTransactionReference()), + $data + ) ) ); - - // Once the checkout order has reached it's end-state it cannot be changed; update the management order instead - if (isset($responseData['error_code']) && 'READ_ONLY_ORDER' === $responseData['error_code']) { - // Attempt to update the merchant references at the order management endpoint - $requestData = array_intersect_key($data, ['merchant_reference1' => true, 'merchant_reference2' => true]); - - $responseData = !empty($requestData) ? - $this->getResponseBody( - $this->sendRequest( - 'PATCH', - sprintf('/ordermanagement/v1/orders/%s/merchant-references', $this->getTransactionReference()), - $requestData - ) - ) : - []; // no merchant references to be updated - } - - return new UpdateTransactionResponse($this, $responseData); } } diff --git a/src/Message/VoidRequest.php b/src/Message/VoidRequest.php index 72c1501..532d0c7 100644 --- a/src/Message/VoidRequest.php +++ b/src/Message/VoidRequest.php @@ -29,15 +29,15 @@ public function getData() */ public function sendData($data) { - $baseUrl = sprintf('/ordermanagement/v1/orders/%s', $this->getTransactionReference()); + $baseUrl = \sprintf('/ordermanagement/v1/orders/%s', $this->getTransactionReference()); $orderManagementResponse = $this->sendRequest('GET', $baseUrl, []); $order = $this->getResponseBody($orderManagementResponse); - $voidUrl = sprintf('%s/release-remaining-authorization', $baseUrl); + $voidUrl = \sprintf('%s/release-remaining-authorization', $baseUrl); if (empty($order['captures'])) { - $voidUrl = sprintf('%s/cancel', $baseUrl); + $voidUrl = \sprintf('%s/cancel', $baseUrl); } $response = $this->sendRequest('POST', $voidUrl, $data); diff --git a/src/Message/VoidResponse.php b/src/Message/VoidResponse.php index 074b1de..e664f44 100644 --- a/src/Message/VoidResponse.php +++ b/src/Message/VoidResponse.php @@ -7,9 +7,7 @@ final class VoidResponse extends AbstractResponse { - /** - * @var int - */ + /** @var int */ private $statusCode; /** @@ -24,17 +22,11 @@ public function __construct(RequestInterface $request, $data, $statusCode) $this->statusCode = $statusCode; } - /** - * @return int - */ public function getStatusCode(): int { return $this->statusCode; } - /** - * @inheritDoc - */ public function isSuccessful(): bool { return parent::isSuccessful() && 204 === $this->statusCode; diff --git a/src/WidgetOptions.php b/src/WidgetOptions.php index 6ed03d9..1058ed3 100644 --- a/src/WidgetOptions.php +++ b/src/WidgetOptions.php @@ -31,6 +31,6 @@ public static function fromArray(array $data): WidgetOptions 'allow_global_billing_countries' => false, ]; - return new self(array_merge($defaults, array_intersect_key($data, $defaults))); + return new self(\array_merge($defaults, \array_intersect_key($data, $defaults))); } } diff --git a/tests/AuthenticationRequestHeaderProviderTest.php b/tests/AuthenticationRequestHeaderProviderTest.php index 61340ab..3e93818 100644 --- a/tests/AuthenticationRequestHeaderProviderTest.php +++ b/tests/AuthenticationRequestHeaderProviderTest.php @@ -20,10 +20,10 @@ public function testWithNoMerchantIdSetWillReturnHeadersWithUsername() self::assertEquals( [ - 'Authorization' => sprintf( + 'Authorization' => \sprintf( 'Basic %s', - base64_encode( - sprintf( + \base64_encode( + \sprintf( '%s:%s', $userName, $secret diff --git a/tests/ExpectedAuthorizationHeaderTrait.php b/tests/ExpectedAuthorizationHeaderTrait.php index 62df427..3c6ec70 100644 --- a/tests/ExpectedAuthorizationHeaderTrait.php +++ b/tests/ExpectedAuthorizationHeaderTrait.php @@ -13,10 +13,10 @@ trait ExpectedAuthorizationHeaderTrait public function getExpectedHeaders(): array { return [ - 'Authorization' => sprintf( + 'Authorization' => \sprintf( 'Basic %s', - base64_encode( - sprintf( + \base64_encode( + \sprintf( '%s:%s', RequestTestCase::USERNAME, RequestTestCase::SECRET diff --git a/tests/GatewayTest.php b/tests/GatewayTest.php index c9c1b6a..cd0d9c6 100644 --- a/tests/GatewayTest.php +++ b/tests/GatewayTest.php @@ -18,12 +18,10 @@ final class GatewayTest extends GatewayTestCase { - /** - * @var Gateway - */ + /** @var Gateway */ protected $gateway; - protected function setUp() + protected function setUp(): void { $this->gateway = new Gateway($this->getHttpClient(), $this->getHttpRequest()); } diff --git a/tests/ItemTest.php b/tests/ItemTest.php index 95cb1f7..78dc50b 100644 --- a/tests/ItemTest.php +++ b/tests/ItemTest.php @@ -12,7 +12,7 @@ public function testGetters() { $taxRate = 21; $totalTaxAmount = 9.45; - $totalAmount = ($totalTaxAmount / $taxRate) * 100; + $totalAmount = $totalTaxAmount / $taxRate * 100; $totalDiscountAmount = 1.00; $type = 'shipping_fee'; $merchantData = 'foobar'; diff --git a/tests/Message/AbstractRequestTest.php b/tests/Message/AbstractRequestTest.php index 2e8d067..c52d382 100644 --- a/tests/Message/AbstractRequestTest.php +++ b/tests/Message/AbstractRequestTest.php @@ -13,24 +13,22 @@ final class AbstractRequestTest extends TestCase { - /** - * @var AbstractRequest - */ + /** @var AbstractRequest */ private $request; - protected function setUp() + protected function setUp(): void { $httpClient = $this->getHttpClient(); $httpRequest = $this->getHttpRequest(); - $this->request = new class($httpClient, $httpRequest) extends AbstractRequest + $this->request = new class ($httpClient, $httpRequest) extends AbstractRequest { /** * @inheritdoc */ public function sendData($data) { - return parent::sendData($data); + return []; } /** @@ -38,7 +36,7 @@ public function sendData($data) */ public function getData() { - return parent::getData(); + return []; } }; } @@ -59,18 +57,19 @@ public function testGetResponseBodyWillReturnArray() $httpClient = $this->getHttpClient(); $httpRequest = $this->getHttpRequest(); - $request = new class($httpClient, $httpRequest) extends AbstractRequest + $request = new class ($httpClient, $httpRequest) extends AbstractRequest { public function sendData($data) { - return parent::sendData($data); + return []; } public function getData() { - return parent::getData(); + return []; } + // phpcs:disable Generic.CodeAnalysis.UselessOverridingMethod public function getResponseBody(ResponseInterface $response): array { return parent::getResponseBody($response); // TODO: Change the autogenerated stub @@ -97,16 +96,16 @@ public function testGetResponseBodyWillReturnArrayIfResponseIsEmtpy() $httpClient = $this->getHttpClient(); $httpRequest = $this->getHttpRequest(); - $request = new class($httpClient, $httpRequest) extends AbstractRequest + $request = new class ($httpClient, $httpRequest) extends AbstractRequest { public function sendData($data) { - return parent::sendData($data); + return []; } public function getData() { - return parent::getData(); + return []; } public function getResponseBody(ResponseInterface $response): array diff --git a/tests/Message/AcknowledgeRequestTest.php b/tests/Message/AcknowledgeRequestTest.php index 16e4ebd..7ba4b35 100644 --- a/tests/Message/AcknowledgeRequestTest.php +++ b/tests/Message/AcknowledgeRequestTest.php @@ -8,15 +8,10 @@ final class AcknowledgeRequestTest extends RequestTestCase { - /** - * @var AcknowledgeRequest - */ + /** @var AcknowledgeRequest */ private $acknowledgeRequest; - /** - * @inheritdoc - */ - protected function setUp() + protected function setUp(): void { parent::setUp(); @@ -38,7 +33,7 @@ public function testSendData() $response = $this->setExpectedPostRequest( $inputData, $expectedData, - self::BASE_URL.'/ordermanagement/v1/orders/foo/acknowledge' + self::BASE_URL . '/ordermanagement/v1/orders/foo/acknowledge' ); $response->expects(self::once())->method('getStatusCode')->willReturn(204); diff --git a/tests/Message/AddressTest.php b/tests/Message/AddressTest.php index 8fc8c86..a188fa7 100644 --- a/tests/Message/AddressTest.php +++ b/tests/Message/AddressTest.php @@ -8,23 +8,23 @@ final class AddressTest extends TestCase { - const ATTENTION = 'quz'; - const CITY = 'Oss'; - const COUNTRY = 'NL'; - const EMAIL = 'foo@bar.com'; - const FAMILY_NAME = 'foo'; - const GIVEN_NAME = 'bar'; - const HOUSE_EXTENSION = 'C'; - const ORGANIZATION_NAME = 'Foo Inc.'; - const PHONE = '24234234'; - const POSTAL_CODE = '523354'; - const REFERENCE = 'ref'; - const REGION = 'NB'; - const STREET = 'Foo Street'; - const STREET_ADDRESS_1 = 'Foo Street 1'; - const STREET_ADDRESS_2 = 'App. 12A'; - const STREET_NUMBER = '1'; - const TITLE = 'Mr.'; + public const ATTENTION = 'quz'; + public const CITY = 'Oss'; + public const COUNTRY = 'NL'; + public const EMAIL = 'foo@bar.com'; + public const FAMILY_NAME = 'foo'; + public const GIVEN_NAME = 'bar'; + public const HOUSE_EXTENSION = 'C'; + public const ORGANIZATION_NAME = 'Foo Inc.'; + public const PHONE = '24234234'; + public const POSTAL_CODE = '523354'; + public const REFERENCE = 'ref'; + public const REGION = 'NB'; + public const STREET = 'Foo Street'; + public const STREET_ADDRESS_1 = 'Foo Street 1'; + public const STREET_ADDRESS_2 = 'App. 12A'; + public const STREET_NUMBER = '1'; + public const TITLE = 'Mr.'; /** * @return array diff --git a/tests/Message/AuthorizeRequestTest.php b/tests/Message/AuthorizeRequestTest.php index 96c319f..f5851d5 100644 --- a/tests/Message/AuthorizeRequestTest.php +++ b/tests/Message/AuthorizeRequestTest.php @@ -17,15 +17,10 @@ class AuthorizeRequestTest extends RequestTestCase use ItemDataTestTrait; use MerchantUrlsDataTestTrait; - /** - * @var AuthorizeRequest - */ + /** @var AuthorizeRequest */ private $authorizeRequest; - /** - * @inheritdoc - */ - protected function setUp() + protected function setUp(): void { parent::setUp(); $this->authorizeRequest = new AuthorizeRequest($this->httpClient, $this->getHttpRequest()); @@ -39,7 +34,7 @@ public function invalidRequestDataProvider(): array $itemBag = $this->createMock(ItemBag::class); $itemBag->method('getIterator')->willReturn(new \ArrayIterator([])); - $data = array_merge( + $data = \array_merge( [ 'currency' => 'EUR', 'amount' => true, @@ -48,13 +43,13 @@ public function invalidRequestDataProvider(): array 'purchase_country' => true, 'tax_amount' => new Money(1, new Currency('EUR')), ], - array_fill_keys(array_keys($this->getMinimalValidMerchantUrlData()), true) + \array_fill_keys(\array_keys($this->getMinimalValidMerchantUrlData()), true) ); $cases = []; foreach ($data as $key => $value) { - $cases[] = [array_diff_key($data, [$key => $value])]; + $cases[] = [\array_diff_key($data, [$key => $value])]; } return $cases; @@ -63,7 +58,7 @@ public function invalidRequestDataProvider(): array public function testGetDataWillReturnCorrectData() { $this->authorizeRequest->initialize( - array_merge( + \array_merge( [ 'currency' => 'EUR', 'locale' => 'nl_NL', @@ -164,7 +159,7 @@ public function testGetDataWithAddressesWillReturnCorrectData() ]; $this->authorizeRequest->initialize( - array_merge( + \array_merge( [ 'currency' => 'EUR', 'locale' => 'nl_NL', @@ -203,7 +198,7 @@ public function testGetDataWithCustomerWillReturnCorrectData() ]; $this->authorizeRequest->initialize( - array_merge( + \array_merge( [ 'locale' => 'nl_NL', 'amount' => '100.00', @@ -258,7 +253,7 @@ public function testGetDataWithOptionsWillReturnCorrectData() ]; $this->authorizeRequest->initialize( - array_merge( + \array_merge( [ 'locale' => 'nl_NL', 'amount' => '100.00', @@ -294,7 +289,7 @@ public function testSendDataWillCreateOrderAndReturnResponse() $inputData = ['request-data' => 'yey?']; $expectedData = ['response-data' => 'yey!']; - $response = $this->setExpectedPostRequest($inputData, $expectedData, self::BASE_URL.'/checkout/v3/orders'); + $response = $this->setExpectedPostRequest($inputData, $expectedData, self::BASE_URL . '/checkout/v3/orders'); $response->expects(self::once())->method('getStatusCode')->willReturn(200); @@ -321,7 +316,7 @@ public function testSendDataWillFetchOrderAndReturnResponseIfTransactionIdAlread $response = $this->setExpectedGetRequest( $expectedData, - self::BASE_URL.'/checkout/v3/orders/f60e69e8-464a-48c0-a452-6fd562540f37' + self::BASE_URL . '/checkout/v3/orders/f60e69e8-464a-48c0-a452-6fd562540f37' ); $response->expects(self::once())->method('getStatusCode')->willReturn(200); diff --git a/tests/Message/CaptureRequestTest.php b/tests/Message/CaptureRequestTest.php index 5bc8e93..7ebe5ae 100644 --- a/tests/Message/CaptureRequestTest.php +++ b/tests/Message/CaptureRequestTest.php @@ -3,28 +3,20 @@ namespace MyOnlineStore\Tests\Omnipay\KlarnaCheckout\Message; -use Money\Currency; -use Money\Money; use MyOnlineStore\Omnipay\KlarnaCheckout\Message\CaptureRequest; use MyOnlineStore\Omnipay\KlarnaCheckout\Message\CaptureResponse; use Omnipay\Common\Exception\InvalidRequestException; class CaptureRequestTest extends RequestTestCase { - const CAPTURE_ID = 'bar'; - const TRANSACTION_REF = 'foo'; - + public const CAPTURE_ID = 'bar'; + public const TRANSACTION_REF = 'foo'; use ItemDataTestTrait; - /** - * @var CaptureRequest - */ + /** @var CaptureRequest */ private $captureRequest; - /** - * @inheritdoc - */ - protected function setUp() + protected function setUp(): void { parent::setUp(); $this->captureRequest = new CaptureRequest($this->httpClient, $this->getHttpRequest()); @@ -88,7 +80,7 @@ public function testSendDataWillCreateCaptureAndReturnResponseWithCaptureData() $response = $this->setExpectedPostRequest( $requestdata, $responseData, - self::BASE_URL.'/ordermanagement/v1/orders/'.self::TRANSACTION_REF.'/captures' + self::BASE_URL . '/ordermanagement/v1/orders/' . self::TRANSACTION_REF . '/captures' ); $response->expects(self::once())->method('getStatusCode')->willReturn(204); diff --git a/tests/Message/ExtendAuthorizationRequestTest.php b/tests/Message/ExtendAuthorizationRequestTest.php index 913fc6b..c6e8bab 100644 --- a/tests/Message/ExtendAuthorizationRequestTest.php +++ b/tests/Message/ExtendAuthorizationRequestTest.php @@ -10,15 +10,10 @@ final class ExtendAuthorizationRequestTest extends RequestTestCase { - /** - * @var ExtendAuthorizationRequest - */ + /** @var ExtendAuthorizationRequest */ private $extendAuthorizationRequest; - /** - * @inheritdoc - */ - protected function setUp() + protected function setUp(): void { parent::setUp(); $this->extendAuthorizationRequest = new ExtendAuthorizationRequest($this->httpClient, $this->getHttpRequest()); @@ -48,18 +43,18 @@ public function testSendDataWillWillSendDataToKlarnaEndPointAndReturnCorrectResp ->method('request') ->with( 'POST', - sprintf( + \sprintf( '%s/ordermanagement/v1/orders/%s/extend-authorization-time', self::BASE_URL, 'foo' ), - array_merge( + \array_merge( ['Content-Type' => 'application/json'], [ - 'Authorization' => sprintf( + 'Authorization' => \sprintf( 'Basic %s', - base64_encode( - sprintf( + \base64_encode( + \sprintf( '%s:%s', null, self::SECRET diff --git a/tests/Message/FetchTransactionRequestTest.php b/tests/Message/FetchTransactionRequestTest.php index ede7509..349e33e 100644 --- a/tests/Message/FetchTransactionRequestTest.php +++ b/tests/Message/FetchTransactionRequestTest.php @@ -14,15 +14,10 @@ final class FetchTransactionRequestTest extends RequestTestCase { use ExpectedAuthorizationHeaderTrait; - /** - * @var FetchTransactionRequest - */ + /** @var FetchTransactionRequest */ private $fetchTransactionRequest; - /** - * @inheritdoc - */ - protected function setUp() + protected function setUp(): void { parent::setUp(); $this->fetchTransactionRequest = new FetchTransactionRequest($this->httpClient, $this->getHttpRequest()); @@ -49,7 +44,7 @@ public function testSendDataWillReturnResponseFromCheckoutApiForIncompleteOrder( $response = $this->setExpectedGetRequest( $expectedCheckoutData, - self::BASE_URL.'/checkout/v3/orders/foo' + self::BASE_URL . '/checkout/v3/orders/foo' ); $response->expects(self::once())->method('getStatusCode')->willReturn(200); @@ -74,7 +69,7 @@ public function testSendDataWillReturnResponseFromCheckoutApiForUnknownOrder() $response = $this->setExpectedGetRequest( $expectedCheckoutData, - self::BASE_URL.'/checkout/v3/orders/foo' + self::BASE_URL . '/checkout/v3/orders/foo' ); $response->expects(self::once())->method('getStatusCode')->willReturn(200); @@ -105,15 +100,15 @@ public function testSendDataWillReturnResponseFromManagementApiForCompleteOrder( ->withConsecutive( [ 'GET', - self::BASE_URL.'/checkout/v3/orders/foo', + self::BASE_URL . '/checkout/v3/orders/foo', $this->getExpectedHeaders(), - null + null, ], [ 'GET', - self::BASE_URL.'/ordermanagement/v1/orders/foo', + self::BASE_URL . '/ordermanagement/v1/orders/foo', $this->getExpectedHeaders(), - null + null, ] )->willReturn($response); @@ -155,15 +150,15 @@ public function testSendDataWillReturnResponseFromManagementApiForDeletedCheckou ->withConsecutive( [ 'GET', - self::BASE_URL.'/checkout/v3/orders/foo', + self::BASE_URL . '/checkout/v3/orders/foo', $this->getExpectedHeaders(), - null + null, ], [ 'GET', - self::BASE_URL.'/ordermanagement/v1/orders/foo', + self::BASE_URL . '/ordermanagement/v1/orders/foo', $this->getExpectedHeaders(), - null + null, ] )->willReturn($response); diff --git a/tests/Message/ItemDataTestTrait.php b/tests/Message/ItemDataTestTrait.php index d589447..9a9b9ba 100644 --- a/tests/Message/ItemDataTestTrait.php +++ b/tests/Message/ItemDataTestTrait.php @@ -4,6 +4,7 @@ namespace MyOnlineStore\Tests\Omnipay\KlarnaCheckout\Message; use MyOnlineStore\Omnipay\KlarnaCheckout\ItemInterface; +use PHPUnit\Framework\MockObject\MockObject; trait ItemDataTestTrait { @@ -22,10 +23,7 @@ protected function getExpectedOrderLine(): array ]; } - /** - * @return \PHPUnit_Framework_MockObject_MockObject - */ - protected function getItemMock(): \PHPUnit_Framework_MockObject_MockObject + protected function getItemMock(): MockObject { $item = $this->createMock(ItemInterface::class); $item->method('getType')->willReturn('shipping_fee'); diff --git a/tests/Message/RefundRequestTest.php b/tests/Message/RefundRequestTest.php index 7106c18..80545ab 100644 --- a/tests/Message/RefundRequestTest.php +++ b/tests/Message/RefundRequestTest.php @@ -11,15 +11,10 @@ class RefundRequestTest extends RequestTestCase { use ItemDataTestTrait; - /** - * @var RefundRequest - */ + /** @var RefundRequest */ private $refundRequest; - /** - * @inheritdoc - */ - protected function setUp() + protected function setUp(): void { parent::setUp(); $this->refundRequest = new RefundRequest($this->httpClient, $this->getHttpRequest()); @@ -77,7 +72,7 @@ public function testSendDataWillCreateRefundAndReturnResponse() $response = $this->setExpectedPostRequest( $inputData, $expectedData, - self::BASE_URL.'/ordermanagement/v1/orders/foo/refunds' + self::BASE_URL . '/ordermanagement/v1/orders/foo/refunds' ); $response->expects(self::once())->method('getStatusCode')->willReturn(204); diff --git a/tests/Message/RequestTestCase.php b/tests/Message/RequestTestCase.php index a9303ac..d73f125 100644 --- a/tests/Message/RequestTestCase.php +++ b/tests/Message/RequestTestCase.php @@ -6,6 +6,7 @@ use MyOnlineStore\Tests\Omnipay\KlarnaCheckout\ExpectedAuthorizationHeaderTrait; use Omnipay\Common\Http\ClientInterface; use Omnipay\Tests\TestCase; +use PHPUnit\Framework\MockObject\MockObject; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\StreamInterface; @@ -13,19 +14,14 @@ abstract class RequestTestCase extends TestCase { use ExpectedAuthorizationHeaderTrait; - const BASE_URL = 'http://localhost'; - const SECRET = 'very-secret-stuff'; - const USERNAME = 'merchant-32'; + public const BASE_URL = 'http://localhost'; + public const SECRET = 'very-secret-stuff'; + public const USERNAME = 'merchant-32'; - /** - * @var ClientInterface|\PHPUnit_Framework_MockObject_MockObject - */ + /** @var ClientInterface|MockObject */ protected $httpClient; - /** - * @inheritdoc - */ - protected function setUp() + protected function setUp(): void { $this->httpClient = $this->createMock(ClientInterface::class); } @@ -34,7 +30,7 @@ protected function setUp() * @param array $responseData * @param string $url * - * @return ResponseInterface|\PHPUnit_Framework_MockObject_MockObject + * @return ResponseInterface|MockObject */ protected function setExpectedGetRequest(array $responseData, $url) { @@ -46,7 +42,7 @@ protected function setExpectedGetRequest(array $responseData, $url) * @param array $responseData * @param string $url * - * @return ResponseInterface|\PHPUnit_Framework_MockObject_MockObject + * @return ResponseInterface|MockObject */ protected function setExpectedPatchRequest(array $inputData, array $responseData, $url) { @@ -64,7 +60,7 @@ protected function setExpectedPatchRequest(array $inputData, array $responseData * @param array $responseData * @param string $url * - * @return ResponseInterface|\PHPUnit_Framework_MockObject_MockObject + * @return ResponseInterface|MockObject */ protected function setExpectedPostRequest(array $inputData, array $responseData, $url) { @@ -84,13 +80,13 @@ protected function setExpectedPostRequest(array $inputData, array $responseData, * @param array $inputData * @param array $responseData * - * @return ResponseInterface|\PHPUnit_Framework_MockObject_MockObject + * @return ResponseInterface|MockObject */ private function setExpectedRequest( $requestMethod, $url, array $headers, - array $inputData = null, + ?array $inputData = null, array $responseData ) { $response = $this->createMock(ResponseInterface::class); @@ -101,7 +97,7 @@ private function setExpectedRequest( ->with( $requestMethod, $url, - array_merge( + \array_merge( $headers, $this->getExpectedHeaders() ), diff --git a/tests/Message/UpdateCustomerAddressRequestTest.php b/tests/Message/UpdateCustomerAddressRequestTest.php index 8362bab..fbe526e 100644 --- a/tests/Message/UpdateCustomerAddressRequestTest.php +++ b/tests/Message/UpdateCustomerAddressRequestTest.php @@ -9,15 +9,10 @@ final class UpdateCustomerAddressRequestTest extends RequestTestCase { - /** - * @var UpdateCustomerAddressRequest - */ + /** @var UpdateCustomerAddressRequest */ private $updateCustomerAddressRequest; - /** - * @inheritdoc - */ - protected function setUp() + protected function setUp(): void { parent::setUp(); @@ -158,7 +153,7 @@ public function testSendDataWillWillSendDataToKlarnaEndPointAndReturnCorrectResp $response = $this->setExpectedPatchRequest( $data, $responseData, - sprintf('%s/ordermanagement/v1/orders/%s/customer-details', self::BASE_URL, $transactionReference) + \sprintf('%s/ordermanagement/v1/orders/%s/customer-details', self::BASE_URL, $transactionReference) ); $response->expects(self::once())->method('getStatusCode')->willReturn(204); @@ -177,7 +172,7 @@ public function testSendDataWillWillSendDataToKlarnaEndPointAndReturnCorrectResp self::assertInstanceOf(UpdateCustomerAddressResponse::class, $updateCustomerAddressResponse); self::assertSame($transactionReference, $updateCustomerAddressResponse->getTransactionReference()); self::assertSame( - array_merge($responseData, ['order_id' => $transactionReference]), + \array_merge($responseData, ['order_id' => $transactionReference]), $updateCustomerAddressResponse->getData() ); self::assertTrue($updateCustomerAddressResponse->isSuccessful()); diff --git a/tests/Message/UpdateMerchantReferencesRequestTest.php b/tests/Message/UpdateMerchantReferencesRequestTest.php index 64b902e..a277bf3 100644 --- a/tests/Message/UpdateMerchantReferencesRequestTest.php +++ b/tests/Message/UpdateMerchantReferencesRequestTest.php @@ -10,12 +10,12 @@ final class UpdateMerchantReferencesRequestTest extends RequestTestCase { - const TRANSACTION_REFERENCE = 1234; + public const TRANSACTION_REFERENCE = 1234; /** @var UpdateTransactionRequest */ private $updateTransactionRequest; - protected function setUp() + protected function setUp(): void { parent::setUp(); diff --git a/tests/Message/UpdateTransactionRequestTest.php b/tests/Message/UpdateTransactionRequestTest.php index 2f13a0d..3ac4f62 100644 --- a/tests/Message/UpdateTransactionRequestTest.php +++ b/tests/Message/UpdateTransactionRequestTest.php @@ -7,25 +7,18 @@ use MyOnlineStore\Omnipay\KlarnaCheckout\Message\UpdateTransactionResponse; use MyOnlineStore\Tests\Omnipay\KlarnaCheckout\ExpectedAuthorizationHeaderTrait; use Omnipay\Common\Exception\InvalidRequestException; -use Psr\Http\Message\ResponseInterface; -use Psr\Http\Message\StreamInterface; class UpdateTransactionRequestTest extends RequestTestCase { use ItemDataTestTrait; use MerchantUrlsDataTestTrait; use ExpectedAuthorizationHeaderTrait; - const TRANSACTION_REFERENCE = 1234; - /** - * @var UpdateTransactionRequest - */ - private $updateTransactionRequest; + public const TRANSACTION_REFERENCE = 1234; - /** - * @inheritdoc - */ - protected function setUp() + private UpdateTransactionRequest $updateTransactionRequest; + + protected function setUp(): void { parent::setUp(); $this->updateTransactionRequest = new UpdateTransactionRequest($this->httpClient, $this->getHttpRequest()); @@ -251,7 +244,7 @@ public function testGetDataWithMerchantUrlsWillReturnCorrectData( $expectedMerchantUrls ) { $this->updateTransactionRequest->initialize( - array_merge( + \array_merge( [ 'amount' => '100.00', 'tax_amount' => 21, @@ -356,7 +349,7 @@ public function testSendDataWillCreateOrderAndReturnResponse() $this->setExpectedPostRequest( $inputData, $responseData, - sprintf('%s/checkout/v3/orders/%s', self::BASE_URL, self::TRANSACTION_REFERENCE) + \sprintf('%s/checkout/v3/orders/%s', self::BASE_URL, self::TRANSACTION_REFERENCE) ); $this->updateTransactionRequest->initialize( @@ -373,107 +366,4 @@ public function testSendDataWillCreateOrderAndReturnResponse() self::assertInstanceOf(UpdateTransactionResponse::class, $updateTransactionResponse); self::assertSame($responseData, $updateTransactionResponse->getData()); } - - public function testSendDataWillUpdateManagementCustomerDetailsAndFailUpdatingMerchantReferences() - { - $inputData = ['merchant_reference1' => 'foo']; - - $response = $this->createMock(ResponseInterface::class); - $stream = $this->createMock(StreamInterface::class); - - $this->httpClient->expects(self::exactly(2)) - ->method('request') - ->withConsecutive( - [ - 'POST', - sprintf('%s/checkout/v3/orders/%s', self::BASE_URL, self::TRANSACTION_REFERENCE), - array_merge(['Content-Type' => 'application/json'], $this->getExpectedHeaders()), - \json_encode($inputData), - ], - [ - 'PATCH', - sprintf( - '%s/ordermanagement/v1/orders/%s/merchant-references', - self::BASE_URL, - self::TRANSACTION_REFERENCE - ), - array_merge( - ['Content-Type' => 'application/json'], - $this->getExpectedHeaders() - ), - \json_encode($inputData), - ] - ) - ->willReturn($response); - - $response->method('getBody')->willReturn($stream); - $stream->expects(self::exactly(2)) - ->method('getContents') - ->willReturnOnConsecutiveCalls( - \json_encode(['error_code' => 'READ_ONLY_ORDER']), - \json_encode(['error_code' => 'doomsday']) - ); - - $this->updateTransactionRequest->initialize( - [ - 'base_url' => self::BASE_URL, - 'username' => self::USERNAME, - 'secret' => self::SECRET, - 'transactionReference' => self::TRANSACTION_REFERENCE, - ] - ); - - self::assertFalse($this->updateTransactionRequest->sendData($inputData)->isSuccessful()); - } - - public function testSendDataWillUpdateOrderManagementMerchantReferences() - { - $merchantReferencesData = ['merchant_reference1' => 'baz', 'merchant_reference2' => 'quz']; - - $response = $this->createMock(ResponseInterface::class); - $stream = $this->createMock(StreamInterface::class); - - $this->httpClient->expects(self::exactly(2)) - ->method('request') - ->withConsecutive( - [ - 'POST', - sprintf('%s/checkout/v3/orders/%s', self::BASE_URL, self::TRANSACTION_REFERENCE), - array_merge(['Content-Type' => 'application/json'], $this->getExpectedHeaders()), - \json_encode($merchantReferencesData), - ], - [ - 'PATCH', - sprintf( - '%s/ordermanagement/v1/orders/%s/merchant-references', - self::BASE_URL, - self::TRANSACTION_REFERENCE - ), - array_merge(['Content-Type' => 'application/json'], $this->getExpectedHeaders()), - \json_encode($merchantReferencesData), - ] - ) - ->willReturn($response); - - $response->method('getBody')->willReturn($stream); - $stream->expects(self::exactly(2)) - ->method('getContents') - ->willReturnOnConsecutiveCalls( - \json_encode(['error_code' => 'READ_ONLY_ORDER']), - \json_encode([]) - ); - - $this->updateTransactionRequest->initialize( - [ - 'base_url' => self::BASE_URL, - 'username' => self::USERNAME, - 'secret' => self::SECRET, - 'transactionReference' => self::TRANSACTION_REFERENCE, - ] - ); - - $updateTransactionResponse = $this->updateTransactionRequest->sendData($merchantReferencesData); - self::assertEmpty($updateTransactionResponse->getData()); - self::assertTrue($updateTransactionResponse->isSuccessful()); - } } diff --git a/tests/Message/VoidRequestTest.php b/tests/Message/VoidRequestTest.php index a9bc6b3..2626f65 100644 --- a/tests/Message/VoidRequestTest.php +++ b/tests/Message/VoidRequestTest.php @@ -11,17 +11,12 @@ class VoidRequestTest extends RequestTestCase { - const TRANSACTION_REF = 'foo'; + public const TRANSACTION_REF = 'foo'; - /** - * @var VoidRequest - */ + /** @var VoidRequest */ private $voidRequest; - /** - * @inheritdoc - */ - protected function setUp() + protected function setUp(): void { parent::setUp(); $this->voidRequest = new VoidRequest($this->httpClient, $this->getHttpRequest()); @@ -63,15 +58,15 @@ public function testSendDataWillVoidOrderAndReturnResponse(array $captures, $exp ->withConsecutive( [ 'GET', - self::BASE_URL.'/ordermanagement/v1/orders/'.self::TRANSACTION_REF, + self::BASE_URL . '/ordermanagement/v1/orders/' . self::TRANSACTION_REF, $this->getExpectedHeaders(), - null + null, ], [ 'POST', - self::BASE_URL.'/ordermanagement/v1/orders/'.self::TRANSACTION_REF.$expectedPostRoute, - array_merge(['Content-Type' => 'application/json'], $this->getExpectedHeaders()), - \json_encode($inputData) + self::BASE_URL . '/ordermanagement/v1/orders/' . self::TRANSACTION_REF . $expectedPostRoute, + \array_merge(['Content-Type' => 'application/json'], $this->getExpectedHeaders()), + \json_encode($inputData), ] ) ->willReturn($response); diff --git a/tests/Message/VoidResponseTest.php b/tests/Message/VoidResponseTest.php index 16b2e8d..0f8f23a 100644 --- a/tests/Message/VoidResponseTest.php +++ b/tests/Message/VoidResponseTest.php @@ -18,7 +18,7 @@ final class VoidResponseTest extends TestCase */ public function responseCodeProvider(): array { - return [[204, true], [403, false],]; + return [[204, true], [403, false]]; } public function testGetCommonValuesReturnCorrectValues()