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

WebTestCase   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 16
c 1
b 0
f 0
dl 0
loc 41
rs 10
wmc 8

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getContainer() 0 8 2
A setUp() 0 4 1
A getKernelClass() 0 3 1
A deleteTmpDir() 0 8 2
A createKernel() 0 7 2
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