Passed
Pull Request — master (#2608)
by Kévin
04:09
created

ApiTestCase   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 7
dl 0
loc 20
rs 10
c 0
b 0
f 0
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A createClient() 0 11 2
1
<?php
2
3
/*
4
 * This file is part of the API Platform project.
5
 *
6
 * (c) Kévin Dunglas <[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
declare(strict_types=1);
13
14
namespace ApiPlatform\Core\Bridge\Symfony\Bundle\Test;
15
16
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
17
use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException;
18
19
/**
20
 * Base class for functional API tests.
21
 *
22
 * @experimental
23
 *
24
 * @author Kévin Dunglas <[email protected]>
25
 */
26
abstract class ApiTestCase extends KernelTestCase
27
{
28
    /**
29
     * Creates a Client.
30
     *
31
     * @param array $options An array of options to pass to the createKernel method
32
     *
33
     * @return Client A Client instance
34
     */
35
    protected static function createClient(array $options = [])
36
    {
37
        $kernel = static::bootKernel($options);
38
39
        try {
40
            $client = $kernel->getContainer()->get('test.api_platform.client');
41
        } catch (ServiceNotFoundException $e) {
42
            throw new \LogicException('You cannot create the client used in functional tests if the BrowserKit component is not available. Try running "composer require symfony/browser-kit".');
43
        }
44
45
        return $client;
46
    }
47
}
48