Test Failed
Push — master ( fd2f49...f2c22d )
by Yaroslav
07:55
created

WebTestCase::getRouteResources()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
/*
4
 *
5
 * (c) Yaroslav Honcharuk <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace Yarhon\RouteGuardBundle\Tests\Functional;
12
13
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase as BaseWebTestCase;
14
use Symfony\Component\Filesystem\Filesystem;
15
use Symfony\Bundle\FrameworkBundle\FrameworkBundle;
16
use Symfony\Bundle\SecurityBundle\SecurityBundle;
17
use Yarhon\RouteGuardBundle\YarhonRouteGuardBundle;
18
19
/**
20
 * @author Yaroslav Honcharuk <[email protected]>
21
 */
22
abstract class WebTestCase extends BaseWebTestCase
23
{
24
    protected static $bundles = [];
25
26
    protected static $configs = [];
27
28
    protected static $routeResources = [];
29
30
    protected static $users = [];
31
32
    protected static function getBundles()
33
    {
34
        return array_merge([
35
            FrameworkBundle::class,
36
            SecurityBundle::class,
37
            YarhonRouteGuardBundle::class,
38
        ], static::$bundles);
39
    }
40
41
    protected static function getConfigs()
42
    {
43
        $configs = static::$configs;
44
        $configs['security']['providers']['main']['memory']['users'] = static::$users;
45
        // $configs['framework']['router'] = $routerConfig;
46
47
        return $configs;
48
    }
49
50
    protected static function getRouteResources()
51
    {
52
        return static::$routeResources;
53
    }
54
55
    public static function setUpBeforeClass()
56
    {
57
        static::deleteTempDir();
58
    }
59
60
    public static function tearDownAfterClass()
61
    {
62
        static::deleteTempDir();
63
    }
64
65
    protected static function deleteTempDir()
66
    {
67
        if (!file_exists($dir = static::getTempDir())) {
68
            return;
69
        }
70
71
        $fs = new Filesystem();
72
        $fs->remove($dir);
73
    }
74
75
    protected static function createKernel(array $options = [])
76
    {
77
        return new app\Kernel(
78
            static::getTempDir(),
79
            static::getBundles(),
80
            static::getConfigs(),
81
            static::getRouteResources(),
82
            isset($options['environment']) ? $options['environment'] : 'test',
83
            isset($options['debug']) ? $options['debug'] : true
84
        );
85
    }
86
87
    protected static function getTempDir()
88
    {
89
        return sys_get_temp_dir().'/route-guard-'.substr(strrchr(static::class, '\\'), 1);
90
    }
91
92
    protected static function createClient(array $options = [], array $server = [])
93
    {
94
        $server = array_merge([
95
            'HTTP_HOST' => 'example.com',
96
        ], $server);
97
98
        return parent::createClient($options, $server);
99
    }
100
}
101