|
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
|
|
|
use Symfony\Component\Filesystem\Filesystem; |
|
25
|
|
|
|
|
26
|
|
|
/* |
|
27
|
|
|
* Based on https://github.com/symfony/symfony/blob/2.7/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/WebTestCase.php |
|
28
|
|
|
*/ |
|
29
|
|
|
class WebTestCase extends BaseKernelTestCase |
|
30
|
|
|
{ |
|
31
|
|
|
protected static function getKernelClass() |
|
32
|
|
|
{ |
|
33
|
|
|
require_once __DIR__.'/app/AppKernel.php'; |
|
34
|
|
|
|
|
35
|
|
|
return 'FOS\ElasticaBundle\Tests\Functional\app\AppKernel'; |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
public static function setUpBeforeClass() |
|
39
|
|
|
{ |
|
40
|
|
|
static::deleteTmpDir(); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
public static function tearDownAfterClass() |
|
44
|
|
|
{ |
|
45
|
|
|
static::deleteTmpDir(); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
protected static function deleteTmpDir() |
|
49
|
|
|
{ |
|
50
|
|
|
if (!file_exists($dir = sys_get_temp_dir().'/'.static::getVarDir())) { |
|
51
|
|
|
return; |
|
52
|
|
|
} |
|
53
|
|
|
$fs = new Filesystem(); |
|
54
|
|
|
$fs->remove($dir); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
protected static function createKernel(array $options = []) |
|
58
|
|
|
{ |
|
59
|
|
|
$class = self::getKernelClass(); |
|
60
|
|
|
|
|
61
|
|
|
if (!isset($options['test_case'])) { |
|
62
|
|
|
throw new \InvalidArgumentException('The option "test_case" must be set.'); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
return new $class( |
|
66
|
|
|
static::getVarDir(), |
|
67
|
|
|
$options['test_case'], |
|
68
|
|
|
isset($options['root_config']) ? $options['root_config'] : 'config.yml', |
|
69
|
|
|
isset($options['environment']) ? $options['environment'] : strtolower(static::getVarDir().$options['test_case']), |
|
70
|
|
|
isset($options['debug']) ? $options['debug'] : true |
|
71
|
|
|
); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
protected static function getVarDir() |
|
75
|
|
|
{ |
|
76
|
|
|
return substr(strrchr(get_called_class(), '\\'), 1); |
|
77
|
|
|
} |
|
78
|
|
|
} |
|
79
|
|
|
|