Skip to content

Commit 6a38f9b

Browse files
Add compatibility with guzzle v7 (#59)
Improved checkstyle Fixed test for guzzle v7 Co-authored-by: Jose Manuel Cardona <[email protected]>
1 parent 69ae17b commit 6a38f9b

File tree

4 files changed

+53
-30
lines changed

4 files changed

+53
-30
lines changed

.travis.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ sudo: false
44

55
matrix:
66
include:
7-
- php: 7.1
8-
env: COLLECT_COVERAGE=true VALIDATE_CODING_STYLE=true
97
- php: 7.2
108
env: COLLECT_COVERAGE=true VALIDATE_CODING_STYLE=true
119
- php: 7.3
1210
env: COLLECT_COVERAGE=true VALIDATE_CODING_STYLE=true
11+
- php: 7.4
12+
env: COLLECT_COVERAGE=true VALIDATE_CODING_STYLE=true
1313
- php: master
1414
env: COLLECT_COVERAGE=true VALIDATE_CODING_STYLE=false
1515
allow_failures:

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
},
1111
"require": {
1212
"php": ">=7.0",
13-
"guzzlehttp/guzzle": "^6.3",
13+
"guzzlehttp/guzzle": "^6.3 || ^7.0",
1414
"softonic/guzzle-oauth2-middleware": "^1.1"
1515
},
1616
"require-dev": {

docker-compose.yml

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,31 @@
1-
version: '3.2'
1+
version: "3.7"
22

33
services:
4+
php:
5+
volumes:
6+
- ./:/app
7+
image: composer:2.0
8+
9+
install:
10+
volumes:
11+
- ./:/app
12+
image: composer:2.0
13+
command: composer install
14+
15+
phpunit:
16+
volumes:
17+
- ./:/app
18+
image: composer:2.0
19+
command: composer phpunit
20+
421
test:
522
volumes:
6-
- ./:/app
7-
image: ricc/composer-prestissimo:latest
8-
command: composer run test
23+
- ./:/app
24+
image: composer:2.0
25+
command: composer run tests
926

1027
fixcs:
1128
volumes:
12-
- ./:/app
13-
image: ricc/composer-prestissimo:latest
29+
- ./:/app
30+
image: composer:2.0
1431
command: composer run fix-cs
15-
16-
psysh:
17-
volumes:
18-
- ./:/app
19-
image: ricc/psysh:latest

tests/ClientTest.php

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,18 @@
22

33
namespace Softonic\GraphQL\Test;
44

5+
use Exception;
6+
use GuzzleHttp\ClientInterface;
7+
use GuzzleHttp\Exception\ServerException;
8+
use GuzzleHttp\Exception\TransferException;
59
use PHPUnit\Framework\TestCase;
10+
use Psr\Http\Message\RequestInterface;
11+
use Psr\Http\Message\ResponseInterface;
12+
use RuntimeException;
613
use Softonic\GraphQL\Client;
14+
use Softonic\GraphQL\Response;
15+
use Softonic\GraphQL\ResponseBuilder;
16+
use UnexpectedValueException;
717

818
class ClientTest extends TestCase
919
{
@@ -13,18 +23,18 @@ class ClientTest extends TestCase
1323

1424
public function setUp()
1525
{
16-
$this->httpClient = $this->createMock(\GuzzleHttp\ClientInterface::class);
17-
$this->mockGraphqlResponseBuilder = $this->createMock(\Softonic\GraphQL\ResponseBuilder::class);
26+
$this->httpClient = $this->createMock(ClientInterface::class);
27+
$this->mockGraphqlResponseBuilder = $this->createMock(ResponseBuilder::class);
1828
$this->client = new Client($this->httpClient, $this->mockGraphqlResponseBuilder);
1929
}
2030

2131
public function testSimpleQueryWhenHasNetworkErrors()
2232
{
2333
$this->httpClient->expects($this->once())
2434
->method('request')
25-
->willThrowException(new \GuzzleHttp\Exception\TransferException('library error'));
35+
->willThrowException(new TransferException('library error'));
2636

27-
$this->expectException(\RuntimeException::class);
37+
$this->expectException(RuntimeException::class);
2838
$this->expectExceptionMessage('Network Error.');
2939

3040
$query = $this->getSimpleQuery();
@@ -35,9 +45,10 @@ public function testCanRetrievePreviousExceptionWhenSimpleQueryHasErrors()
3545
{
3646
$previousException = null;
3747
try {
38-
$originalException = new \GuzzleHttp\Exception\ServerException(
48+
$originalException = new ServerException(
3949
'Server side error',
40-
$this->createMock(\Psr\Http\Message\RequestInterface::class)
50+
$this->createMock(RequestInterface::class),
51+
$this->createMock(ResponseInterface::class)
4152
);
4253

4354
$this->httpClient->expects($this->once())
@@ -46,7 +57,7 @@ public function testCanRetrievePreviousExceptionWhenSimpleQueryHasErrors()
4657

4758
$query = $this->getSimpleQuery();
4859
$this->client->query($query);
49-
} catch (\Exception $e) {
60+
} catch (Exception $e) {
5061
$previousException = $e->getPrevious();
5162
} finally {
5263
$this->assertSame($originalException, $previousException);
@@ -57,11 +68,11 @@ public function testSimpleQueryWhenInvalidJsonIsReceived()
5768
{
5869
$query = $this->getSimpleQuery();
5970

60-
$mockHttpResponse = $this->createMock(\Psr\Http\Message\ResponseInterface::class);
71+
$mockHttpResponse = $this->createMock(ResponseInterface::class);
6172
$this->mockGraphqlResponseBuilder->expects($this->once())
6273
->method('build')
6374
->with($mockHttpResponse)
64-
->willThrowException(new \UnexpectedValueException('Invalid JSON response.'));
75+
->willThrowException(new UnexpectedValueException('Invalid JSON response.'));
6576
$this->httpClient->expects($this->once())
6677
->method('request')
6778
->with(
@@ -75,16 +86,16 @@ public function testSimpleQueryWhenInvalidJsonIsReceived()
7586
)
7687
->willReturn($mockHttpResponse);
7788

78-
$this->expectException(\UnexpectedValueException::class);
89+
$this->expectException(UnexpectedValueException::class);
7990
$this->expectExceptionMessage('Invalid JSON response.');
8091

8192
$this->client->query($query);
8293
}
8394

8495
public function testSimpleQuery()
8596
{
86-
$mockResponse = $this->createMock(\Softonic\GraphQL\Response::class);
87-
$mockHttpResponse = $this->createMock(\Psr\Http\Message\ResponseInterface::class);
97+
$mockResponse = $this->createMock(Response::class);
98+
$mockHttpResponse = $this->createMock(ResponseInterface::class);
8899

89100
$response = [
90101
'data' => [
@@ -114,13 +125,13 @@ public function testSimpleQuery()
114125
->willReturn($mockHttpResponse);
115126

116127
$response = $this->client->query($query);
117-
$this->assertInstanceOf(\Softonic\GraphQL\Response::class, $response);
128+
$this->assertInstanceOf(Response::class, $response);
118129
}
119130

120131
public function testQueryWithVariables()
121132
{
122-
$mockResponse = $this->createMock(\Softonic\GraphQL\Response::class);
123-
$mockHttpResponse = $this->createMock(\Psr\Http\Message\ResponseInterface::class);
133+
$mockResponse = $this->createMock(Response::class);
134+
$mockHttpResponse = $this->createMock(ResponseInterface::class);
124135

125136
$response = [
126137
'data' => [
@@ -155,7 +166,7 @@ public function testQueryWithVariables()
155166
->willReturn($mockHttpResponse);
156167

157168
$response = $this->client->query($query, $variables);
158-
$this->assertInstanceOf(\Softonic\GraphQL\Response::class, $response);
169+
$this->assertInstanceOf(Response::class, $response);
159170
}
160171

161172
private function getSimpleQuery()

0 commit comments

Comments
 (0)