From 897e0791d45ac7e6869395ee9c1382073041a560 Mon Sep 17 00:00:00 2001 From: Michiel Devriese Date: Wed, 18 Sep 2024 15:02:08 +0200 Subject: [PATCH 1/3] Loosen `psr/http-message` version to allow `^2.0` --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index e0329f3f..1f8434e7 100644 --- a/composer.json +++ b/composer.json @@ -30,7 +30,7 @@ "ext-soap": "*", "moneyphp/money": "^3.0 || ^4.0", "myclabs/php-enum": "^1.5", - "psr/http-message": "^1.0", + "psr/http-message": "^1.0 || ^2.0", "psr/log": "^1.0 || ^2.0 || ^3.0", "webmozart/assert": "^1.2" }, From 0684fdb04d6e7c283d6dfc844fddc40f4f0fe214 Mon Sep 17 00:00:00 2001 From: Roj Vroemen Date: Wed, 18 Sep 2024 16:11:51 +0200 Subject: [PATCH 2/3] Fix mocked return value used in tests when using `psr/http-message:^2.0` --- tests/Dummy/StringStream.php | 81 +++++++++++++++++++ .../Secure/Provider/OAuthProviderTest.php | 7 +- 2 files changed, 85 insertions(+), 3 deletions(-) create mode 100644 tests/Dummy/StringStream.php diff --git a/tests/Dummy/StringStream.php b/tests/Dummy/StringStream.php new file mode 100644 index 00000000..6219f0a3 --- /dev/null +++ b/tests/Dummy/StringStream.php @@ -0,0 +1,81 @@ +value = $value; + } + + public function __toString(): string + { + return $this->value; + } + + public function close(): void + { + } + + public function detach() + { + } + + public function getSize(): ?int + { + } + + public function tell(): int + { + } + + public function eof(): bool + { + } + + public function isSeekable(): bool + { + } + + public function seek(int $offset, int $whence = SEEK_SET): void + { + } + + public function rewind(): void + { + } + + public function isWritable(): bool + { + } + + public function write(string $string): int + { + } + + public function isReadable(): bool + { + } + + public function read(int $length): string + { + } + + public function getContents(): string + { + } + + public function getMetadata(?string $key = null) + { + } +} \ No newline at end of file diff --git a/tests/UnitTests/Secure/Provider/OAuthProviderTest.php b/tests/UnitTests/Secure/Provider/OAuthProviderTest.php index 29def3e2..71a90efa 100644 --- a/tests/UnitTests/Secure/Provider/OAuthProviderTest.php +++ b/tests/UnitTests/Secure/Provider/OAuthProviderTest.php @@ -2,6 +2,7 @@ namespace PhpTwinfield\Secure\Provider; +use Dummy\StringStream; use GuzzleHttp\ClientInterface; use League\OAuth2\Client\Provider\Exception\IdentityProviderException; use League\OAuth2\Client\Token\AccessToken; @@ -77,7 +78,7 @@ public function testGetAccessToken() $response = $this->createMock(ResponseInterface::class); $response->expects($this->any()) ->method("getBody") - ->willReturn('{"access_token":"mock_access_token", "token_type":"bearer"}'); + ->willReturn(new StringStream('{"access_token":"mock_access_token", "token_type":"bearer"}')); $response->expects($this->any()) ->method("getHeader") ->willReturn(['content-type' => 'json']); @@ -102,7 +103,7 @@ public function testExceptionThrownWhenErrorObjectReceived() $response = $this->createMock(ResponseInterface::class); $response->expects($this->any()) ->method("getBody") - ->willReturn('{"error":{"type":"request","message":"someErrorMessage"}}'); + ->willReturn(new StringStream('{"error":{"type":"request","message":"someErrorMessage"}}')); $response->expects($this->any()) ->method("getHeader") ->willReturn(['content-type' => 'json']); @@ -125,7 +126,7 @@ public function testGetResourceOwnerDetails() $response = $this->createMock(ResponseInterface::class); $response->expects($this->any()) ->method("getBody") - ->willReturn('{"sub": "someId", "twf.organisationId": "someOrganisationId"}'); + ->willReturn(new StringStream('{"sub": "someId", "twf.organisationId": "someOrganisationId"}')); $response->expects($this->any()) ->method("getHeader") ->willReturn(['content-type' => 'json']); From 5250150ec5b2b64a2af63981e418c5b91e18900d Mon Sep 17 00:00:00 2001 From: Roj Vroemen Date: Wed, 18 Sep 2024 16:30:21 +0200 Subject: [PATCH 3/3] Ignore phpstan errors of dummy `StringStream` --- phpstan.neon | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/phpstan.neon b/phpstan.neon index 364905f7..53adf318 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,2 +1,46 @@ parameters: ignoreErrors: + - + message: "#^Method Dummy\\\\StringStream\\:\\:eof\\(\\) should return bool but return statement is missing\\.$#" + count: 1 + path: tests/Dummy/StringStream.php + + - + message: "#^Method Dummy\\\\StringStream\\:\\:getContents\\(\\) should return string but return statement is missing\\.$#" + count: 1 + path: tests/Dummy/StringStream.php + + - + message: "#^Method Dummy\\\\StringStream\\:\\:getSize\\(\\) should return int\\|null but return statement is missing\\.$#" + count: 1 + path: tests/Dummy/StringStream.php + + - + message: "#^Method Dummy\\\\StringStream\\:\\:isReadable\\(\\) should return bool but return statement is missing\\.$#" + count: 1 + path: tests/Dummy/StringStream.php + + - + message: "#^Method Dummy\\\\StringStream\\:\\:isSeekable\\(\\) should return bool but return statement is missing\\.$#" + count: 1 + path: tests/Dummy/StringStream.php + + - + message: "#^Method Dummy\\\\StringStream\\:\\:isWritable\\(\\) should return bool but return statement is missing\\.$#" + count: 1 + path: tests/Dummy/StringStream.php + + - + message: "#^Method Dummy\\\\StringStream\\:\\:read\\(\\) should return string but return statement is missing\\.$#" + count: 1 + path: tests/Dummy/StringStream.php + + - + message: "#^Method Dummy\\\\StringStream\\:\\:tell\\(\\) should return int but return statement is missing\\.$#" + count: 1 + path: tests/Dummy/StringStream.php + + - + message: "#^Method Dummy\\\\StringStream\\:\\:write\\(\\) should return int but return statement is missing\\.$#" + count: 1 + path: tests/Dummy/StringStream.php \ No newline at end of file