|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace RabbitMqModule\Service; |
|
4
|
|
|
|
|
5
|
|
|
use Interop\Container\ContainerInterface; |
|
6
|
|
|
use RabbitMqModule\Service\AbstractFactory as ModuleAbstractFactory; |
|
7
|
|
|
use Zend\Stdlib\ArrayObject; |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* Class AbstractFactoryTest |
|
11
|
|
|
* @package RabbitMqModule\Service |
|
12
|
|
|
*/ |
|
13
|
|
|
class AbstractFactoryTest extends \PHPUnit_Framework_TestCase |
|
14
|
|
|
{ |
|
15
|
|
|
public function testGetOptions() |
|
16
|
|
|
{ |
|
17
|
|
|
$configuration = [ |
|
18
|
|
|
'rabbitmq_module' => [ |
|
19
|
|
|
'default-key' => [ |
|
20
|
|
|
'default-name' => [ |
|
21
|
|
|
'opt2' => 'value2', |
|
22
|
|
|
], |
|
23
|
|
|
'name1' => [ |
|
24
|
|
|
'opt1' => 'value1', |
|
25
|
|
|
], |
|
26
|
|
|
], |
|
27
|
|
|
], |
|
28
|
|
|
]; |
|
29
|
|
|
|
|
30
|
|
|
/** @var ContainerInterface|\PHPUnit_Framework_MockObject_MockObject $serviceLocator */ |
|
31
|
|
|
$serviceLocator = static::getMockBuilder(ContainerInterface::class) |
|
32
|
|
|
->setMethods(['get', 'has']) |
|
33
|
|
|
->getMock(); |
|
34
|
|
|
$factory = static::getMockBuilder(ModuleAbstractFactory::class) |
|
35
|
|
|
->setConstructorArgs(['default-name']) |
|
36
|
|
|
->setMethods(['getOptionsClass', '__invoke']) |
|
37
|
|
|
->getMock(); |
|
38
|
|
|
|
|
39
|
|
|
$serviceLocator->method('get')->willReturn($configuration); |
|
40
|
|
|
$serviceLocator->method('has')->willReturn(true); |
|
41
|
|
|
$factory->method('getOptionsClass')->willReturn('ArrayObject'); |
|
42
|
|
|
|
|
43
|
|
|
/* @var ModuleAbstractFactory $factory */ |
|
44
|
|
|
/** @var ArrayObject $ret */ |
|
45
|
|
|
$ret = $factory->getOptions($serviceLocator, 'default-key'); |
|
46
|
|
|
|
|
47
|
|
|
static::assertInstanceOf('ArrayObject', $ret); |
|
48
|
|
|
static::assertEquals($configuration['rabbitmq_module']['default-key']['default-name'], $ret->getArrayCopy()); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* @expectedException \RuntimeException |
|
53
|
|
|
*/ |
|
54
|
|
|
public function testGetInvalidOptions() |
|
55
|
|
|
{ |
|
56
|
|
|
$configuration = [ |
|
57
|
|
|
'rabbitmq_module' => [ |
|
58
|
|
|
'default-key' => [ |
|
59
|
|
|
'default-name' => [ |
|
60
|
|
|
'opt2' => 'value2', |
|
61
|
|
|
], |
|
62
|
|
|
'name1' => [ |
|
63
|
|
|
'opt1' => 'value1', |
|
64
|
|
|
], |
|
65
|
|
|
], |
|
66
|
|
|
], |
|
67
|
|
|
]; |
|
68
|
|
|
|
|
69
|
|
|
/** @var ContainerInterface|\PHPUnit_Framework_MockObject_MockObject $serviceLocator */ |
|
70
|
|
|
$serviceLocator = static::getMockBuilder(ContainerInterface::class) |
|
71
|
|
|
->setMethods(['get', 'has']) |
|
72
|
|
|
->getMock(); |
|
73
|
|
|
$factory = static::getMockBuilder(ModuleAbstractFactory::class) |
|
74
|
|
|
->setConstructorArgs(['default-name']) |
|
75
|
|
|
->setMethods(['getOptionsClass', '__invoke']) |
|
76
|
|
|
->getMock(); |
|
77
|
|
|
|
|
78
|
|
|
$serviceLocator->method('get')->willReturn($configuration); |
|
79
|
|
|
|
|
80
|
|
|
/* @var AbstractFactory $factory */ |
|
81
|
|
|
$factory->getOptions($serviceLocator, 'default-key', 'invalid-key'); |
|
82
|
|
|
} |
|
83
|
|
|
} |
|
84
|
|
|
|