From 0d79010fa4c337505c231ccb7ef35332b6172083 Mon Sep 17 00:00:00 2001 From: Frederik Rommel Date: Tue, 8 Jun 2021 18:33:36 +0200 Subject: [PATCH] feat: adds php8.0 compatibility --- .github/workflows/push.yml | 2 +- composer.json | 2 +- src/RequestBuilder.php | 2 +- src/Service/DeviceFingerprint.php | 30 +++++++++----------- src/Service/Util.php | 2 +- tests/Unit/Service/DeviceFingerprintTest.php | 11 ++++--- 6 files changed, 24 insertions(+), 25 deletions(-) diff --git a/.github/workflows/push.yml b/.github/workflows/push.yml index 99b178e..b098d5a 100644 --- a/.github/workflows/push.yml +++ b/.github/workflows/push.yml @@ -9,7 +9,7 @@ jobs: strategy: matrix: operating-system: ['ubuntu-latest'] - php-versions: ['7.0', '7.2', '7.4'] + php-versions: ['7.0', '7.2', '7.4', '8.0'] steps: - name: Checkout diff --git a/composer.json b/composer.json index 749286f..9a98eea 100755 --- a/composer.json +++ b/composer.json @@ -29,7 +29,7 @@ "require-dev": { "friendsofphp/php-cs-fixer": "^2.17@dev", "donatj/mock-webserver": "dev-master", - "phpunit/phpunit": "^6.5||^7.5||^8.5" + "phpunit/phpunit": "^6.5||^7.5||^8.5||^9.0" }, "minimum-stability": "dev", "autoload": { diff --git a/src/RequestBuilder.php b/src/RequestBuilder.php index cc02e5e..b2e0ff8 100755 --- a/src/RequestBuilder.php +++ b/src/RequestBuilder.php @@ -281,7 +281,7 @@ private function callMethod($name, $arguments) */ private function getMethod($name, $arguments) { - if (method_exists($this->responseModel, $name)) { + if ($this->responseModel && method_exists($this->responseModel, $name)) { if (count($arguments) > 0) { return $this->responseModel->$name(current($arguments)); } else { diff --git a/src/Service/DeviceFingerprint.php b/src/Service/DeviceFingerprint.php index 1fb4db0..a7cb9f5 100755 --- a/src/Service/DeviceFingerprint.php +++ b/src/Service/DeviceFingerprint.php @@ -49,22 +49,18 @@ public static function createDeviceIdentToken($identifier) */ public function getDeviceIdentSnippet($deviceIdentToken) { - $snippet = sprintf( - '', - json_encode([ - 't' => $deviceIdentToken, - 'v' => $this->deviceIdentSId, - 'l' => 'Checkout', - ]) - ); - - $snippet .= sprintf( - ' - ', - $this->deviceIdentSId, - $deviceIdentToken - ); - - return $snippet; + $params = [ + 't' => $deviceIdentToken, + 'v' => $this->deviceIdentSId, + 'l' => 'Checkout', + ]; + ob_start(); ?> + + + + $method(); if (!empty($var)) { return true; diff --git a/tests/Unit/Service/DeviceFingerprintTest.php b/tests/Unit/Service/DeviceFingerprintTest.php index 5cad6f4..4e1de9c 100644 --- a/tests/Unit/Service/DeviceFingerprintTest.php +++ b/tests/Unit/Service/DeviceFingerprintTest.php @@ -22,6 +22,9 @@ function microtime() use PHPUnit\Framework\TestCase; use RatePAY\Service\DeviceFingerprint; + /** + * @requires PHPUnit 7.5 + */ class DeviceFingerprintTest extends TestCase { public function testCreateDeviceIdentToken() @@ -33,16 +36,16 @@ public function testCreateDeviceIdentToken() $this->assertEquals($expectedHash, $hash); } + public function testGetDeviceIdentSnippet() { $deviceFingerprint = new DeviceFingerprint('hello-world-123'); $snippet = $deviceFingerprint->getDeviceIdentSnippet('secure-token-123'); - $expectedSnippet = ' - '; - - $this->assertEquals($expectedSnippet, $snippet); + $this->assertStringContainsString('//d.ratepay.com/di.css?t=secure-token-123&v=hello-world-123&l=Checkout', $snippet); + $this->assertStringContainsString('{"t":"secure-token-123","v":"hello-world-123","l":"Checkout"}', $snippet); + $this->assertStringContainsString('//d.ratepay.com/hello-world-123/di.js', $snippet); } } }