8
8
namespace Magento \Framework \Amqp \Test \Unit ;
9
9
10
10
use Magento \Framework \Amqp \Config ;
11
+ use Magento \Framework \Amqp \Connection \Factory as ConnectionFactory ;
12
+ use Magento \Framework \Amqp \Connection \FactoryOptions ;
11
13
use Magento \Framework \App \DeploymentConfig ;
12
- use Magento \Framework \TestFramework \Unit \Helper \ObjectManager ;
13
14
use PHPUnit \Framework \MockObject \MockObject ;
14
15
use PHPUnit \Framework \TestCase ;
15
16
@@ -21,9 +22,9 @@ class ConfigTest extends TestCase
21
22
private $ deploymentConfigMock ;
22
23
23
24
/**
24
- * @var ObjectManager
25
+ * @var ConnectionFactory
25
26
*/
26
- private $ objectManager ;
27
+ private $ connectionFactory ;
27
28
28
29
/**
29
30
* @var Config
@@ -32,17 +33,12 @@ class ConfigTest extends TestCase
32
33
33
34
protected function setUp (): void
34
35
{
35
- $ this ->objectManager = new ObjectManager ($ this );
36
36
$ this ->deploymentConfigMock = $ this ->getMockBuilder (DeploymentConfig::class)
37
37
->disableOriginalConstructor ()
38
38
->setMethods (['getConfigData ' ])
39
39
->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 );
46
42
}
47
43
48
44
public function testGetNullConfig ()
@@ -140,4 +136,70 @@ public function testGetCustomConfig()
140
136
$ this ->assertEquals ($ expectedSsl , $ amqpConfig ->getValue (Config::SSL ));
141
137
$ this ->assertEquals ('randomValue ' , $ amqpConfig ->getValue ('randomKey ' ));
142
138
}
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
+ }
143
205
}
0 commit comments