|
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; |
|
13
|
|
|
|
|
14
|
|
|
use Overblog\GraphQLBundle\Tests\Functional\app\AppKernel; |
|
15
|
|
|
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; |
|
16
|
|
|
use Symfony\Component\Filesystem\Filesystem; |
|
17
|
|
|
use Symfony\Component\HttpFoundation\Request; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* TestCase. |
|
21
|
|
|
*/ |
|
22
|
|
|
abstract class TestCase extends WebTestCase |
|
23
|
|
|
{ |
|
24
|
|
|
/** |
|
25
|
|
|
* @var AppKernel[] |
|
26
|
|
|
*/ |
|
27
|
|
|
private static $kernels = []; |
|
28
|
|
|
|
|
29
|
|
|
protected static function getKernelClass() |
|
30
|
|
|
{ |
|
31
|
|
|
require_once __DIR__.'/app/AppKernel.php'; |
|
32
|
|
|
|
|
33
|
|
|
return 'Overblog\GraphQLBundle\Tests\Functional\app\AppKernel'; |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* {@inheritdoc} |
|
38
|
|
|
*/ |
|
39
|
|
|
protected static function createKernel(array $options = []) |
|
40
|
|
|
{ |
|
41
|
|
|
if (null === static::$class) { |
|
42
|
|
|
static::$class = static::getKernelClass(); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
$options['test_case'] = isset($options['test_case']) ? $options['test_case'] : null; |
|
46
|
|
|
|
|
47
|
|
|
$env = isset($options['environment']) ? $options['environment'] : 'overbloggraphbundletest'.strtolower($options['test_case']); |
|
48
|
|
|
$debug = isset($options['debug']) ? $options['debug'] : true; |
|
49
|
|
|
|
|
50
|
|
|
$kernelKey = $options['test_case'] ?: '__default__'; |
|
51
|
|
|
$kernelKey .= '//'.$env.'//'.var_export($debug, true); |
|
52
|
|
|
|
|
53
|
|
|
if (!isset(self::$kernels[$kernelKey])) { |
|
54
|
|
|
self::$kernels[$kernelKey] = new static::$class($env, $debug, $options['test_case']); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
return self::$kernels[$kernelKey]; |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* {@inheritdoc} |
|
62
|
|
|
*/ |
|
63
|
|
|
public static function setUpBeforeClass() |
|
64
|
|
|
{ |
|
65
|
|
|
$fs = new Filesystem(); |
|
66
|
|
|
$fs->remove(sys_get_temp_dir().'/OverblogGraphQLBundle/'); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* {@inheritdoc} |
|
71
|
|
|
*/ |
|
72
|
|
|
protected function tearDown() |
|
73
|
|
|
{ |
|
74
|
|
|
static::$kernel = null; |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
protected static function createAndBootKernel(array $options = []) |
|
78
|
|
|
{ |
|
79
|
|
|
static::bootKernel($options); |
|
80
|
|
|
|
|
81
|
|
|
static::getContainer()->get('overblog_graphql.cache_compiler')->loadClasses(); |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
protected static function executeGraphQLRequest($query, $rootValue = [], $throwException = false) |
|
85
|
|
|
{ |
|
86
|
|
|
$request = new Request(); |
|
87
|
|
|
$request->query->set('query', $query); |
|
88
|
|
|
|
|
89
|
|
|
$req = static::getContainer()->get('overblog_graphql.request_parser')->parse($request); |
|
90
|
|
|
$executor = static::getContainer()->get('overblog_graphql.request_executor'); |
|
91
|
|
|
$executor->setThrowException($throwException); |
|
92
|
|
|
$res = $executor->execute($req, $rootValue); |
|
93
|
|
|
|
|
94
|
|
|
return $res->toArray(); |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
protected static function assertGraphQL($query, array $expectedData = null, array $expectedErrors = null, $rootValue = []) |
|
98
|
|
|
{ |
|
99
|
|
|
$result = static::executeGraphQLRequest($query, $rootValue, true); |
|
100
|
|
|
|
|
101
|
|
|
$expected = []; |
|
102
|
|
|
|
|
103
|
|
|
if (null !== $expectedData) { |
|
104
|
|
|
$expected['data'] = $expectedData; |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
|
|
if (null !== $expectedErrors) { |
|
108
|
|
|
$expected['errors'] = $expectedErrors; |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
static::assertEquals($expected, $result, json_encode($result)); |
|
112
|
|
|
} |
|
113
|
|
|
|
|
114
|
|
|
protected static function getContainer() |
|
115
|
|
|
{ |
|
116
|
|
|
return static::$kernel->getContainer(); |
|
117
|
|
|
} |
|
118
|
|
|
} |
|
119
|
|
|
|