Completed
Push — master ( e4a43c...c6b5e7 )
by Tomáš
15:17
created

SymfonyContainerAdapterTest   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 70
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 3
dl 0
loc 70
rs 10
c 0
b 0
f 0

8 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 9 1
A testParameters() 0 5 1
A testNonExistingParameters() 0 4 1
A testServices() 0 5 1
A testNonExistingService() 0 5 1
A testUnsupportedMethodsSet() 0 4 1
A testUnsupportedMethodsSetParameter() 0 4 1
A testUnsupportedMethodsInitialized() 0 4 1
1
<?php
2
3
namespace Symplify\NetteAdapterForSymfonyBundles\Tests;
4
5
use Nette\DI\Container;
6
use PHPUnit\Framework\TestCase;
7
use stdClass;
8
use Symplify\NetteAdapterForSymfonyBundles\SymfonyContainerAdapter;
9
10
final class SymfonyContainerAdapterTest extends TestCase
11
{
12
    /**
13
     * @var SymfonyContainerAdapter
14
     */
15
    private $symfonyContainerAdapter;
16
17
    protected function setUp()
18
    {
19
        $containerMock = $this->prophesize(Container::class);
20
        $containerMock->getParameters()->willReturn(['someParameter' => 'someValue']);
21
        $containerMock->hasService('someService')->willReturn(true);
22
        $containerMock->hasService('nonExistingService')->willReturn(false);
23
        $containerMock->getService('someService')->willReturn('service');
24
        $this->symfonyContainerAdapter = new SymfonyContainerAdapter([], $containerMock->reveal());
25
    }
26
27
    public function testParameters()
28
    {
29
        $this->assertSame('someValue', $this->symfonyContainerAdapter->getParameter('someParameter'));
30
        $this->assertTrue($this->symfonyContainerAdapter->hasParameter('someParameter'));
31
    }
32
33
    /**
34
     * @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException
35
     */
36
    public function testNonExistingParameters()
37
    {
38
        $this->symfonyContainerAdapter->getParameter('nonExistingParameter');
39
    }
40
41
    public function testServices()
42
    {
43
        $this->assertTrue($this->symfonyContainerAdapter->has('someService'));
44
        $this->assertSame('service', $this->symfonyContainerAdapter->get('someService'));
45
    }
46
47
    /**
48
     * @expectedException \Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException
49
     */
50
    public function testNonExistingService()
51
    {
52
        $this->assertFalse($this->symfonyContainerAdapter->has('nonExistingService'));
53
        $this->symfonyContainerAdapter->get('nonExistingService');
54
    }
55
56
    /**
57
     * @expectedException \Symplify\NetteAdapterForSymfonyBundles\Exception\UnsupportedApiException
58
     */
59
    public function testUnsupportedMethodsSet()
60
    {
61
        $this->symfonyContainerAdapter->set('someService', new stdClass());
62
    }
63
64
    /**
65
     * @expectedException \Symplify\NetteAdapterForSymfonyBundles\Exception\UnsupportedApiException
66
     */
67
    public function testUnsupportedMethodsSetParameter()
68
    {
69
        $this->symfonyContainerAdapter->setParameter('someParameter', 'someValue');
70
    }
71
72
    /**
73
     * @expectedException \Symplify\NetteAdapterForSymfonyBundles\Exception\UnsupportedApiException
74
     */
75
    public function testUnsupportedMethodsInitialized()
76
    {
77
        $this->symfonyContainerAdapter->initialized('someService');
78
    }
79
}
80