Completed
Push — 1.0 ( 9c5da5...1ab6ce )
by David
01:49
created

testSimpleServiceProvider()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 6
nc 1
nop 0
dl 0
loc 11
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
4
namespace TheCodingMachine\Interop\ServiceProviderBridgeBundle;
5
6
7
use Psr\Log\LoggerInterface;
8
use Psr\Log\NullLogger;
9
use Symfony\Component\DependencyInjection\ContainerBuilder;
10
use Symfony\Component\DependencyInjection\Definition;
11
use TheCodingMachine\Interop\ServiceProviderBridgeBundle\Tests\Fixtures\TestServiceProvider;
12
use TheCodingMachine\Interop\ServiceProviderBridgeBundle\Tests\Fixtures\TestServiceProviderOverride;
13
use TheCodingMachine\Interop\ServiceProviderBridgeBundle\Tests\Fixtures\TestServiceProviderOverride2;
14
15
class ServiceProviderCompilationPassTest extends \PHPUnit_Framework_TestCase
16
{
17
    protected function getContainer(array $lazyArray, $useDiscovery = false)
18
    {
19
        $bundle = new InteropServiceProviderBridgeBundle($lazyArray, $useDiscovery);
20
21
        $container = new ContainerBuilder();
22
        $container->setParameter('database_host', 'localhost');
23
        $container->setDefinition('logger', new Definition(NullLogger::class));
24
25
        $bundle->build($container);
26
        $container->compile();
27
        $bundle->setContainer($container);
28
        $bundle->boot();
29
        return $container;
30
    }
31
32
    public function testSimpleServiceProvider()
33
    {
34
        $container = $this->getContainer([
35
            TestServiceProvider::class
36
        ]);
37
38
        $serviceA = $container->get('serviceA');
39
40
        $this->assertInstanceOf(\stdClass::class, $serviceA);
41
        $this->assertEquals(42, $container->get('function'));
42
    }
43
44
    public function testServiceProviderOverrides()
45
    {
46
        $container = $this->getContainer([
47
            TestServiceProvider::class,
48
            TestServiceProviderOverride::class,
49
            TestServiceProviderOverride2::class
50
        ]);
51
52
        $serviceA = $container->get('serviceA');
53
54
        $this->assertInstanceOf(\stdClass::class, $serviceA);
55
        $this->assertEquals('foo', $serviceA->newProperty);
56
        $this->assertEquals('bar', $serviceA->newProperty2);
57
    }
58
59
    /**
60
     * @expectedException \TheCodingMachine\Interop\ServiceProviderBridgeBundle\Exception\InvalidArgumentException
61
     */
62
    /*public function testExceptionMessageIfNoPuliBundle()
0 ignored issues
show
Unused Code Comprehensibility introduced by
59% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
63
    {
64
        $bundle = new InteropServiceProviderBridgeBundle([], true);
65
        $container = new ContainerBuilder();
66
        $bundle->build($container);
67
        $container->compile();
68
    }*/
69
70
    /**
71
     *
72
     */
73
    public function testTcmDiscovery()
74
    {
75
        // If TCM discovery is enabled, the CommonAliasesServiceProvider is registered.
76
        $container = $this->getContainer([], true);
77
78
        $logger = $container->get(LoggerInterface::class);
79
80
        $this->assertInstanceOf(LoggerInterface::class, $logger);
81
    }
82
}
83