Skip to content

Commit baf91a3

Browse files
author
Cyril Mizzi
committed
fixes ModelTransformerTest
fixes GraphQL tests adds backward compatibilities try fixing travis error
1 parent 3372a09 commit baf91a3

File tree

2 files changed

+34
-16
lines changed

2 files changed

+34
-16
lines changed

tests/GraphQLTest.php

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ public function testQuery() {
6969
$graphql->registerType('post', Entity\Post::class);
7070

7171
$params = ['query' => 'query { user(id: 1) { name, posts { title } }}'];
72-
$content = $response->getData(true);
7372
$user = Entity\User::with('posts')->find(1);
7473
$posts = [];
7574

@@ -79,13 +78,12 @@ public function testQuery() {
7978

8079
$this->call('GET', '/graphql', $params);
8180
$this->seeJsonEquals([
82-
$this->assertSame([
83-
'user' => [
84-
'name' => $user->name,
85-
'posts' => $posts
81+
'user' => [
82+
'name' => $user->name,
83+
'posts' => $posts
84+
]
8685
]
87-
], $content['data']);
88-
]);
86+
], $response);
8987
}
9088

9189
/**
@@ -102,17 +100,33 @@ public function testMutation() {
102100

103101
$params = ['query' => 'mutation { updateName : user(id: 1, name : "Test") { id, name } }'];
104102
$this->json('POST', '/graphql', $params);
105-
$content = $response->getData(true);
106103
$entity = Entity\User::find(1);
107104

108105
$this->seeJsonEquals([
109-
$this->assertArrayNotHasKey('errors', $content);
110-
$this->assertSame([
111-
'updateName' => [
112-
'id' => (string) $entity->getKey(),
113-
'name' => $entity->name
106+
'data' => [
107+
'updateName' => [
108+
'id' => (string) $entity->getKey(),
109+
'name' => $entity->name
110+
]
114111
]
115-
], $content['data']);
116-
]);
112+
], $response);
113+
}
114+
115+
/**
116+
* Backward compatibility between 5.3 and 5.4
117+
*
118+
* @param array $data
119+
* @param mixed $response
120+
*
121+
* @return void
122+
*/
123+
public function assertJsonEquals(array $data, $response) {
124+
if (method_exists($response, 'assertJson')) {
125+
$response->assertJson($data);
126+
}
127+
128+
if (method_exists($response, 'seeJsonEquals')) {
129+
$response->seeJsonEquals($data);
130+
}
117131
}
118132
}

tests/Transformer/ModelTransformerTest.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,16 @@
55
use StudioNet\GraphQL\Tests\TestCase;
66
use StudioNet\GraphQL\Transformer\Type\ModelTransformer;
77
use StudioNet\GraphQL\Type\EloquentObjectType;
8+
use Illuminate\Foundation\Testing\DatabaseTransactions;
89

910
/**
1011
* ModelTransformerTest
1112
*
1213
* @see TestCase
1314
*/
1415
class ModelTransformerTest extends TestCase {
16+
use DatabaseTransactions;
17+
1518
/**
1619
* testSupports
1720
*
@@ -85,6 +88,7 @@ public function testResolve() {
8588
$resolver = $transformer->transform($user)->getFields()['posts']->config['resolve'];
8689
$response = call_user_func_array($resolver, [$entity, ['take' => 1, 'skip' => 1]]);
8790

88-
$this->assertSame($entity->posts->get(1)->toArray(), $response[0]->toArray());
91+
$this->assertSame(1, count($response));
92+
$this->assertSame($entity->posts->get(1)->toArray(), current($response)->toArray());
8993
}
9094
}

0 commit comments

Comments
 (0)