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 pathTestCase.php
97 lines (83 loc) · 2.98 KB
/
TestCase.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
<?php
use Orchestra\Testbench\TestCase as BaseTestCase;
class TestCase extends BaseTestCase
{
protected $queries;
protected $data;
/**
* Setup the test environment.
*/
public function setUp()
{
parent::setUp();
$this->queries = include(__DIR__.'/Objects/queries.php');
$this->data = include(__DIR__.'/Objects/data.php');
}
protected function getEnvironmentSetUp($app)
{
$app['config']->set('graphql.schemas.default', [
'query' => [
'examples' => ExamplesQuery::class,
'examplesContext' => ExamplesContextQuery::class,
'examplesRoot' => ExamplesRootQuery::class,
'examplesAuthorize' => ExamplesAuthorizeQuery::class,
'examplesAuthenticated' => ExamplesAuthenticatedQuery::class,
'examplesPagination' => ExamplesPaginationQuery::class,
],
'mutation' => [
'updateExample' => UpdateExampleMutation::class
]
]);
$app['config']->set('graphql.schemas.custom', [
'query' => [
'examplesCustom' => ExamplesQuery::class,
],
'mutation' => [
'updateExampleCustom' => UpdateExampleMutation::class
]
]);
$app['config']->set('graphql.types', [
'Example' => ExampleType::class
]);
}
protected function assertGraphQLSchema($schema)
{
$this->assertInstanceOf('GraphQL\Type\Schema', $schema);
}
protected function assertGraphQLSchemaHasQuery($schema, $key)
{
//Query
$query = $schema->getQueryType();
$queryFields = $query->getFields();
$this->assertArrayHasKey($key, $queryFields);
$queryField = $queryFields[$key];
$queryListType = $queryField->getType();
$queryType = $queryListType->getWrappedType();
$this->assertInstanceOf('GraphQL\Type\Definition\FieldDefinition', $queryField);
$this->assertInstanceOf('GraphQL\Type\Definition\ListOfType', $queryListType);
$this->assertInstanceOf('GraphQL\Type\Definition\ObjectType', $queryType);
}
protected function assertGraphQLSchemaHasMutation($schema, $key)
{
//Mutation
$mutation = $schema->getMutationType();
$mutationFields = $mutation->getFields();
$this->assertArrayHasKey($key, $mutationFields);
$mutationField = $mutationFields[$key];
$mutationType = $mutationField->getType();
$this->assertInstanceOf('GraphQL\Type\Definition\FieldDefinition', $mutationField);
$this->assertInstanceOf('GraphQL\Type\Definition\ObjectType', $mutationType);
}
protected function getPackageProviders($app)
{
return [
\Folklore\GraphQL\ServiceProvider::class
];
}
protected function getPackageAliases($app)
{
return [
'GraphQL' => \Folklore\GraphQL\Support\Facades\GraphQL::class
];
}
}