1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the FOSElasticaBundle package. |
5
|
|
|
* |
6
|
|
|
* (c) FriendsOfSymfony <http://friendsofsymfony.github.com/> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* This file is part of the FOSElasticaBundle project. |
14
|
|
|
* |
15
|
|
|
* (c) Tim Nagel <[email protected]> |
16
|
|
|
* |
17
|
|
|
* This source file is subject to the MIT license that is bundled |
18
|
|
|
* with this source code in the file LICENSE. |
19
|
|
|
*/ |
20
|
|
|
|
21
|
|
|
namespace FOS\ElasticaBundle\Tests\Functional; |
22
|
|
|
|
23
|
|
|
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase as BaseKernelTestCase; |
24
|
|
|
|
25
|
|
|
/* |
26
|
|
|
* Based on https://github.com/symfony/symfony/blob/2.7/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/WebTestCase.php |
27
|
|
|
*/ |
28
|
|
|
class WebTestCase extends BaseKernelTestCase |
29
|
|
|
{ |
30
|
|
|
protected static function getKernelClass() |
31
|
|
|
{ |
32
|
|
|
require_once __DIR__.'/app/AppKernel.php'; |
33
|
|
|
|
34
|
|
|
return 'FOS\ElasticaBundle\Tests\Functional\app\AppKernel'; |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
public static function setUpBeforeClass() |
38
|
|
|
{ |
39
|
|
|
static::deleteTmpDir(); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
public static function tearDownAfterClass() |
43
|
|
|
{ |
44
|
|
|
static::deleteTmpDir(); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
protected static function deleteTmpDir() |
48
|
|
|
{ |
49
|
|
|
if (!file_exists($dir = sys_get_temp_dir().'/'.static::getVarDir())) { |
50
|
|
|
return; |
51
|
|
|
} |
52
|
|
|
$fs = new Filesystem(); |
53
|
|
|
$fs->remove($dir); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
protected static function createKernel(array $options = []) |
57
|
|
|
{ |
58
|
|
|
$class = self::getKernelClass(); |
59
|
|
|
|
60
|
|
|
if (!isset($options['test_case'])) { |
61
|
|
|
throw new \InvalidArgumentException('The option "test_case" must be set.'); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
return new $class( |
65
|
|
|
static::getVarDir(), |
66
|
|
|
$options['test_case'], |
67
|
|
|
isset($options['root_config']) ? $options['root_config'] : 'config.yml', |
68
|
|
|
isset($options['environment']) ? $options['environment'] : strtolower(static::getVarDir().$options['test_case']), |
69
|
|
|
isset($options['debug']) ? $options['debug'] : true |
70
|
|
|
); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
protected static function getVarDir() |
74
|
|
|
{ |
75
|
|
|
return substr(strrchr(get_called_class(), '\\'), 1); |
76
|
|
|
} |
77
|
|
|
} |
78
|
|
|
|