-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
/
AbstractWebTestCase.php
81 lines (66 loc) · 2.32 KB
/
AbstractWebTestCase.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Bundle\SecurityBundle\Tests\Functional;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase as BaseWebTestCase;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\HttpKernel\KernelInterface;
abstract class AbstractWebTestCase extends BaseWebTestCase
{
public static function assertRedirect($response, $location)
{
self::assertTrue($response->isRedirect(), 'Response is not a redirect, got status code: '.substr($response, 0, 2000));
self::assertEquals('http://localhost'.$location, $response->headers->get('Location'));
}
public static function setUpBeforeClass(): void
{
static::deleteTmpDir();
}
public static function tearDownAfterClass(): void
{
static::deleteTmpDir();
}
public function provideSecuritySystems()
{
yield [['enable_authenticator_manager' => true]];
yield [['enable_authenticator_manager' => false]];
}
protected static function deleteTmpDir()
{
if (!file_exists($dir = sys_get_temp_dir().'/'.static::getVarDir())) {
return;
}
$fs = new Filesystem();
$fs->remove($dir);
}
protected static function getKernelClass(): string
{
require_once __DIR__.'/app/AppKernel.php';
return 'Symfony\Bundle\SecurityBundle\Tests\Functional\app\AppKernel';
}
protected static function createKernel(array $options = []): KernelInterface
{
$class = self::getKernelClass();
if (!isset($options['test_case'])) {
throw new \InvalidArgumentException('The option "test_case" must be set.');
}
return new $class(
static::getVarDir(),
$options['test_case'],
$options['root_config'] ?? 'config.yml',
$options['environment'] ?? strtolower(static::getVarDir().$options['test_case']),
$options['debug'] ?? false,
$options['enable_authenticator_manager'] ?? false
);
}
protected static function getVarDir()
{
return 'SB'.substr(strrchr(static::class, '\\'), 1);
}
}