From 4c86f2c1cfc01c3ca6717a376ee92bb3213d0758 Mon Sep 17 00:00:00 2001 From: Jose Manuel Cardona Date: Fri, 1 Mar 2024 10:15:57 +0100 Subject: [PATCH 1/2] Fix tests and dependencies --- composer.json | 2 +- src/Console/Mutation/GenerateConfig.php | 2 +- tests/ResponseBuilderTest.php | 19 +++++++++++++++---- 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/composer.json b/composer.json index 3fd0fb4..c4c424c 100644 --- a/composer.json +++ b/composer.json @@ -18,7 +18,7 @@ "guzzlehttp/guzzle": "^6.3 || ^7.0", "softonic/guzzle-oauth2-middleware": "^2.1", "ext-json": "*", - "symfony/console": "^5.0 || ^6.0 || ^7.0" + "symfony/console": "^6.0 || ^7.0" }, "require-dev": { "friendsofphp/php-cs-fixer": "^3.9", diff --git a/src/Console/Mutation/GenerateConfig.php b/src/Console/Mutation/GenerateConfig.php index 03cdfcc..330d14c 100644 --- a/src/Console/Mutation/GenerateConfig.php +++ b/src/Console/Mutation/GenerateConfig.php @@ -54,7 +54,7 @@ protected function configure() ); } - protected function execute(InputInterface $input, OutputInterface $output) + protected function execute(InputInterface $input, OutputInterface $output): int { if (!$this->checkArguments($input, $output)) { return 1; diff --git a/tests/ResponseBuilderTest.php b/tests/ResponseBuilderTest.php index 49944cb..d7e3c8a 100644 --- a/tests/ResponseBuilderTest.php +++ b/tests/ResponseBuilderTest.php @@ -2,8 +2,10 @@ namespace Softonic\GraphQL; +use GuzzleHttp\Psr7\BufferStream; use PHPUnit\Framework\TestCase; use Psr\Http\Message\ResponseInterface; +use Psr\Http\Message\StreamInterface; use UnexpectedValueException; class ResponseBuilderTest extends TestCase @@ -24,7 +26,7 @@ public function testBuildMalformedResponse() $mockHttpResponse = $this->createMock(ResponseInterface::class); $mockHttpResponse->expects($this->once()) ->method('getBody') - ->willReturn('malformed response'); + ->willReturn($this->stringToStream('malformed response')); $this->expectException(UnexpectedValueException::class); $this->expectExceptionMessage('Invalid JSON response. Response body: '); @@ -53,7 +55,7 @@ public function testBuildInvalidGraphqlJsonResponse(string $body) $mockHttpResponse->expects($this->once()) ->method('getBody') - ->willReturn($body); + ->willReturn($this->stringToStream($body)); $this->expectException(UnexpectedValueException::class); $this->expectExceptionMessage('Invalid GraphQL JSON response. Response body: '); @@ -67,7 +69,7 @@ public function testBuildValidGraphqlJsonWithoutErrors() $mockHttpResponse->expects($this->once()) ->method('getBody') - ->willReturn('{"data": {"foo": "bar"}}'); + ->willReturn($this->stringToStream('{"data": {"foo": "bar"}}')); $expectedData = ['foo' => 'bar']; $dataObjectMock = [ @@ -107,7 +109,7 @@ public function testBuildValidGraphqlJsonWithErrors(string $body) $mockHttpResponse->expects($this->once()) ->method('getBody') - ->willReturn($body); + ->willReturn($this->stringToStream($body)); $this->dataObjectBuilder->expects($this->once()) ->method('buildQuery') @@ -121,4 +123,13 @@ public function testBuildValidGraphqlJsonWithErrors(string $body) $this->assertTrue($response->hasErrors()); $this->assertEquals([['foo' => 'bar']], $response->getErrors()); } + + public function stringToStream(string $string): StreamInterface + { + $buffer = new BufferStream(); + + $buffer->write($string); + + return $buffer; + } } From d2e7157f2f4491e0e0fe3de6528537a48853e2e2 Mon Sep 17 00:00:00 2001 From: Jose Manuel Cardona Date: Fri, 1 Mar 2024 10:24:03 +0100 Subject: [PATCH 2/2] Improve README --- README.md | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 1da81f4..7ffc4e2 100644 --- a/README.md +++ b/README.md @@ -32,13 +32,19 @@ composer require softonic/graphql-client You can instantiate a simple client or with Oauth2 support. -Simple Client: +#### Simple Client ```php