Skip to content

Commit 9c059f2

Browse files
committed
move tests in bundle
1 parent 77a4a2f commit 9c059f2

28 files changed

+2023
-7
lines changed

.editorconfig

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
root = true
2+
3+
[*]
4+
charset = utf-8
5+
end_of_line = lf
6+
indent_size = 2
7+
indent_style = space
8+
insert_final_newline = true
9+
trim_trailing_whitespace = true
10+
11+
[*.md]
12+
indent_size = 4
13+
trim_trailing_whitespace = false
14+
15+
[*.mk,Makefile]
16+
indent_style = tab
17+
18+
[*.{php,yml,yaml}]
19+
indent_size = 4

.gitignore

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
phpunit.xml
2+
build
3+
vendor
4+
composer.lock
5+
composer.phar

README.md

Whitespace-only changes.

Relay/Connection/Output/ConnectionBuilder.php

-7
Original file line numberDiff line numberDiff line change
@@ -101,13 +101,6 @@ public static function connectionFromArraySlice($arraySlice, array $args, array
101101

102102
$edges = [];
103103

104-
// var_dump(compact(
105-
// 'countArraySlice', 'slice', 'end', 'length',
106-
// 'offset', 'first', 'after', 'before',
107-
// 'beforeOffset', 'afterOffset',
108-
// 'startOffset', 'endOffset', 'sliceStart'
109-
// ));
110-
111104
foreach($slice as $index => $value) {
112105
$edges[] = new Edge(static::offsetToCursor($startOffset + $index), $value);
113106
}

Request/Executor.php

+20
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ class Executor
1919
*/
2020
private $dispatcher;
2121

22+
/** @var boolean */
2223
private $enabledDebug;
2324

2425
public function __construct(Schema $schema, EventDispatcherInterface $dispatcher, $enabledDebug)
@@ -28,6 +29,25 @@ public function __construct(Schema $schema, EventDispatcherInterface $dispatcher
2829
$this->enabledDebug = $enabledDebug;
2930
}
3031

32+
/**
33+
* @return boolean
34+
*/
35+
public function getEnabledDebug()
36+
{
37+
return $this->enabledDebug;
38+
}
39+
40+
/**
41+
* @param boolean $enabledDebug
42+
* @return $this
43+
*/
44+
public function setEnabledDebug($enabledDebug)
45+
{
46+
$this->enabledDebug = $enabledDebug;
47+
48+
return $this;
49+
}
50+
3151
public function execute(array $data, array $context = [])
3252
{
3353
$source = new Source($data['query']);

Tests/Functional/BootTest.php

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
namespace Overblog\GraphBundle\Tests\Functional;
4+
5+
6+
class BootTest extends TestCase
7+
{
8+
public function testBoot()
9+
{
10+
$kernel = $this->createKernel();
11+
$kernel->boot();
12+
}
13+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,262 @@
1+
<?php
2+
3+
namespace Overblog\GraphBundle\Tests\Functional\Relay\Mutation;
4+
5+
6+
use Overblog\GraphBundle\Tests\Functional\TestCase;
7+
8+
/**
9+
* Class MutationTest
10+
* @see https://github.com/graphql/graphql-relay-js/blob/master/src/mutation/__tests__/mutation.js
11+
*/
12+
class MutationTest extends TestCase
13+
{
14+
protected function setUp()
15+
{
16+
parent::setUp();
17+
18+
static::$kernel = static::createKernel(['test_case' => 'mutation']);
19+
static::$kernel->boot();
20+
}
21+
22+
public function testRequiresAnArgument()
23+
{
24+
$query = <<<EOF
25+
mutation M {
26+
simpleMutation {
27+
result
28+
}
29+
}
30+
EOF;
31+
$result = $this->executeGraphQlRequest($query);
32+
33+
$this->assertCount(1, $result['errors']);
34+
$this->assertEquals(
35+
'Field "simpleMutation" argument "input" of type "simpleMutationInput!" is required but not provided.',
36+
$result['errors'][0]['message']
37+
);
38+
}
39+
40+
public function testReturnTheSameClientMutationId()
41+
{
42+
$query = <<<EOF
43+
mutation M {
44+
simpleMutation(input: {clientMutationId: "abc"}) {
45+
result
46+
clientMutationId
47+
}
48+
}
49+
EOF;
50+
51+
$expectedData = [
52+
'simpleMutation' => [
53+
'result' => 1,
54+
'clientMutationId' => 'abc'
55+
],
56+
];
57+
58+
$this->assertGraphQl($query, $expectedData);
59+
}
60+
61+
62+
public function testSupportsThunksAsInputAndOutputFields()
63+
{
64+
$query = <<<EOF
65+
mutation M {
66+
simpleMutationWithThunkFields(input: {inputData: 1234, clientMutationId: "abc"}) {
67+
result
68+
clientMutationId
69+
}
70+
}
71+
EOF;
72+
$expectedData = [
73+
'simpleMutationWithThunkFields' => [
74+
'result' => 1234,
75+
'clientMutationId' => 'abc'
76+
],
77+
];
78+
79+
$this->assertGraphQl($query, $expectedData);
80+
}
81+
82+
83+
public function testContainsCorrectInput()
84+
{
85+
$query = <<<EOF
86+
{
87+
__type(name: "simpleMutationInput") {
88+
name
89+
kind
90+
inputFields {
91+
name
92+
type {
93+
name
94+
kind
95+
ofType {
96+
name
97+
kind
98+
}
99+
}
100+
}
101+
}
102+
}
103+
EOF;
104+
$expectedData = [
105+
'__type' => [
106+
'name' => 'simpleMutationInput',
107+
'kind' => 'INPUT_OBJECT',
108+
'inputFields' => [
109+
[
110+
'name' => 'clientMutationId',
111+
'type' => [
112+
'name' => null,
113+
'kind' => 'NON_NULL',
114+
'ofType' => [
115+
'name' => 'String',
116+
'kind' => 'SCALAR'
117+
]
118+
]
119+
]
120+
]
121+
]
122+
];
123+
124+
$this->assertGraphQl($query, $expectedData);
125+
}
126+
127+
public function testContainsCorrectPayload()
128+
{
129+
$query = <<<EOF
130+
{
131+
__type(name: "simpleMutationPayload") {
132+
name
133+
kind
134+
fields {
135+
name
136+
type {
137+
name
138+
kind
139+
ofType {
140+
name
141+
kind
142+
}
143+
}
144+
}
145+
}
146+
}
147+
EOF;
148+
149+
$expectedData = [
150+
'__type' => [
151+
'name' => 'simpleMutationPayload',
152+
'kind' => 'OBJECT',
153+
'fields' => [
154+
[
155+
'name' => 'result',
156+
'type' => [
157+
'name' => 'Int',
158+
'kind' => 'SCALAR',
159+
'ofType' => null
160+
]
161+
],
162+
[
163+
'name' => 'clientMutationId',
164+
'type' => [
165+
'name' => null,
166+
'kind' => 'NON_NULL',
167+
'ofType' => [
168+
'name' => 'String',
169+
'kind' => 'SCALAR'
170+
]
171+
]
172+
]
173+
174+
]
175+
]
176+
];
177+
178+
$this->assertGraphQl($query, $expectedData);
179+
180+
}
181+
182+
public function testContainsCorrectField()
183+
{
184+
$query = <<<EOF
185+
{
186+
__schema {
187+
mutationType {
188+
fields {
189+
name
190+
args {
191+
name
192+
type {
193+
name
194+
kind
195+
ofType {
196+
name
197+
kind
198+
}
199+
}
200+
}
201+
type {
202+
name
203+
kind
204+
}
205+
}
206+
}
207+
}
208+
}
209+
EOF;
210+
211+
$expectedData = [
212+
'__schema' => [
213+
'mutationType' => [
214+
'fields' => [
215+
[
216+
'name' => 'simpleMutation',
217+
'args' => [
218+
[
219+
'name' => 'input',
220+
'type' => [
221+
'name' => null,
222+
'kind' => 'NON_NULL',
223+
'ofType' => [
224+
'name' => 'simpleMutationInput',
225+
'kind' => 'INPUT_OBJECT'
226+
]
227+
]
228+
]
229+
],
230+
'type' => [
231+
'name' => 'simpleMutationPayload',
232+
'kind' => 'OBJECT'
233+
]
234+
],
235+
[
236+
'name' => 'simpleMutationWithThunkFields',
237+
'args' => [
238+
[
239+
'name' => 'input',
240+
'type' => [
241+
'name' => null,
242+
'kind' => 'NON_NULL',
243+
'ofType' => [
244+
'name' => 'simpleMutationWithThunkFieldsInput',
245+
'kind' => 'INPUT_OBJECT'
246+
]
247+
]
248+
]
249+
],
250+
'type' => [
251+
'name' => 'simpleMutationWithThunkFieldsPayload',
252+
'kind' => 'OBJECT'
253+
]
254+
]
255+
]
256+
]
257+
]
258+
];
259+
260+
$this->assertGraphQl($query, $expectedData);
261+
}
262+
}

0 commit comments

Comments
 (0)