Passed
Push — master ( ed1746...93ccd7 )
by Vladimir
09:00
created

Issue467Test::testInputObjectValidation()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 28
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 8
dl 0
loc 28
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace GraphQL\Tests\Regression;
6
7
use GraphQL\GraphQL;
8
use GraphQL\Utils\BuildSchema;
9
use PHPUnit\Framework\TestCase;
10
11
/**
12
 * @see https://github.com/webonyx/graphql-php/issues/467
13
 */
14
class Issue467Test extends TestCase
15
{
16
    public function testInputObjectValidation()
17
    {
18
        $schemaStr = '
19
input MsgInput {
20
  msg: String
21
}
22
23
type Query {
24
  echo(msg: MsgInput): String
25
}
26
27
schema {
28
    query: Query
29
}
30
';
31
32
        $query     = '
33
query echo ($msg: MsgInput) {
34
          echo (msg: $msg)
35
}';
36
        $variables = ['msg' => ['my message']];
37
38
        $schema = BuildSchema::build($schemaStr);
39
        $result = GraphQL::executeQuery($schema, $query, null, null, $variables);
40
41
        $expectedError = 'Variable "$msg" got invalid value ["my message"]; Field "0" is not defined by type MsgInput.';
42
        self::assertCount(1, $result->errors);
43
        self::assertEquals($expectedError, $result->errors[0]->getMessage());
44
    }
45
}
46