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
|
|
|
|