Passed
Pull Request — master (#1)
by Björn
02:56
created

ContainerProviderTrait::getFullyLoadedContainer()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 5
nc 2
nop 1
1
<?php
2
3
namespace BestIt\KitchensinkBundle\Tests;
4
5
use BestIt\KitchensinkBundle\BestItKitchensinkBundle;
6
use BestIt\KitchensinkBundle\DependencyInjection\BestItKitchensinkExtension;
7
use Symfony\Component\DependencyInjection\ContainerBuilder;
8
9
/**
10
 * Provides you with a fully build container.
11
 * @author blange <[email protected]>
12
 * @category Tests
13
 * @package BestIt\KitchensinkBundle
14
 * @version $id$
15
 */
16
trait ContainerProviderTrait
17
{
18
    /**
19
     * Returns a container builder for this app.
20
     * @return ContainerBuilder
21
     */
22
    private function getContainer(): ContainerBuilder
23
    {
24
        $container = new ContainerBuilder();
25
        $container->setParameter('kernel.cache_dir', sys_get_temp_dir());
26
        $container->setParameter('kernel.bundles', ['BestItKitchensinkBundle' => BestItKitchensinkBundle::class]);
27
        $container->set('bestit_kitchensink.data_provider.test_fake', new DataProviderFake());
28
29
        return $container;
30
    }
31
32
    /**
33
     * Returns the full config.
34
     * @return array
35
     */
36
    private function getFullConfig(): array
37
    {
38
        $config = [
39
            'best_it_kitchensink' => [
40
                'data_provider' => 'bestit_kitchensink.data_provider.test_fake',
41
                'template' => 'kitchensink/index.html.twig'
42
            ]
43
        ];
44
        return $config;
45
    }
46
47
    /**
48
     * Checks the full load of the container.
49
     * @param array|void $config Inject another config.
50
     * @return ContainerBuilder
51
     */
52
    public function getFullyLoadedContainer($config = null): ContainerBuilder
53
    {
54
        if ($config === null) {
55
            $config = $this->getFullConfig();
56
        }
57
58
        (new BestItKitchensinkExtension())->load($config, $container = $this->getContainer());
59
60
        return $container;
61
    }
62
}
63