1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* All rights reserved |
5
|
|
|
*/ |
6
|
|
|
|
7
|
|
|
namespace Gendoria\CommandQueueBundle\Tests; |
8
|
|
|
|
9
|
|
|
use Gendoria\CommandQueue\QueueManager\MultipleQueueManager; |
10
|
|
|
use Gendoria\CommandQueue\SendDriver\SendDriverInterface; |
11
|
|
|
use Gendoria\CommandQueueBundle\DependencyInjection\GendoriaCommandQueueExtension; |
12
|
|
|
use Gendoria\CommandQueueBundle\DependencyInjection\Pass\PoolsPass; |
13
|
|
|
use InvalidArgumentException; |
14
|
|
|
use PHPUnit_Framework_TestCase; |
15
|
|
|
use ReflectionObject; |
16
|
|
|
use stdClass; |
17
|
|
|
use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException; |
18
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
19
|
|
|
use Symfony\Component\DependencyInjection\Definition; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* Description of ManagerTest |
23
|
|
|
* |
24
|
|
|
* @author Tomasz Struczyński <[email protected]> |
25
|
|
|
* @group CommandQueue |
26
|
|
|
* @group legacy |
27
|
|
|
*/ |
28
|
|
|
class DependencyInjectionTest extends PHPUnit_Framework_TestCase |
29
|
|
|
{ |
30
|
1 |
|
public function testHasDefaultPool() |
31
|
|
|
{ |
32
|
1 |
|
$container = new ContainerBuilder(); |
33
|
1 |
|
$extension = new GendoriaCommandQueueExtension(); |
34
|
1 |
|
$sendDriverMock = $this->getMockBuilder(SendDriverInterface::class)->getMock(); |
35
|
|
|
$config = array( |
36
|
|
|
'pools' => array( |
37
|
|
|
'default' => array( |
38
|
1 |
|
'send_driver' => '@dummy', |
39
|
1 |
|
), |
40
|
1 |
|
), |
41
|
1 |
|
); |
42
|
1 |
|
$container->addDefinitions(array( |
43
|
1 |
|
'dummy' => new Definition(get_class($sendDriverMock)), |
44
|
1 |
|
)); |
45
|
1 |
|
$extension->load(array($config), $container); |
46
|
1 |
|
$container->addCompilerPass(new PoolsPass()); |
47
|
1 |
|
$container->compile(); |
48
|
|
|
|
49
|
|
|
/* @var $manager MultipleQueueManager */ |
50
|
1 |
|
$manager = $container->get('gendoria_command_queue.manager'); |
51
|
1 |
|
$this->assertInstanceOf(MultipleQueueManager::class, $manager); |
52
|
1 |
|
$reflectionClass = new ReflectionObject($manager); |
53
|
1 |
|
$defaultPoolProp = $reflectionClass->getProperty('defaultPool'); |
54
|
1 |
|
$defaultPoolProp->setAccessible(true); |
55
|
1 |
|
$this->assertNotEmpty($defaultPoolProp->getValue($manager)); |
56
|
1 |
|
$sendDriversProp = $reflectionClass->getProperty('sendDrivers'); |
57
|
1 |
|
$sendDriversProp->setAccessible(true); |
58
|
1 |
|
$this->assertEquals($sendDriversProp->getValue($manager), array('default' => $sendDriverMock)); |
59
|
1 |
|
} |
60
|
|
|
|
61
|
1 |
|
public function testNoPools() |
62
|
|
|
{ |
63
|
1 |
|
$this->setExpectedException(InvalidConfigurationException::class, 'The child node "pools" at path "gendoria_command_queue" must be configured.'); |
64
|
1 |
|
$container = new ContainerBuilder(); |
65
|
1 |
|
$extension = new GendoriaCommandQueueExtension(); |
66
|
|
|
$config = array( |
67
|
1 |
|
); |
68
|
1 |
|
$extension->load(array($config), $container); |
69
|
|
|
} |
70
|
|
|
|
71
|
1 |
|
public function testInvalidSendDriverNoService() |
72
|
|
|
{ |
73
|
1 |
|
$this->setExpectedException(InvalidArgumentException::class, 'Non existing send driver service provided: @dummy.'); |
74
|
1 |
|
$container = new ContainerBuilder(); |
75
|
1 |
|
$extension = new GendoriaCommandQueueExtension(); |
76
|
|
|
$config = array( |
77
|
|
|
'pools' => array( |
78
|
1 |
|
'default' => array( |
79
|
1 |
|
'send_driver' => '@dummy', |
80
|
1 |
|
), |
81
|
1 |
|
), |
82
|
1 |
|
); |
83
|
1 |
|
$extension->load(array($config), $container); |
84
|
1 |
|
$container->addCompilerPass(new PoolsPass()); |
85
|
1 |
|
$container->compile(); |
86
|
|
|
} |
87
|
|
|
|
88
|
1 |
|
public function testInvalidSendDriverInvalidInterface() |
89
|
|
|
{ |
90
|
1 |
|
$this->setExpectedException(InvalidArgumentException::class, 'Service "dummy" does not implement interface "'.SendDriverInterface::class.'".'); |
91
|
1 |
|
$container = new ContainerBuilder(); |
92
|
1 |
|
$sendDriverMock = $this->getMockBuilder(stdClass::class)->getMock(); |
93
|
1 |
|
$extension = new GendoriaCommandQueueExtension(); |
94
|
|
|
$config = array( |
95
|
|
|
'pools' => array( |
96
|
|
|
'default' => array( |
97
|
1 |
|
'send_driver' => '@dummy', |
98
|
1 |
|
), |
99
|
1 |
|
), |
100
|
1 |
|
); |
101
|
1 |
|
$container->addDefinitions(array( |
102
|
1 |
|
'dummy' => new Definition(get_class($sendDriverMock)), |
103
|
1 |
|
)); |
104
|
1 |
|
$extension->load(array($config), $container); |
105
|
1 |
|
$container->addCompilerPass(new PoolsPass()); |
106
|
1 |
|
$container->compile(); |
107
|
|
|
} |
108
|
|
|
} |
109
|
|
|
|