Completed
Push — master ( be1f89...dd7c75 )
by Artem
13:35
created

ConnectionFactoryTest::testCreateServiceWithInvalidFactory()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 27
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 27
rs 8.8571
cc 1
eloc 14
nc 1
nop 0
1
<?php
2
3
namespace RabbitMqModule\Service;
4
5
use Zend\ServiceManager\ServiceManager;
6
7
/**
8
 * Class ConnectionFactoryTest
9
 * @package RabbitMqModule\Service
10
 */
11
class ConnectionFactoryTest extends \PHPUnit_Framework_TestCase
12
{
13
    public function testCreateService()
14
    {
15
        $factory = new ConnectionFactory('foo');
16
        $serviceManager = new ServiceManager();
17
        $serviceManager->setService(
18
            'Configuration',
19
            [
20
                'rabbitmq_module' => [
21
                    'connection' => [
22
                        'foo' => [
23
                            'type' => 'bar',
24
                        ],
25
                    ],
26
                ],
27
            ]
28
        );
29
30
        $factoryMock = static::getMockBuilder('RabbitMqModule\\Service\\Connection\\ConnectionFactoryInterface')
31
            ->getMock();
32
        $factoryMock->expects(static::once())
33
            ->method('createConnection')
34
            ->will(static::returnValue('foo'));
35
36
        $serviceManager->setService('barFactoryMock', $factoryMock);
37
38
        $factory->setFactoryMap([
39
            'bar' => 'barFactoryMock',
40
        ]);
41
42
        $service = $factory($serviceManager, 'foo');
43
44
        static::assertEquals('foo', $service);
45
    }
46
47
    /**
48
     * @expectedException \InvalidArgumentException
49
     */
50
    public function testCreateServiceWithInvalidType()
51
    {
52
        $factory = new ConnectionFactory('foo');
53
        $serviceManager = new ServiceManager();
54
        $serviceManager->setService(
55
            'Configuration',
56
            [
57
                'rabbitmq_module' => [
58
                    'connection' => [
59
                        'foo' => [
60
                            'type' => 'foo',
61
                        ],
62
                    ],
63
                ],
64
            ]
65
        );
66
67
        $factory($serviceManager, 'foo');
68
    }
69
70
    /**
71
     * @expectedException \RuntimeException
72
     */
73
    public function testCreateServiceWithInvalidFactory()
74
    {
75
        $factory = new ConnectionFactory('foo');
76
        $serviceManager = new ServiceManager();
77
        $serviceManager->setService(
78
            'Configuration',
79
            [
80
                'rabbitmq_module' => [
81
                    'connection' => [
82
                        'foo' => [
83
                            'type' => 'bar',
84
                        ],
85
                    ],
86
                ],
87
            ]
88
        );
89
90
        $serviceManager->setService('barFactoryMock', 'string');
91
92
        $factory->setFactoryMap([
93
            'bar' => 'barFactoryMock',
94
        ]);
95
96
        $service = $factory($serviceManager, 'foo');
97
98
        static::assertEquals('foo', $service);
99
    }
100
}
101