Passed
Pull Request — master (#2608)
by Kévin
05:16
created

ApiTestCase::createClient()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 14
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 6
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 14
rs 10
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
use Symfony\Contracts\HttpClient\HttpClientInterface;
19
20
/**
21
 * Base class for functional API tests.
22
 *
23
 * @experimental
24
 *
25
 * @author Kévin Dunglas <[email protected]>
26
 */
27
abstract class ApiTestCase extends KernelTestCase
28
{
29
    /**
30
     * Creates a Client.
31
     *
32
     * @param array $options An array of options to pass to the createKernel method
33
     */
34
    protected static function createClient(array $options = []): Client
35
    {
36
        $kernel = static::bootKernel($options);
37
38
        try {
39
            /**
40
             * @var Client
41
             */
42
            $client = $kernel->getContainer()->get('test.api_platform.client');
43
        } catch (ServiceNotFoundException $e) {
44
            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".');
45
        }
46
47
        return $client;
48
    }
49
}
50