|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/******************************************************************************* |
|
4
|
|
|
* This file is part of the GraphQL Bundle package. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) YnloUltratech <[email protected]> |
|
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 Ynlo\GraphQLBundle\Test; |
|
13
|
|
|
|
|
14
|
|
|
use PHPUnit\Util\Blacklist; |
|
15
|
|
|
use Symfony\Bundle\FrameworkBundle\Client; |
|
16
|
|
|
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* Class ApiTestCase |
|
20
|
|
|
*/ |
|
21
|
|
|
class ApiTestCase extends WebTestCase |
|
22
|
|
|
{ |
|
23
|
|
|
use DataFixtureTrait; |
|
24
|
|
|
use RequestHelperTrait; |
|
25
|
|
|
use ResponseHelperTrait; |
|
26
|
|
|
use JsonHelperTrait; |
|
27
|
|
|
use DoctrineORMHelperTrait; |
|
28
|
|
|
use GraphQLHelperTrait; |
|
29
|
|
|
|
|
30
|
|
|
private static $client; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* Whether the client should be cleared after each test |
|
34
|
|
|
* |
|
35
|
|
|
* @var bool |
|
36
|
|
|
*/ |
|
37
|
|
|
protected $cleanup = true; |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* Constructs a test case with the given name. |
|
41
|
|
|
* |
|
42
|
|
|
* @param string $name |
|
43
|
|
|
* @param array $data |
|
44
|
|
|
* @param string $dataName |
|
45
|
|
|
*/ |
|
46
|
|
|
public function __construct($name = null, array $data = [], $dataName = '') |
|
47
|
|
|
{ |
|
48
|
|
|
parent::__construct($name, $data, $dataName); |
|
49
|
|
|
|
|
50
|
|
|
Blacklist::$blacklistedClassNames['Ynlo\GraphQLBundle\Test\ApiTestCase'] = 1; |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* {@inheritdoc} |
|
56
|
|
|
*/ |
|
57
|
|
|
public static function setUpBeforeClass() |
|
58
|
|
|
{ |
|
59
|
|
|
self::$client = null; |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* {@inheritdoc} |
|
64
|
|
|
*/ |
|
65
|
21 |
|
public function setUp() |
|
66
|
|
|
{ |
|
67
|
21 |
|
self::loadFixtures(); |
|
68
|
21 |
|
} |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* {@inheritdoc} |
|
72
|
|
|
*/ |
|
73
|
21 |
|
protected function tearDown() |
|
74
|
|
|
{ |
|
75
|
21 |
|
if ($this->cleanup) { |
|
76
|
21 |
|
self::$client = null; |
|
77
|
|
|
} |
|
78
|
21 |
|
} |
|
79
|
|
|
|
|
80
|
|
|
/** |
|
81
|
|
|
* {@inheritdoc} |
|
82
|
|
|
*/ |
|
83
|
21 |
|
protected static function createClient(array $options = [], array $server = []) |
|
84
|
|
|
{ |
|
85
|
21 |
|
$client = parent::createClient($options, $server); |
|
86
|
21 |
|
self::$client = $client; |
|
87
|
|
|
|
|
88
|
21 |
|
return $client; |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
/** |
|
92
|
|
|
* {@inheritdoc} |
|
93
|
|
|
*/ |
|
94
|
21 |
|
protected static function getClient(): Client |
|
95
|
|
|
{ |
|
96
|
21 |
|
return self::$client ?? self::createClient(); |
|
97
|
|
|
} |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
|