Skip to content

Commit 0692fe8

Browse files
Fix tests and dependencies (#68)
* Fix tests and dependencies * Improve README --------- Co-authored-by: Jose Manuel Cardona <[email protected]>
1 parent 5dee6bf commit 0692fe8

File tree

4 files changed

+25
-8
lines changed

4 files changed

+25
-8
lines changed

README.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,19 @@ composer require softonic/graphql-client
3232

3333
You can instantiate a simple client or with Oauth2 support.
3434

35-
Simple Client:
35+
#### Simple Client
3636
```php
3737
<?php
3838
$client = \Softonic\GraphQL\ClientBuilder::build('https://your-domain/graphql');
3939
```
4040

41-
OAuth2 provider:
41+
#### OAuth2 provider
42+
43+
This package allows you to use [thephpleague/oauth2-client](https://github.com/thephpleague/oauth2-client) adapters for authentication, so the endpoint depends on the adapter that you are using.
44+
The adapter could be [custom](https://oauth2-client.thephpleague.com/providers/implementing/) or provided by the library as [official](https://oauth2-client.thephpleague.com/providers/league/) or [third party](https://oauth2-client.thephpleague.com/providers/thirdparty/).
45+
46+
This is an example using a custom provider.
47+
4248
```php
4349
<?php
4450

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"guzzlehttp/guzzle": "^6.3 || ^7.0",
1919
"softonic/guzzle-oauth2-middleware": "^2.1",
2020
"ext-json": "*",
21-
"symfony/console": "^5.0 || ^6.0 || ^7.0"
21+
"symfony/console": "^6.0 || ^7.0"
2222
},
2323
"require-dev": {
2424
"friendsofphp/php-cs-fixer": "^3.9",

src/Console/Mutation/GenerateConfig.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ protected function configure()
5454
);
5555
}
5656

57-
protected function execute(InputInterface $input, OutputInterface $output)
57+
protected function execute(InputInterface $input, OutputInterface $output): int
5858
{
5959
if (!$this->checkArguments($input, $output)) {
6060
return 1;

tests/ResponseBuilderTest.php

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22

33
namespace Softonic\GraphQL;
44

5+
use GuzzleHttp\Psr7\BufferStream;
56
use PHPUnit\Framework\TestCase;
67
use Psr\Http\Message\ResponseInterface;
8+
use Psr\Http\Message\StreamInterface;
79
use UnexpectedValueException;
810

911
class ResponseBuilderTest extends TestCase
@@ -24,7 +26,7 @@ public function testBuildMalformedResponse()
2426
$mockHttpResponse = $this->createMock(ResponseInterface::class);
2527
$mockHttpResponse->expects($this->once())
2628
->method('getBody')
27-
->willReturn('malformed response');
29+
->willReturn($this->stringToStream('malformed response'));
2830

2931
$this->expectException(UnexpectedValueException::class);
3032
$this->expectExceptionMessage('Invalid JSON response. Response body: ');
@@ -53,7 +55,7 @@ public function testBuildInvalidGraphqlJsonResponse(string $body)
5355

5456
$mockHttpResponse->expects($this->once())
5557
->method('getBody')
56-
->willReturn($body);
58+
->willReturn($this->stringToStream($body));
5759

5860
$this->expectException(UnexpectedValueException::class);
5961
$this->expectExceptionMessage('Invalid GraphQL JSON response. Response body: ');
@@ -67,7 +69,7 @@ public function testBuildValidGraphqlJsonWithoutErrors()
6769

6870
$mockHttpResponse->expects($this->once())
6971
->method('getBody')
70-
->willReturn('{"data": {"foo": "bar"}}');
72+
->willReturn($this->stringToStream('{"data": {"foo": "bar"}}'));
7173

7274
$expectedData = ['foo' => 'bar'];
7375
$dataObjectMock = [
@@ -107,7 +109,7 @@ public function testBuildValidGraphqlJsonWithErrors(string $body)
107109

108110
$mockHttpResponse->expects($this->once())
109111
->method('getBody')
110-
->willReturn($body);
112+
->willReturn($this->stringToStream($body));
111113

112114
$this->dataObjectBuilder->expects($this->once())
113115
->method('buildQuery')
@@ -121,4 +123,13 @@ public function testBuildValidGraphqlJsonWithErrors(string $body)
121123
$this->assertTrue($response->hasErrors());
122124
$this->assertEquals([['foo' => 'bar']], $response->getErrors());
123125
}
126+
127+
public function stringToStream(string $string): StreamInterface
128+
{
129+
$buffer = new BufferStream();
130+
131+
$buffer->write($string);
132+
133+
return $buffer;
134+
}
124135
}

0 commit comments

Comments
 (0)