88namespace Magento \Framework \Amqp \Test \Unit ;
99
1010use Magento \Framework \Amqp \Config ;
11+ use Magento \Framework \Amqp \Connection \Factory as ConnectionFactory ;
12+ use Magento \Framework \Amqp \Connection \FactoryOptions ;
1113use Magento \Framework \App \DeploymentConfig ;
12- use Magento \Framework \TestFramework \Unit \Helper \ObjectManager ;
1314use PHPUnit \Framework \MockObject \MockObject ;
1415use PHPUnit \Framework \TestCase ;
1516
@@ -21,9 +22,9 @@ class ConfigTest extends TestCase
2122 private $ deploymentConfigMock ;
2223
2324 /**
24- * @var ObjectManager
25+ * @var ConnectionFactory
2526 */
26- private $ objectManager ;
27+ private $ connectionFactory ;
2728
2829 /**
2930 * @var Config
@@ -32,17 +33,12 @@ class ConfigTest extends TestCase
3233
3334 protected function setUp (): void
3435 {
35- $ this ->objectManager = new ObjectManager ($ this );
3636 $ this ->deploymentConfigMock = $ this ->getMockBuilder (DeploymentConfig::class)
3737 ->disableOriginalConstructor ()
3838 ->setMethods (['getConfigData ' ])
3939 ->getMock ();
40- $ this ->amqpConfig = $ this ->objectManager ->getObject (
41- Config::class,
42- [
43- 'config ' => $ this ->deploymentConfigMock ,
44- ]
45- );
40+ $ this ->connectionFactory = $ this ->createMock (ConnectionFactory::class);
41+ $ this ->amqpConfig = new Config ($ this ->deploymentConfigMock , 'amqp ' , $ this ->connectionFactory );
4642 }
4743
4844 public function testGetNullConfig ()
@@ -140,4 +136,70 @@ public function testGetCustomConfig()
140136 $ this ->assertEquals ($ expectedSsl , $ amqpConfig ->getValue (Config::SSL ));
141137 $ this ->assertEquals ('randomValue ' , $ amqpConfig ->getValue ('randomKey ' ));
142138 }
139+
140+ /**
141+ * @param array $config
142+ * @param array $expected
143+ * @return void
144+ * @dataProvider configDataProvider
145+ */
146+ public function testCreateConnection (array $ config , array $ expected ): void
147+ {
148+ $ this ->deploymentConfigMock ->expects ($ this ->once ())
149+ ->method ('getConfigData ' )
150+ ->with (Config::QUEUE_CONFIG )
151+ ->willReturn (
152+ [
153+ Config::AMQP_CONFIG => $ config
154+ ]
155+ );
156+ $ this ->connectionFactory ->expects ($ this ->once ())
157+ ->method ('create ' )
158+ ->with (
159+ $ this ->callback (
160+ function (FactoryOptions $ factoryOptions ) use ($ expected ) {
161+ $ actual = [];
162+ foreach (array_keys ($ expected ) as $ method ) {
163+ $ actual [$ method ] = $ factoryOptions ->$ method ();
164+ }
165+ return $ actual === $ expected ;
166+ }
167+ )
168+ );
169+ $ this ->amqpConfig ->getChannel ();
170+ }
171+
172+ /**
173+ * @return array
174+ */
175+ public function configDataProvider (): array
176+ {
177+ return [
178+ [
179+ [
180+ Config::HOST => 'localhost ' ,
181+ Config::PORT => '5672 ' ,
182+ Config::USERNAME => 'user ' ,
183+ Config::PASSWORD => 'pass ' ,
184+ Config::VIRTUALHOST => '/ ' ,
185+ ],
186+ [
187+ 'isSslEnabled ' => false
188+ ]
189+ ],
190+ [
191+ [
192+ Config::HOST => 'localhost ' ,
193+ Config::PORT => '5672 ' ,
194+ Config::USERNAME => 'user ' ,
195+ Config::PASSWORD => 'pass ' ,
196+ Config::VIRTUALHOST => '/ ' ,
197+ Config::SSL => ' true ' ,
198+ ],
199+ [
200+ 'isSslEnabled ' => true
201+ ]
202+ ]
203+ ];
204+ }
143205}
0 commit comments