Skip to content

Commit

Permalink
Fix mocked return value used in tests when using psr/http-message:^2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
rojtjo committed Sep 18, 2024
1 parent 897e079 commit 0684fdb
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 3 deletions.
81 changes: 81 additions & 0 deletions tests/Dummy/StringStream.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<?php

declare(strict_types=1);

namespace Dummy;

use Psr\Http\Message\StreamInterface;

final class StringStream implements StreamInterface
{
/**
* @var string
*/
private $value;

public function __construct(string $value)
{
$this->value = $value;
}

public function __toString(): string
{
return $this->value;
}

public function close(): void
{
}

public function detach()
{
}

public function getSize(): ?int

Check failure on line 34 in tests/Dummy/StringStream.php

View workflow job for this annotation

GitHub Actions / PHP 7.3

Method Dummy\StringStream::getSize() should return int|null but return statement is missing.

Check failure on line 34 in tests/Dummy/StringStream.php

View workflow job for this annotation

GitHub Actions / PHP 7.4

Method Dummy\StringStream::getSize() should return int|null but return statement is missing.

Check failure on line 34 in tests/Dummy/StringStream.php

View workflow job for this annotation

GitHub Actions / PHP 8

Method Dummy\StringStream::getSize() should return int|null but return statement is missing.
{
}

public function tell(): int

Check failure on line 38 in tests/Dummy/StringStream.php

View workflow job for this annotation

GitHub Actions / PHP 7.3

Method Dummy\StringStream::tell() should return int but return statement is missing.

Check failure on line 38 in tests/Dummy/StringStream.php

View workflow job for this annotation

GitHub Actions / PHP 7.4

Method Dummy\StringStream::tell() should return int but return statement is missing.

Check failure on line 38 in tests/Dummy/StringStream.php

View workflow job for this annotation

GitHub Actions / PHP 8

Method Dummy\StringStream::tell() should return int but return statement is missing.
{
}

public function eof(): bool

Check failure on line 42 in tests/Dummy/StringStream.php

View workflow job for this annotation

GitHub Actions / PHP 7.3

Method Dummy\StringStream::eof() should return bool but return statement is missing.

Check failure on line 42 in tests/Dummy/StringStream.php

View workflow job for this annotation

GitHub Actions / PHP 7.4

Method Dummy\StringStream::eof() should return bool but return statement is missing.

Check failure on line 42 in tests/Dummy/StringStream.php

View workflow job for this annotation

GitHub Actions / PHP 8

Method Dummy\StringStream::eof() should return bool but return statement is missing.
{
}

public function isSeekable(): bool

Check failure on line 46 in tests/Dummy/StringStream.php

View workflow job for this annotation

GitHub Actions / PHP 7.3

Method Dummy\StringStream::isSeekable() should return bool but return statement is missing.

Check failure on line 46 in tests/Dummy/StringStream.php

View workflow job for this annotation

GitHub Actions / PHP 7.4

Method Dummy\StringStream::isSeekable() should return bool but return statement is missing.

Check failure on line 46 in tests/Dummy/StringStream.php

View workflow job for this annotation

GitHub Actions / PHP 8

Method Dummy\StringStream::isSeekable() should return bool but return statement is missing.
{
}

public function seek(int $offset, int $whence = SEEK_SET): void
{
}

public function rewind(): void
{
}

public function isWritable(): bool

Check failure on line 58 in tests/Dummy/StringStream.php

View workflow job for this annotation

GitHub Actions / PHP 7.3

Method Dummy\StringStream::isWritable() should return bool but return statement is missing.

Check failure on line 58 in tests/Dummy/StringStream.php

View workflow job for this annotation

GitHub Actions / PHP 7.4

Method Dummy\StringStream::isWritable() should return bool but return statement is missing.

Check failure on line 58 in tests/Dummy/StringStream.php

View workflow job for this annotation

GitHub Actions / PHP 8

Method Dummy\StringStream::isWritable() should return bool but return statement is missing.
{
}

public function write(string $string): int

Check failure on line 62 in tests/Dummy/StringStream.php

View workflow job for this annotation

GitHub Actions / PHP 7.3

Method Dummy\StringStream::write() should return int but return statement is missing.

Check failure on line 62 in tests/Dummy/StringStream.php

View workflow job for this annotation

GitHub Actions / PHP 7.4

Method Dummy\StringStream::write() should return int but return statement is missing.

Check failure on line 62 in tests/Dummy/StringStream.php

View workflow job for this annotation

GitHub Actions / PHP 8

Method Dummy\StringStream::write() should return int but return statement is missing.
{
}

public function isReadable(): bool

Check failure on line 66 in tests/Dummy/StringStream.php

View workflow job for this annotation

GitHub Actions / PHP 7.3

Method Dummy\StringStream::isReadable() should return bool but return statement is missing.

Check failure on line 66 in tests/Dummy/StringStream.php

View workflow job for this annotation

GitHub Actions / PHP 7.4

Method Dummy\StringStream::isReadable() should return bool but return statement is missing.

Check failure on line 66 in tests/Dummy/StringStream.php

View workflow job for this annotation

GitHub Actions / PHP 8

Method Dummy\StringStream::isReadable() should return bool but return statement is missing.
{
}

public function read(int $length): string

Check failure on line 70 in tests/Dummy/StringStream.php

View workflow job for this annotation

GitHub Actions / PHP 7.3

Method Dummy\StringStream::read() should return string but return statement is missing.

Check failure on line 70 in tests/Dummy/StringStream.php

View workflow job for this annotation

GitHub Actions / PHP 7.4

Method Dummy\StringStream::read() should return string but return statement is missing.

Check failure on line 70 in tests/Dummy/StringStream.php

View workflow job for this annotation

GitHub Actions / PHP 8

Method Dummy\StringStream::read() should return string but return statement is missing.
{
}

public function getContents(): string

Check failure on line 74 in tests/Dummy/StringStream.php

View workflow job for this annotation

GitHub Actions / PHP 7.3

Method Dummy\StringStream::getContents() should return string but return statement is missing.

Check failure on line 74 in tests/Dummy/StringStream.php

View workflow job for this annotation

GitHub Actions / PHP 7.4

Method Dummy\StringStream::getContents() should return string but return statement is missing.

Check failure on line 74 in tests/Dummy/StringStream.php

View workflow job for this annotation

GitHub Actions / PHP 8

Method Dummy\StringStream::getContents() should return string but return statement is missing.
{
}

public function getMetadata(?string $key = null)
{
}
}
7 changes: 4 additions & 3 deletions tests/UnitTests/Secure/Provider/OAuthProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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']);
Expand All @@ -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']);
Expand All @@ -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']);
Expand Down

0 comments on commit 0684fdb

Please sign in to comment.