Failed Conditions
Push — master ( 804daa...8817e8 )
by Vladimir
04:14
created

testStringXListOfString()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 4
dl 0
loc 12
c 0
b 0
f 0
rs 10
cc 1
nc 1
nop 0
1
<?php
2
namespace GraphQL\Tests\Validator;
3
4
use GraphQL\Error\FormattedError;
5
use GraphQL\Language\SourceLocation;
6
use GraphQL\Validator\Rules\VariablesInAllowedPosition;
7
8
class VariablesInAllowedPositionTest extends ValidatorTestCase
9
{
10
    // Validate: Variables are in allowed positions
11
12
    /**
13
     * @it Boolean => Boolean
14
     */
15
    public function testBooleanXBoolean()
16
    {
17
        // Boolean => Boolean
18
        $this->expectPassesRule(new VariablesInAllowedPosition(), '
19
      query Query($booleanArg: Boolean)
20
      {
21
        complicatedArgs {
22
          booleanArgField(booleanArg: $booleanArg)
23
        }
24
      }
25
        ');
26
    }
27
28
    /**
29
     * @it Boolean => Boolean within fragment
30
     */
31
    public function testBooleanXBooleanWithinFragment()
32
    {
33
        // Boolean => Boolean within fragment
34
        $this->expectPassesRule(new VariablesInAllowedPosition, '
35
      fragment booleanArgFrag on ComplicatedArgs {
36
        booleanArgField(booleanArg: $booleanArg)
37
      }
38
      query Query($booleanArg: Boolean)
39
      {
40
        complicatedArgs {
41
          ...booleanArgFrag
42
        }
43
      }
44
        ');
45
46
        $this->expectPassesRule(new VariablesInAllowedPosition, '
47
      query Query($booleanArg: Boolean)
48
      {
49
        complicatedArgs {
50
          ...booleanArgFrag
51
        }
52
      }
53
      fragment booleanArgFrag on ComplicatedArgs {
54
        booleanArgField(booleanArg: $booleanArg)
55
      }
56
        ');
57
    }
58
59
    /**
60
     * @it Boolean! => Boolean
61
     */
62
    public function testBooleanNonNullXBoolean()
63
    {
64
        // Boolean! => Boolean
65
        $this->expectPassesRule(new VariablesInAllowedPosition, '
66
      query Query($nonNullBooleanArg: Boolean!)
67
      {
68
        complicatedArgs {
69
          booleanArgField(booleanArg: $nonNullBooleanArg)
70
        }
71
      }
72
        ');
73
    }
74
75
    /**
76
     * @it Boolean! => Boolean within fragment
77
     */
78
    public function testBooleanNonNullXBooleanWithinFragment()
79
    {
80
        // Boolean! => Boolean within fragment
81
        $this->expectPassesRule(new VariablesInAllowedPosition, '
82
      fragment booleanArgFrag on ComplicatedArgs {
83
        booleanArgField(booleanArg: $nonNullBooleanArg)
84
      }
85
86
      query Query($nonNullBooleanArg: Boolean!)
87
      {
88
        complicatedArgs {
89
          ...booleanArgFrag
90
        }
91
      }
92
        ');
93
    }
94
95
    /**
96
     * @it Int => Int! with default
97
     */
98
    public function testIntXIntNonNullWithDefault()
99
    {
100
        // Int => Int! with default
101
        $this->expectPassesRule(new VariablesInAllowedPosition, '
102
      query Query($intArg: Int = 1)
103
      {
104
        complicatedArgs {
105
          nonNullIntArgField(nonNullIntArg: $intArg)
106
        }
107
      }
108
        ');
109
    }
110
111
    /**
112
     * @it [String] => [String]
113
     */
114
    public function testListOfStringXListOfString()
115
    {
116
        $this->expectPassesRule(new VariablesInAllowedPosition, '
117
      query Query($stringListVar: [String])
118
      {
119
        complicatedArgs {
120
          stringListArgField(stringListArg: $stringListVar)
121
        }
122
      }
123
        ');
124
    }
125
126
    /**
127
     * @it [String!] => [String]
128
     */
129
    public function testListOfStringNonNullXListOfString()
130
    {
131
        $this->expectPassesRule(new VariablesInAllowedPosition, '
132
      query Query($stringListVar: [String!])
133
      {
134
        complicatedArgs {
135
          stringListArgField(stringListArg: $stringListVar)
136
        }
137
      }
138
        ');
139
    }
140
141
    /**
142
     * @it String => [String] in item position
143
     */
144
    public function testStringXListOfStringInItemPosition()
145
    {
146
        $this->expectPassesRule(new VariablesInAllowedPosition, '
147
      query Query($stringVar: String)
148
      {
149
        complicatedArgs {
150
          stringListArgField(stringListArg: [$stringVar])
151
        }
152
      }
153
        ');
154
    }
155
156
    /**
157
     * @it String! => [String] in item position
158
     */
159
    public function testStringNonNullXListOfStringInItemPosition()
160
    {
161
        $this->expectPassesRule(new VariablesInAllowedPosition, '
162
      query Query($stringVar: String!)
163
      {
164
        complicatedArgs {
165
          stringListArgField(stringListArg: [$stringVar])
166
        }
167
      }
168
        ');
169
    }
170
171
    /**
172
     * @it ComplexInput => ComplexInput
173
     */
174
    public function testComplexInputXComplexInput()
175
    {
176
        $this->expectPassesRule(new VariablesInAllowedPosition, '
177
      query Query($complexVar: ComplexInput)
178
      {
179
        complicatedArgs {
180
          complexArgField(complexArg: $ComplexInput)
181
        }
182
      }
183
        ');
184
    }
185
186
    /**
187
     * @it ComplexInput => ComplexInput in field position
188
     */
189
    public function testComplexInputXComplexInputInFieldPosition()
190
    {
191
        $this->expectPassesRule(new VariablesInAllowedPosition, '
192
      query Query($boolVar: Boolean = false)
193
      {
194
        complicatedArgs {
195
          complexArgField(complexArg: {requiredArg: $boolVar})
196
        }
197
      }
198
        ');
199
    }
200
201
    /**
202
     * @it Boolean! => Boolean! in directive
203
     */
204
    public function testBooleanNonNullXBooleanNonNullInDirective()
205
    {
206
        $this->expectPassesRule(new VariablesInAllowedPosition, '
207
      query Query($boolVar: Boolean!)
208
      {
209
        dog @include(if: $boolVar)
210
      }
211
        ');
212
    }
213
214
    /**
215
     * @it Boolean => Boolean! in directive with default
216
     */
217
    public function testBooleanXBooleanNonNullInDirectiveWithDefault()
218
    {
219
        $this->expectPassesRule(new VariablesInAllowedPosition, '
220
      query Query($boolVar: Boolean = false)
221
      {
222
        dog @include(if: $boolVar)
223
      }
224
        ');
225
    }
226
227
    /**
228
     * @it Int => Int!
229
     */
230
    public function testIntXIntNonNull()
231
    {
232
        $this->expectFailsRule(new VariablesInAllowedPosition, '
233
      query Query($intArg: Int) {
234
        complicatedArgs {
235
          nonNullIntArgField(nonNullIntArg: $intArg)
236
        }
237
      }
238
        ', [
239
            FormattedError::create(
0 ignored issues
show
Deprecated Code introduced by
The function GraphQL\Error\FormattedError::create() has been deprecated: as of v0.8.0 ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

239
            /** @scrutinizer ignore-deprecated */ FormattedError::create(

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
240
                VariablesInAllowedPosition::badVarPosMessage('intArg', 'Int', 'Int!'),
241
                [new SourceLocation(2, 19), new SourceLocation(4, 45)]
242
            )
243
        ]);
244
    }
245
246
    /**
247
     * @it Int => Int! within fragment
248
     */
249
    public function testIntXIntNonNullWithinFragment()
250
    {
251
        $this->expectFailsRule(new VariablesInAllowedPosition, '
252
      fragment nonNullIntArgFieldFrag on ComplicatedArgs {
253
        nonNullIntArgField(nonNullIntArg: $intArg)
254
      }
255
256
      query Query($intArg: Int) {
257
        complicatedArgs {
258
          ...nonNullIntArgFieldFrag
259
        }
260
      }
261
        ', [
262
            FormattedError::create(
0 ignored issues
show
Deprecated Code introduced by
The function GraphQL\Error\FormattedError::create() has been deprecated: as of v0.8.0 ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

262
            /** @scrutinizer ignore-deprecated */ FormattedError::create(

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
263
                VariablesInAllowedPosition::badVarPosMessage('intArg', 'Int', 'Int!'),
264
                [new SourceLocation(6, 19), new SourceLocation(3, 43)]
265
            )
266
        ]);
267
    }
268
269
    /**
270
     * @it Int => Int! within nested fragment
271
     */
272
    public function testIntXIntNonNullWithinNestedFragment()
273
    {
274
        // Int => Int! within nested fragment
275
        $this->expectFailsRule(new VariablesInAllowedPosition, '
276
      fragment outerFrag on ComplicatedArgs {
277
        ...nonNullIntArgFieldFrag
278
      }
279
280
      fragment nonNullIntArgFieldFrag on ComplicatedArgs {
281
        nonNullIntArgField(nonNullIntArg: $intArg)
282
      }
283
284
      query Query($intArg: Int)
285
      {
286
        complicatedArgs {
287
          ...outerFrag
288
        }
289
      }
290
        ', [
291
            FormattedError::create(
0 ignored issues
show
Deprecated Code introduced by
The function GraphQL\Error\FormattedError::create() has been deprecated: as of v0.8.0 ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

291
            /** @scrutinizer ignore-deprecated */ FormattedError::create(

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
292
                VariablesInAllowedPosition::badVarPosMessage('intArg', 'Int', 'Int!'),
293
                [new SourceLocation(10, 19), new SourceLocation(7,43)]
294
            )
295
        ]);
296
    }
297
298
    /**
299
     * @it String over Boolean
300
     */
301
    public function testStringOverBoolean()
302
    {
303
        $this->expectFailsRule(new VariablesInAllowedPosition, '
304
      query Query($stringVar: String) {
305
        complicatedArgs {
306
          booleanArgField(booleanArg: $stringVar)
307
        }
308
      }
309
        ', [
310
            FormattedError::create(
0 ignored issues
show
Deprecated Code introduced by
The function GraphQL\Error\FormattedError::create() has been deprecated: as of v0.8.0 ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

310
            /** @scrutinizer ignore-deprecated */ FormattedError::create(

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
311
                VariablesInAllowedPosition::badVarPosMessage('stringVar', 'String', 'Boolean'),
312
                [new SourceLocation(2,19), new SourceLocation(4,39)]
313
            )
314
        ]);
315
    }
316
317
    /**
318
     * @it String => [String]
319
     */
320
    public function testStringXListOfString()
321
    {
322
        $this->expectFailsRule(new VariablesInAllowedPosition, '
323
      query Query($stringVar: String) {
324
        complicatedArgs {
325
          stringListArgField(stringListArg: $stringVar)
326
        }
327
      }
328
        ', [
329
            FormattedError::create(
0 ignored issues
show
Deprecated Code introduced by
The function GraphQL\Error\FormattedError::create() has been deprecated: as of v0.8.0 ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

329
            /** @scrutinizer ignore-deprecated */ FormattedError::create(

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
330
                VariablesInAllowedPosition::badVarPosMessage('stringVar', 'String', '[String]'),
331
                [new SourceLocation(2, 19), new SourceLocation(4,45)]
332
            )
333
        ]);
334
    }
335
336
    /**
337
     * @it Boolean => Boolean! in directive
338
     */
339
    public function testBooleanXBooleanNonNullInDirective()
340
    {
341
        $this->expectFailsRule(new VariablesInAllowedPosition, '
342
      query Query($boolVar: Boolean) {
343
        dog @include(if: $boolVar)
344
      }
345
        ', [
346
            FormattedError::create(
0 ignored issues
show
Deprecated Code introduced by
The function GraphQL\Error\FormattedError::create() has been deprecated: as of v0.8.0 ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

346
            /** @scrutinizer ignore-deprecated */ FormattedError::create(

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
347
                VariablesInAllowedPosition::badVarPosMessage('boolVar', 'Boolean', 'Boolean!'),
348
                [new SourceLocation(2, 19), new SourceLocation(3,26)]
349
            )
350
        ]);
351
    }
352
353
    /**
354
     * @it String => Boolean! in directive
355
     */
356
    public function testStringXBooleanNonNullInDirective()
357
    {
358
        // String => Boolean! in directive
359
        $this->expectFailsRule(new VariablesInAllowedPosition, '
360
      query Query($stringVar: String) {
361
        dog @include(if: $stringVar)
362
      }
363
        ', [
364
            FormattedError::create(
0 ignored issues
show
Deprecated Code introduced by
The function GraphQL\Error\FormattedError::create() has been deprecated: as of v0.8.0 ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

364
            /** @scrutinizer ignore-deprecated */ FormattedError::create(

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
365
                VariablesInAllowedPosition::badVarPosMessage('stringVar', 'String', 'Boolean!'),
366
                [new SourceLocation(2, 19), new SourceLocation(3,26)]
367
            )
368
        ]);
369
    }
370
371
    /**
372
     * @it [String] => [String!]
373
     */
374
    public function testStringArrayXStringNonNullArray()
375
    {
376
        $this->expectFailsRule(
377
            new VariablesInAllowedPosition,
378
            '
379
      query Query($stringListVar: [String])
380
      {
381
        complicatedArgs {
382
          stringListNonNullArgField(stringListNonNullArg: $stringListVar)
383
        }
384
      }
385
        ', [
386
                FormattedError::create(
0 ignored issues
show
Deprecated Code introduced by
The function GraphQL\Error\FormattedError::create() has been deprecated: as of v0.8.0 ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

386
                /** @scrutinizer ignore-deprecated */ FormattedError::create(

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
387
                    VariablesInAllowedPosition::badVarPosMessage('stringListVar', '[String]', '[String!]'),
388
                    [new SourceLocation(2, 19), new SourceLocation(5, 59)]
389
                )
390
            ]
391
        );
392
    }
393
}
394