-
Notifications
You must be signed in to change notification settings - Fork 104
/
InterfaceTypeConfigTest.php
75 lines (62 loc) · 2.39 KB
/
InterfaceTypeConfigTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
<?php
/*
* This file is a part of GraphQL project.
*
* @author Alexandr Viniychuk <a@viniychuk.com>
* created: 5/12/16 4:17 PM
*/
namespace Youshido\Tests\Library\Config;
use Youshido\GraphQL\Config\Object\InterfaceTypeConfig;
use Youshido\GraphQL\Type\Object\ObjectType;
use Youshido\GraphQL\Type\Scalar\IntType;
use Youshido\GraphQL\Type\Scalar\StringType;
use Youshido\Tests\DataProvider\TestInterfaceType;
class InterfaceTypeConfigTest extends \PHPUnit_Framework_TestCase
{
public function testCreation()
{
$config = new InterfaceTypeConfig(['name' => 'Test'], null, false);
$this->assertEquals($config->getName(), 'Test', 'Normal creation');
}
/**
* @expectedException Youshido\GraphQL\Validator\Exception\ConfigurationException
*/
public function testConfigNoFields()
{
new InterfaceTypeConfig(['name' => 'Test', 'resolveType' => function () { }], null, true);
}
/**
* @expectedException Youshido\GraphQL\Validator\Exception\ConfigurationException
*/
public function testConfigNoResolve()
{
new InterfaceTypeConfig(['name' => 'Test', 'fields' => ['id' => new IntType()]], null, true);
}
/**
* @expectedException Youshido\GraphQL\Validator\Exception\ConfigurationException
*/
public function testConfigInvalidResolve()
{
$config = new InterfaceTypeConfig(['name' => 'Test', 'fields' => ['id' => new IntType()]], null, false);
$config->resolveType(['invalid object']);
}
public function testInterfaces()
{
$interfaceConfig = new InterfaceTypeConfig([
'name' => 'Test',
'fields' => ['id' => new IntType()],
'resolveType' => function ($object) {
return $object->getType();
}
], null, true);
$object = new ObjectType(['name' => 'User', 'fields' => ['name' => new StringType()]]);
$this->assertEquals($interfaceConfig->getName(), 'Test');
$this->assertEquals($interfaceConfig->resolveType($object), $object->getType());
$testInterface = new TestInterfaceType();
$interfaceConfigWithNoResolve = new InterfaceTypeConfig([
'name' => 'Test',
'fields' => ['id' => new IntType()]
], $testInterface, false);
$this->assertEquals($interfaceConfigWithNoResolve->resolveType($object), $object);
}
}