1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of php-cache\cache-bundle package. |
5
|
|
|
* |
6
|
|
|
* (c) 2015-2015 Aaron Scherer <[email protected]>, Tobias Nyholm <[email protected]> |
7
|
|
|
* |
8
|
|
|
* This source file is subject to the MIT license that is bundled |
9
|
|
|
* with this source code in the file LICENSE. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Cache\CacheBundle\Tests\Unit; |
13
|
|
|
|
14
|
|
|
use Cache\CacheBundle\DependencyInjection\CacheExtension; |
15
|
|
|
use Symfony\Component\Config\FileLocator; |
16
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
17
|
|
|
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader; |
18
|
|
|
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Class TestCase. |
22
|
|
|
* |
23
|
|
|
* @author Aaron Scherer <[email protected]> |
24
|
|
|
*/ |
25
|
|
|
class TestCase extends \PHPUnit_Framework_TestCase |
26
|
|
|
{ |
27
|
|
|
/** |
28
|
|
|
* @param ContainerBuilder $container |
29
|
|
|
* @param string $file |
30
|
|
|
*/ |
31
|
|
|
protected function loadFromFile(ContainerBuilder $container, $file) |
32
|
|
|
{ |
33
|
|
|
$loader = new YamlFileLoader($container, new FileLocator(__DIR__.'/Fixtures')); |
34
|
|
|
$loader->load($file.'.yml'); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @param array $data |
39
|
|
|
* |
40
|
|
|
* @return ContainerBuilder |
41
|
|
|
*/ |
42
|
|
|
protected function createContainer(array $data = []) |
43
|
|
|
{ |
44
|
|
|
return new ContainerBuilder(new ParameterBag(array_merge( |
45
|
|
|
[ |
46
|
|
|
'kernel.bundles' => ['FrameworkBundle' => 'Symfony\\Bundle\\FrameworkBundle\\FrameworkBundle'], |
47
|
|
|
'kernel.cache_dir' => __DIR__, |
48
|
|
|
'kernel.debug' => false, |
49
|
|
|
'kernel.environment' => 'test', |
50
|
|
|
'kernel.name' => 'kernel', |
51
|
|
|
'kernel.root_dir' => __DIR__, |
52
|
|
|
], |
53
|
|
|
$data |
54
|
|
|
))); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @param string $file |
59
|
|
|
* @param array $data |
60
|
|
|
* |
61
|
|
|
* @return ContainerBuilder |
62
|
|
|
*/ |
63
|
|
|
protected function createContainerFromFile($file, $data = []) |
64
|
|
|
{ |
65
|
|
|
$container = $this->createContainer($data); |
66
|
|
|
$container->registerExtension(new CacheExtension()); |
67
|
|
|
$this->loadFromFile($container, $file); |
68
|
|
|
|
69
|
|
|
$container->getCompilerPassConfig() |
70
|
|
|
->setOptimizationPasses([]); |
71
|
|
|
$container->getCompilerPassConfig() |
72
|
|
|
->setRemovingPasses([]); |
73
|
|
|
$container->compile(); |
74
|
|
|
|
75
|
|
|
return $container; |
76
|
|
|
} |
77
|
|
|
} |
78
|
|
|
|