Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix tests and dependencies #68

Merged
merged 2 commits into from
Mar 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,19 @@ composer require softonic/graphql-client

You can instantiate a simple client or with Oauth2 support.

Simple Client:
#### Simple Client
```php
<?php
$client = \Softonic\GraphQL\ClientBuilder::build('https://your-domain/graphql');
```

OAuth2 provider:
#### OAuth2 provider

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.
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/).

This is an example using a custom provider.

```php
<?php

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion src/Console/Mutation/GenerateConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
19 changes: 15 additions & 4 deletions tests/ResponseBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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: ');
Expand Down Expand Up @@ -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: ');
Expand All @@ -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 = [
Expand Down Expand Up @@ -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')
Expand All @@ -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;
}
}
Loading