From 79983463fea0ce475d6905857d7cb0ce46290c0f Mon Sep 17 00:00:00 2001 From: Jan Langer Date: Mon, 25 Nov 2024 10:52:57 +0100 Subject: [PATCH] Updated dependencies --- .github/workflows/build.yml | 2 +- composer.json | 11 ++-- src/AdditionalData/OrderAddress.php | 4 +- src/Api/Driver/CurlDriver.php | 7 +-- src/Crypto/CryptoService.php | 13 +--- tests/phpunit.xml | 59 ++++++++++--------- tests/unit/Api/ApiClientTest.php | 4 +- .../TransactionSettlementExtensionTest.php | 5 +- tests/unit/Crypto/CryptoServiceTest.php | 2 +- .../Crypto/SignatureDataFormatterTest.php | 2 +- tests/unit/RequestFactoryTest.php | 48 +++++++-------- 11 files changed, 71 insertions(+), 86 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 011b993..56b6911 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -189,7 +189,7 @@ jobs: run: "composer update --prefer-dist --no-interaction --no-progress --no-suggest" - name: "Tests" - run: "composer run check:tests" + run: "composer run check:tests-coverage" - name: "Upload to Codecov.io" env: diff --git a/composer.json b/composer.json index 70608ee..b79e07f 100644 --- a/composer.json +++ b/composer.json @@ -22,10 +22,10 @@ "ext-curl": "*", "guzzlehttp/guzzle": "^6.4.1 || ^7.0.1", "php-parallel-lint/php-parallel-lint": "^1.3.1", - "phpstan/phpstan": "^1.7.15", - "phpstan/phpstan-phpunit": "^1.1.1", - "phpstan/phpstan-strict-rules": "^1.2.3", - "phpunit/phpunit": "^9.5.21", + "phpstan/phpstan": "^2.0.2", + "phpstan/phpstan-phpunit": "^2.0.1", + "phpstan/phpstan-strict-rules": "^2.0.0", + "phpunit/phpunit": "^10.5.38", "psr/log": "^3.0.0", "slevomat/coding-standard": "^8.0.0", "squizlabs/php_codesniffer": "^3.7.1" @@ -38,7 +38,8 @@ "@check:types", "@check:tests" ], - "check:tests": "php ./vendor/phpunit/phpunit/phpunit -d memory_limit=512M --configuration tests/phpunit.xml tests", + "check:tests-coverage": "php ./vendor/phpunit/phpunit/phpunit -d memory_limit=512M --configuration tests/phpunit.xml tests", + "check:tests": "@check:tests-coverage --no-coverage", "check:cs": "php ./vendor/squizlabs/php_codesniffer/bin/phpcs --standard=build --extensions=php --encoding=utf-8 --tab-width=4 -sp src tests", "fix:cs": "php ./vendor/squizlabs/php_codesniffer/bin/phpcbf --standard=build --extensions=php --encoding=utf-8 --tab-width=4 -sp src tests", "check:lint": "php ./vendor/php-parallel-lint/php-parallel-lint/parallel-lint src tests", diff --git a/src/AdditionalData/OrderAddress.php b/src/AdditionalData/OrderAddress.php index 15f29fe..a26ddfa 100644 --- a/src/AdditionalData/OrderAddress.php +++ b/src/AdditionalData/OrderAddress.php @@ -31,9 +31,7 @@ public function __construct( if ($this->address3 !== null) { Validator::checkWhitespacesAndLength($this->address3, self::ADDRESS_LENGTH_MAX); } - if ($this->city !== null) { - Validator::checkWhitespacesAndLength($this->city, self::ADDRESS_LENGTH_MAX); - } + Validator::checkWhitespacesAndLength($this->city, self::ADDRESS_LENGTH_MAX); Validator::checkWhitespacesAndLength($this->zip, self::ZIP_LENGTH_MAX); } diff --git a/src/Api/Driver/CurlDriver.php b/src/Api/Driver/CurlDriver.php index 2d20014..fa2bd62 100644 --- a/src/Api/Driver/CurlDriver.php +++ b/src/Api/Driver/CurlDriver.php @@ -23,7 +23,6 @@ use const CURLOPT_RETURNTRANSFER; use const CURLOPT_SSL_VERIFYPEER; use const CURLOPT_TIMEOUT; -use const PHP_VERSION_ID; class CurlDriver implements ApiClientDriver { @@ -46,7 +45,7 @@ public function request(HttpMethod $method, string $url, ?array $data, array $he if ($method === HttpMethod::POST || $method === HttpMethod::PUT) { curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method->value); - curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data)); + curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data, JSON_THROW_ON_ERROR)); } curl_setopt($ch, CURLOPT_TIMEOUT, $this->timeout); @@ -69,10 +68,6 @@ public function request(HttpMethod $method, string $url, ?array $data, array $he $body = substr((string) $output, $headerSize); $responseCode = ResponseCode::from(curl_getinfo($ch, CURLINFO_HTTP_CODE)); - if (PHP_VERSION_ID < 80000) { - curl_close($ch); - } - return new Response( $responseCode, json_decode($body, true), diff --git a/src/Crypto/CryptoService.php b/src/Crypto/CryptoService.php index 7fcc95d..accf915 100644 --- a/src/Crypto/CryptoService.php +++ b/src/Crypto/CryptoService.php @@ -6,7 +6,6 @@ use function base64_encode; use function file_get_contents; use const OPENSSL_ALGO_SHA256; -use const PHP_VERSION_ID; class CryptoService { @@ -46,13 +45,7 @@ public function signData(array $data, SignatureDataFormatter $signatureDataForma throw new SigningFailedException($data); } - $signature = base64_encode($signature); - if (PHP_VERSION_ID < 80000) { - // phpcs:ignore Generic.PHP.DeprecatedFunctions - openssl_free_key($privateKeyId); - } - - return $signature; + return base64_encode($signature); } /** @@ -77,10 +70,6 @@ public function verifyData(array $data, string $signature, SignatureDataFormatte } $verifyResult = openssl_verify($message, $signature, $publicKeyId, self::HASH_METHOD); - if (PHP_VERSION_ID < 80000) { - // phpcs:ignore Generic.PHP.DeprecatedFunctions - openssl_free_key($publicKeyId); - } if ($verifyResult === -1) { throw new VerificationFailedException($data, (string) openssl_error_string()); } diff --git a/tests/phpunit.xml b/tests/phpunit.xml index 76502ea..66f31a7 100644 --- a/tests/phpunit.xml +++ b/tests/phpunit.xml @@ -1,34 +1,37 @@ - - - ../src - - - - - - - - - - - unit - - + + + ../src + + + + + + + + + + + + + unit + + - + diff --git a/tests/unit/Api/ApiClientTest.php b/tests/unit/Api/ApiClientTest.php index f94a712..3c4ede4 100644 --- a/tests/unit/Api/ApiClientTest.php +++ b/tests/unit/Api/ApiClientTest.php @@ -20,7 +20,7 @@ class ApiClientTest extends TestCase /** * @return mixed[] */ - public function getRequests(): array + public static function getRequests(): array { return [ [ @@ -200,7 +200,7 @@ public function testRequests( /** * @return mixed[] */ - public function getTestExceptions(): array + public static function getTestExceptions(): array { return [ [ diff --git a/tests/unit/Call/Extension/TransactionSettlementExtensionTest.php b/tests/unit/Call/Extension/TransactionSettlementExtensionTest.php index 75fa294..3d3403c 100644 --- a/tests/unit/Call/Extension/TransactionSettlementExtensionTest.php +++ b/tests/unit/Call/Extension/TransactionSettlementExtensionTest.php @@ -2,7 +2,6 @@ namespace SlevomatCsobGateway\Call\Extension; -use DateTimeImmutable; use PHPUnit\Framework\TestCase; class TransactionSettlementExtensionTest extends TestCase @@ -18,11 +17,11 @@ public function testCreateResponse(): void ]); self::assertSame('2016-04-12 12:06:20 848000', $transactionSettlementResponse->getCreatedDate()->format('Y-m-d H:i:s u')); - /** @var DateTimeImmutable $authDate */ + $authDate = $transactionSettlementResponse->getAuthDate(); self::assertNotNull($authDate); self::assertSame('2016-04-12 10:06:35', $authDate->format('Y-m-d H:i:s')); - /** @var DateTimeImmutable $settlementDate */ + $settlementDate = $transactionSettlementResponse->getSettlementDate(); self::assertNotNull($settlementDate); self::assertSame('2016-04-12', $settlementDate->format('Y-m-d')); diff --git a/tests/unit/Crypto/CryptoServiceTest.php b/tests/unit/Crypto/CryptoServiceTest.php index a9a0f5a..5ae6a0c 100644 --- a/tests/unit/Crypto/CryptoServiceTest.php +++ b/tests/unit/Crypto/CryptoServiceTest.php @@ -20,7 +20,7 @@ protected function setUp(): void /** * @return mixed[] */ - public function getSignDataData(): array + public static function getSignDataData(): array { return [ [ diff --git a/tests/unit/Crypto/SignatureDataFormatterTest.php b/tests/unit/Crypto/SignatureDataFormatterTest.php index 6ec0e03..682dfc7 100644 --- a/tests/unit/Crypto/SignatureDataFormatterTest.php +++ b/tests/unit/Crypto/SignatureDataFormatterTest.php @@ -10,7 +10,7 @@ class SignatureDataFormatterTest extends TestCase /** * @return mixed[] */ - public function getFormatDataForSignatureData(): array + public static function getFormatDataForSignatureData(): array { return [ [ diff --git a/tests/unit/RequestFactoryTest.php b/tests/unit/RequestFactoryTest.php index 6dc4a9c..0e19c70 100644 --- a/tests/unit/RequestFactoryTest.php +++ b/tests/unit/RequestFactoryTest.php @@ -61,70 +61,70 @@ public function testCreateInitPayment(): void 1, ); - self::assertTrue(true); + $this->expectNotToPerformAssertions(); } public function testCreateProcessPayment(): void { $this->requestFactory->createProcessPayment('123456789'); - self::assertTrue(true); + $this->expectNotToPerformAssertions(); } public function testCreatePaymentStatus(): void { $this->requestFactory->createPaymentStatus('123456789'); - self::assertTrue(true); + $this->expectNotToPerformAssertions(); } public function testCreateReversePayment(): void { $this->requestFactory->createReversePayment('123456789'); - self::assertTrue(true); + $this->expectNotToPerformAssertions(); } public function testCreateClosePayment(): void { $this->requestFactory->createClosePayment('123456789'); - self::assertTrue(true); + $this->expectNotToPerformAssertions(); } public function testCreateRefundPayment(): void { $this->requestFactory->createRefundPayment('123456789'); - self::assertTrue(true); + $this->expectNotToPerformAssertions(); } public function testCreateEchoRequest(): void { $this->requestFactory->createEchoRequest(); - self::assertTrue(true); + $this->expectNotToPerformAssertions(); } public function testCreatePostEchoRequest(): void { $this->requestFactory->createPostEchoRequest(); - self::assertTrue(true); + $this->expectNotToPerformAssertions(); } public function testCreateEchoCustomer(): void { $this->requestFactory->createEchoCustomer('cust123@mail.com'); - self::assertTrue(true); + $this->expectNotToPerformAssertions(); } public function testCreateReceivePayment(): void { $this->requestFactory->createReceivePaymentRequest(); - self::assertTrue(true); + $this->expectNotToPerformAssertions(); } public function testCreateOneclickInitPayment(): void @@ -139,14 +139,14 @@ public function testCreateOneclickInitPayment(): void HttpMethod::POST, ); - self::assertTrue(true); + $this->expectNotToPerformAssertions(); } public function testCreateOneclickProcessPayment(): void { $this->requestFactory->createOneclickProcessPayment('ef08b6e9f22345c'); - self::assertTrue(true); + $this->expectNotToPerformAssertions(); } public function testCreatePaymentButtonRequest(): void @@ -162,14 +162,14 @@ public function testCreatePaymentButtonRequest(): void Language::EN, ); - self::assertTrue(true); + $this->expectNotToPerformAssertions(); } public function testCreateApplePayEchoRequest(): void { $this->requestFactory->createApplePayEchoRequest(); - self::assertTrue(true); + $this->expectNotToPerformAssertions(); } public function testCreateApplePayInitRequest(): void @@ -201,7 +201,7 @@ public function testCreateApplePayInitRequest(): void HttpMethod::POST, ); - self::assertTrue(true); + $this->expectNotToPerformAssertions(); } public function testCreateApplePayProcessRequest(): void @@ -224,21 +224,21 @@ public function testCreateApplePayProcessRequest(): void ), ); - self::assertTrue(true); + $this->expectNotToPerformAssertions(); } public function testCreateOneClickEchoRequest(): void { $this->requestFactory->createOneClickEchoRequest('ef08b6e9f22345c'); - self::assertTrue(true); + $this->expectNotToPerformAssertions(); } public function testCreateMallPayCancelRequest(): void { $this->requestFactory->createMallPayCancelRequest('ef08b6e9f22345c', CancelReason::ABANDONED); - self::assertTrue(true); + $this->expectNotToPerformAssertions(); } public function testCreateMallPayInitRequest(): void @@ -299,7 +299,7 @@ public function testCreateMallPayInitRequest(): void null, ); - self::assertTrue(true); + $this->expectNotToPerformAssertions(); } public function testCreateMMallPayLogisticsRequest(): void @@ -315,7 +315,7 @@ public function testCreateMMallPayLogisticsRequest(): void '123456', ); - self::assertTrue(true); + $this->expectNotToPerformAssertions(); } public function testCreateMallPayRefundRequest(): void @@ -323,7 +323,7 @@ public function testCreateMallPayRefundRequest(): void $orderItemReference = new OrderItemReference('123', null, 'Thing', OrderItemType::DIGITAL, 1); $this->requestFactory->createMallPayRefundRequest('ef08b6e9f22345c', null, [$orderItemReference]); - self::assertTrue(true); + $this->expectNotToPerformAssertions(); } public function testCreateGooglePayInitRequest(): void @@ -338,7 +338,7 @@ public function testCreateGooglePayInitRequest(): void HttpMethod::POST, ); - self::assertTrue(true); + $this->expectNotToPerformAssertions(); } public function testCreateGooglePayProcessRequest(): void @@ -358,14 +358,14 @@ public function testCreateGooglePayProcessRequest(): void ), ); - self::assertTrue(true); + $this->expectNotToPerformAssertions(); } public function testCreateGooglePayEchoRequest(): void { $this->requestFactory->createGooglePayEchoRequest(); - self::assertTrue(true); + $this->expectNotToPerformAssertions(); } }