Passed
Pull Request — master (#19)
by Simon
04:16
created

WebTestCase::getContainer()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 4
c 1
b 0
f 0
nc 2
nop 0
dl 0
loc 8
rs 10
1
<?php
2
3
namespace Sil\RouteSecurityBundle\Tests;
4
5
use Sil\RouteSecurityBundle\Tests\Fixtures\AppKernel;
6
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase as BaseWebTestCase;
7
use Symfony\Component\DependencyInjection\ContainerInterface;
8
use Symfony\Component\Filesystem\Filesystem;
9
use Symfony\Component\HttpKernel\Kernel;
10
11
abstract class WebTestCase extends BaseWebTestCase
12
{
13
    protected function deleteTmpDir()
14
    {
15
        if (!file_exists($dir = sys_get_temp_dir().'/'.Kernel::VERSION)) {
16
            return;
17
        }
18
19
        $fs = new Filesystem();
20
        $fs->remove($dir);
21
    }
22
23
    protected static function getContainer(): ContainerInterface
24
    {
25
        if (!static::$kernel) {
26
            static::$kernel = static::createKernel();
27
        }
28
        static::$kernel->boot();
29
30
        return static::$kernel->getContainer();
31
    }
32
33
    protected static function getKernelClass()
34
    {
35
        return AppKernel::class;
36
    }
37
38
    protected static function createKernel(array $options = array())
39
    {
40
        $class = self::getKernelClass();
41
42
        return new $class(
43
            'default',
44
            isset($options['debug']) ? $options['debug'] : true
45
        );
46
    }
47
48
    public function setUp(): void
49
    {
50
        parent::setUp();
51
        $this->deleteTmpDir();
52
    }
53
}
54