1 | <?php |
||
28 | class DependencyInjectionTest extends PHPUnit_Framework_TestCase |
||
29 | { |
||
30 | public function testHasDefaultPool() |
||
31 | { |
||
32 | $container = new ContainerBuilder(); |
||
33 | $extension = new GendoriaCommandQueueExtension(); |
||
34 | $sendDriverMock = $this->getMockBuilder(SendDriverInterface::class)->getMock(); |
||
35 | $config = array( |
||
36 | 'pools' => array( |
||
37 | 'default' => array( |
||
38 | 'send_driver' => '@dummy', |
||
39 | ), |
||
40 | ), |
||
41 | ); |
||
42 | $container->addDefinitions(array( |
||
43 | 'dummy' => new Definition(get_class($sendDriverMock)), |
||
44 | )); |
||
45 | $extension->load(array($config), $container); |
||
46 | $container->addCompilerPass(new PoolsPass()); |
||
47 | $container->compile(); |
||
48 | |||
49 | /* @var $manager MultipleQueueManager */ |
||
50 | $manager = $container->get('gendoria_command_queue.manager'); |
||
51 | $this->assertInstanceOf(MultipleQueueManager::class, $manager); |
||
52 | $reflectionClass = new ReflectionObject($manager); |
||
53 | $defaultPoolProp = $reflectionClass->getProperty('defaultPool'); |
||
54 | $defaultPoolProp->setAccessible(true); |
||
55 | $this->assertNotEmpty($defaultPoolProp->getValue($manager)); |
||
56 | $sendDriversProp = $reflectionClass->getProperty('sendDrivers'); |
||
57 | $sendDriversProp->setAccessible(true); |
||
58 | $this->assertEquals($sendDriversProp->getValue($manager), array('default' => $sendDriverMock)); |
||
59 | } |
||
60 | |||
61 | public function testNoPools() |
||
62 | { |
||
63 | $this->setExpectedException(InvalidConfigurationException::class, 'The child node "pools" at path "gendoria_command_queue" must be configured.'); |
||
64 | $container = new ContainerBuilder(); |
||
65 | $extension = new GendoriaCommandQueueExtension(); |
||
66 | $config = array( |
||
67 | ); |
||
68 | $extension->load(array($config), $container); |
||
69 | } |
||
70 | |||
71 | public function testInvalidSendDriverNoService() |
||
72 | { |
||
73 | $this->setExpectedException(InvalidArgumentException::class, 'Non existing send driver service provided: @dummy.'); |
||
74 | $container = new ContainerBuilder(); |
||
75 | $extension = new GendoriaCommandQueueExtension(); |
||
76 | $config = array( |
||
77 | 'pools' => array( |
||
78 | 'default' => array( |
||
79 | 'send_driver' => '@dummy', |
||
80 | ), |
||
81 | ), |
||
82 | ); |
||
83 | $extension->load(array($config), $container); |
||
84 | $container->addCompilerPass(new PoolsPass()); |
||
85 | $container->compile(); |
||
86 | } |
||
87 | |||
88 | public function testInvalidSendDriverInvalidInterface() |
||
89 | { |
||
90 | $this->setExpectedException(InvalidArgumentException::class, 'Service "dummy" does not implement interface "'.SendDriverInterface::class.'".'); |
||
91 | $container = new ContainerBuilder(); |
||
92 | $sendDriverMock = $this->getMockBuilder(stdClass::class)->getMock(); |
||
93 | $extension = new GendoriaCommandQueueExtension(); |
||
94 | $config = array( |
||
95 | 'pools' => array( |
||
96 | 'default' => array( |
||
97 | 'send_driver' => '@dummy', |
||
98 | ), |
||
99 | ), |
||
100 | ); |
||
101 | $container->addDefinitions(array( |
||
102 | 'dummy' => new Definition(get_class($sendDriverMock)), |
||
103 | )); |
||
104 | $extension->load(array($config), $container); |
||
105 | $container->addCompilerPass(new PoolsPass()); |
||
106 | $container->compile(); |
||
107 | } |
||
108 | } |
||
109 |