Passed
Push — master ( 36097f...93304f )
by Rafael
03:14
created

ApiTestCase::before()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 2
ccs 1
cts 1
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 0
nc 1
nop 0
crap 1
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
    protected 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
    final public static function setUpBeforeClass()
58
    {
59
        static::$client = null;
60
    }
61
62
    /**
63
     * {@inheritdoc}
64
     */
65 22
    final public function setUp()
66
    {
67 22
        static::loadFixtures();
68 22
        $this->before();
69 22
    }
70
71
    /**
72
     * This method is called before a test is executed.
73
     */
74 22
    public function before()
75
    {
76
77 22
    }
78
79
    /**
80
     * {@inheritdoc}
81
     */
82 22
    final protected function tearDown()
83
    {
84 22
        if ($this->cleanup) {
85 22
            static::$client = null;
86
        }
87 22
        $this->after();
88 22
    }
89
90
    /**
91
     * This method is called after a test is executed.
92
     */
93 22
    public function after()
94
    {
95
96 22
    }
97
98
    /**
99
     * {@inheritdoc}
100
     */
101 22
    protected static function createClient(array $options = [], array $server = [])
102
    {
103 22
        $client = parent::createClient($options, $server);
104 22
        static::$client = $client;
105
106 22
        return $client;
107
    }
108
109
    /**
110
     * {@inheritdoc}
111
     */
112 22
    protected static function getClient(): Client
113
    {
114 22
        return static::$client ?? static::createClient();
115
    }
116
}
117
118