TestCase::createContainer()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 14
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 9
nc 1
nop 1
1
<?php
2
3
/*
4
 * This file is part of php-cache\cache-bundle package.
5
 *
6
 * (c) 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 PHPUnit\Framework\TestCase as BaseTestCase;
16
use Symfony\Component\Config\FileLocator;
17
use Symfony\Component\DependencyInjection\ContainerBuilder;
18
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
19
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
20
21
/**
22
 * Class TestCase.
23
 *
24
 * @author Aaron Scherer <[email protected]>
25
 */
26
class TestCase extends BaseTestCase
27
{
28
    /**
29
     * @param ContainerBuilder $container
30
     * @param string           $file
31
     */
32
    protected function loadFromFile(ContainerBuilder $container, $file)
33
    {
34
        $loader = new YamlFileLoader($container, new FileLocator(__DIR__.'/Fixtures'));
35
        $loader->load($file.'.yml');
36
    }
37
38
    /**
39
     * @param array $data
40
     *
41
     * @return ContainerBuilder
42
     */
43
    protected function createContainer(array $data = [])
44
    {
45
        return new ContainerBuilder(new ParameterBag(array_merge(
46
            [
47
                'kernel.bundles'     => ['FrameworkBundle' => 'Symfony\\Bundle\\FrameworkBundle\\FrameworkBundle'],
48
                'kernel.cache_dir'   => __DIR__,
49
                'kernel.debug'       => false,
50
                'kernel.environment' => 'test',
51
                'kernel.name'        => 'kernel',
52
                'kernel.root_dir'    => __DIR__,
53
            ],
54
            $data
55
        )));
56
    }
57
58
    /**
59
     * @param string $file
60
     * @param array  $data
61
     *
62
     * @return ContainerBuilder
63
     */
64
    protected function createContainerFromFile($file, $data = [])
65
    {
66
        $container = $this->createContainer($data);
67
        $container->registerExtension(new CacheExtension());
68
        $this->loadFromFile($container, $file);
69
70
        $container->getCompilerPassConfig()
71
            ->setOptimizationPasses([]);
72
        $container->getCompilerPassConfig()
73
            ->setRemovingPasses([]);
74
        $container->compile();
75
76
        return $container;
77
    }
78
}
79