1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the OverblogGraphQLBundle package. |
5
|
|
|
* |
6
|
|
|
* (c) Overblog <http://github.com/overblog/> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Overblog\GraphQLBundle\Tests\Functional\Security; |
13
|
|
|
|
14
|
|
|
use GraphQL\Type\Definition\EnumType; |
15
|
|
|
use GraphQL\Type\Definition\ObjectType; |
16
|
|
|
use GraphQL\Type\Definition\Type; |
17
|
|
|
use Overblog\GraphQLBundle\Tests\Functional\TestCase; |
18
|
|
|
|
19
|
|
|
class DefinitionTest extends TestCase |
20
|
|
|
{ |
21
|
|
|
protected function setUp() |
22
|
|
|
{ |
23
|
|
|
parent::setUp(); |
24
|
|
|
|
25
|
|
|
static::createAndBootKernel(['test_case' => 'definition']); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
public function testDefinesEnumTypeWithDeprecatedValue() |
29
|
|
|
{ |
30
|
|
|
/** @var EnumType $enumTypeWithDeprecatedValue */ |
31
|
|
|
$enumTypeWithDeprecatedValue = $this->getType('EnumWithDeprecatedValue'); |
32
|
|
|
$value = $enumTypeWithDeprecatedValue->getValues()[0]; |
33
|
|
|
$this->assertEquals([ |
34
|
|
|
'name' => 'foo', |
35
|
|
|
'description' => null, |
36
|
|
|
'deprecationReason' => 'Just because', |
37
|
|
|
'value' => 'foo', |
38
|
|
|
], (array) $value); |
39
|
|
|
$this->assertEquals(true, $this->isDeprecated($value)); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
public function testDefinesAnObjectTypeWithDeprecatedField() |
43
|
|
|
{ |
44
|
|
|
/** @var ObjectType $TypeWithDeprecatedField */ |
45
|
|
|
$TypeWithDeprecatedField = $this->getType('ObjectWithDeprecatedField'); |
46
|
|
|
$field = $TypeWithDeprecatedField->getField('bar'); |
47
|
|
|
$this->assertEquals(Type::string(), $field->getType()); |
48
|
|
|
$this->assertEquals(true, $this->isDeprecated($field)); |
49
|
|
|
$this->assertEquals('A terrible reason', $field->deprecationReason); |
50
|
|
|
$this->assertEquals('bar', $field->name); |
51
|
|
|
$this->assertEquals([], $field->args); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
private function isDeprecated($node) |
55
|
|
|
{ |
56
|
|
|
// TODO(mcg-web) refactor after moving to latest lib version |
57
|
|
|
if (is_callable([$node, 'isDeprecated'])) { |
58
|
|
|
return $node->isDeprecated(); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
return (bool) $node->deprecationReason; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
private function getType($type) |
65
|
|
|
{ |
66
|
|
|
return $this->getContainer()->get('overblog_graphql.type_resolver')->resolve($type); |
67
|
|
|
} |
68
|
|
|
} |
69
|
|
|
|