Completed
Push — 1.0 ( d216e1...58fc60 )
by David
02:54
created

SymfonyContainerAdapterTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
c 1
b 0
f 0
lcom 0
cbo 4
dl 0
loc 49
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A testContainer() 0 12 1
A testContainerNotFound() 0 8 1
A testContainerWithException() 0 11 1
A exceptionFactory() 0 4 1
1
<?php
2
3
4
namespace TheCodingMachine\Interop\ServiceProviderBridgeBundle;
5
6
7
use Symfony\Component\DependencyInjection\ContainerBuilder;
8
use Symfony\Component\DependencyInjection\Definition;
9
10
class SymfonyContainerAdapterTest extends \PHPUnit_Framework_TestCase
11
{
12
13
    public function testContainer()
14
    {
15
        $container = new ContainerBuilder();
16
        $container->setParameter('database_host', 'localhost');
17
18
        $container->compile();
19
20
        $containerAdapter = new SymfonyContainerAdapter($container);
21
22
        $this->assertTrue($containerAdapter->has('database_host'));
23
        $this->assertFalse($containerAdapter->has('not_exists'));
24
    }
25
26
    /**
27
     * @expectedException \TheCodingMachine\Interop\ServiceProviderBridgeBundle\Exception\NotFoundException
28
     */
29
    public function testContainerNotFound()
30
    {
31
        $container = new ContainerBuilder();
32
        $container->compile();
33
        $containerAdapter = new SymfonyContainerAdapter($container);
34
35
        $containerAdapter->get('not_found');
36
    }
37
38
    /**
39
     * @expectedException \TheCodingMachine\Interop\ServiceProviderBridgeBundle\Exception\ContainerException
40
     */
41
    public function testContainerWithException()
42
    {
43
        $container = new ContainerBuilder();
44
        $definition = new Definition(\stdClass::class);
45
        $definition->setFactory(self::class, "exceptionFactory");
0 ignored issues
show
Unused Code introduced by
The call to Definition::setFactory() has too many arguments starting with 'exceptionFactory'.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
46
        $container->setDefinition('mydef', $definition);
47
        $container->compile();
48
        $containerAdapter = new SymfonyContainerAdapter($container);
49
50
        $containerAdapter->get('mydef');
51
    }
52
53
    public static function exceptionFactory()
54
    {
55
        throw new \Exception('Boom!');
56
    }
57
58
}
59