AbstractExtensionTest::getContainer()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 11
rs 9.9
c 0
b 0
f 0
cc 2
nc 2
nop 1
1
<?php
2
3
namespace Mathielen\ImportEngineBundle\Tests\DependencyInjection;
4
5
use Symfony\Component\DependencyInjection\ContainerBuilder;
6
7
abstract class AbstractExtensionTest extends AbstractTest
8
{
9
    abstract protected function loadConfiguration(ContainerBuilder $container, $resource);
10
11
    private function getContainer($resource = null)
12
    {
13
        if ($resource) {
14
            $this->loadConfiguration($this->container, $resource);
15
        }
16
17
        $this->container->loadFromExtension($this->extension->getAlias());
18
        $this->container->compile();
19
20
        return $this->container;
21
    }
22
23
    public function testWithoutConfiguration()
24
    {
25
        $container = $this->getContainer();
26
        $this->assertFalse($container->has('mathielen_importengine.import.storagelocator'));
27
        $this->assertFalse($container->has('mathielen_importengine.import.builder'));
28
    }
29
30
    public function testFullConfiguration()
31
    {
32
        $container = $this->getContainer('full');
33
        $this->assertTrue($container->has('mathielen_importengine.import.storagelocator'));
34
        $this->assertTrue($container->has('mathielen_importengine.import.builder'));
35
    }
36
37
    public function testMediumConfiguration()
38
    {
39
        $container = $this->getContainer('medium');
40
        $this->assertTrue($container->has('mathielen_importengine.import.storagelocator'));
41
        $this->assertTrue($container->has('mathielen_importengine.import.builder'));
42
    }
43
44
    public function testMinimumConfiguration()
45
    {
46
        $container = $this->getContainer('minimum');
47
        $this->assertTrue($container->has('mathielen_importengine.import.storagelocator'));
48
        $this->assertTrue($container->has('mathielen_importengine.import.builder'));
49
    }
50
51
    public function testStorageProvidersAreProperlyRegisteredByTheirName()
52
    {
53
        $container = $this->getContainer('full');
54
55
        $storageLocatorDef = $container->findDefinition('mathielen_importengine.import.storagelocator');
56
        $methodCalls = $storageLocatorDef->getMethodCalls();
57
58
        $registeredStorageProviderIds = [];
59
        foreach ($methodCalls as $methodCall) {
60
            $arguments = $methodCall[1];
61
62
            $registeredStorageProviderIds[] = $arguments[0];
63
        }
64
65
        $this->assertEquals(['upload', 'localdir', 'localfile', 'doctrine', 'services'], $registeredStorageProviderIds);
66
    }
67
}
68