This repository was archived by the owner on Feb 10, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 232
/
Copy pathFieldTest.php
69 lines (59 loc) · 1.73 KB
/
FieldTest.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
<?php
use Folklore\Support\Field;
use GraphQL\Type\Definition\Type;
use GraphQL\Type\Definition\ObjectType;
class FieldTest extends TestCase
{
protected function getFieldClass()
{
return ExampleField::class;
}
/**
* Test get attributes
*
* @test
*/
public function testGetAttributes()
{
$class = $this->getFieldClass();
$field = new $class();
$attributes = $field->getAttributes();
$this->assertArrayHasKey('name', $attributes);
$this->assertArrayHasKey('type', $attributes);
$this->assertArrayHasKey('args', $attributes);
$this->assertArrayHasKey('resolve', $attributes);
$this->assertInternalType('array', $attributes['args']);
$this->assertInstanceOf(Closure::class, $attributes['resolve']);
$this->assertInstanceOf(get_class($field->type()), $attributes['type']);
}
/**
* Test resolve closure
*
* @test
*/
public function testResolve()
{
$class = $this->getFieldClass();
$field = $this->getMockBuilder($class)
->setMethods(['resolve'])
->getMock();
$field->expects($this->once())
->method('resolve');
$attributes = $field->getAttributes();
$attributes['resolve'](null, [], [], null);
}
/**
* Test to array
*
* @test
*/
public function testToArray()
{
$class = $this->getFieldClass();
$field = new $class();
$array = $field->toArray();
$this->assertInternalType('array', $array);
$attributes = $field->getAttributes();
$this->assertEquals($attributes, $array);
}
}