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

AbstractServiceFactoryTest::setUp()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 28
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 4
Bugs 0 Features 0
Metric Value
c 4
b 0
f 0
dl 0
loc 28
rs 8.8571
cc 1
eloc 15
nc 1
nop 0
1
<?php
2
3
namespace RabbitMqModule\Service;
4
5
use PhpAmqpLib\Connection\AbstractConnection;
6
use PHPUnit_Framework_TestCase;
7
use Zend\ServiceManager\ServiceManager;
8
9
/**
10
 * Class AbstractServiceFactoryTest
11
 * @package RabbitMqModule\Service
12
 */
13
class AbstractServiceFactoryTest extends PHPUnit_Framework_TestCase
14
{
15
    /**
16
     * @var \Zend\ServiceManager\ServiceManager
17
     */
18
    protected $serviceManager;
19
20
    /**
21
     * {@inheritdoc}
22
     */
23
    public function setUp()
24
    {
25
        $this->serviceManager = new ServiceManager();
26
        $this->serviceManager->setService(
27
            'Configuration',
28
            [
29
                'rabbitmq_module' => [
30
                    'connection' => [
31
                        'default' => [],
32
                    ],
33
                    'producer' => [
34
                        'foo' => [
35
                            'exchange' => [],
36
                        ],
37
                    ],
38
                    'foo' => [
39
                        'bar' => [
40
41
                        ],
42
                    ],
43
                    'factories' => [
44
                        'foo' => 'fooFactory',
45
                        'producer' => ServiceFactoryMock::class,
46
                    ],
47
                ],
48
            ]
49
        );
50
    }
51
52
    public function testCanCreateServiceWithName()
53
    {
54
        $sm = $this->serviceManager;
55
        $factory = new AbstractServiceFactory();
56
        static::assertTrue($factory->canCreate($sm, 'rabbitmq_module.foo.bar'));
57
        static::assertFalse($factory->canCreate($sm, 'rabbitmq_module.foo.bar2'));
58
    }
59
60
    public function testCreateServiceWithName()
61
    {
62
        $connection = static::getMockBuilder(AbstractConnection::class)
63
            ->disableOriginalConstructor()
64
            ->getMockForAbstractClass();
65
        $sm = $this->serviceManager;
66
        $sm->setService('rabbitmq_module.connection.default', $connection);
67
        $factory = new AbstractServiceFactory();
68
        static::assertTrue(
69
            $factory($sm, 'rabbitmq_module.producer.foo')
70
        );
71
    }
72
73
    /**
74
     * @expectedException \Zend\ServiceManager\Exception\ServiceNotFoundException
75
     */
76
    public function testCreateServiceUnknown()
77
    {
78
        $sm = $this->serviceManager;
79
        $factory = new AbstractServiceFactory();
80
        static::assertTrue(
81
            $factory($sm, 'rabbitmq_module.unknown-key.foo')
82
        );
83
    }
84
}
85