26
26
use PHPUnit \Framework \MockObject \MockObject ;
27
27
use PHPUnit \Framework \TestCase ;
28
28
use Psr \Log \LoggerInterface ;
29
+ use Magento \Framework \MessageQueue \DefaultValueProvider ;
29
30
30
31
/**
31
32
* Unit test for Consumer class.
@@ -99,6 +100,11 @@ class ConsumerTest extends TestCase
99
100
*/
100
101
private $ deploymentConfig ;
101
102
103
+ /**
104
+ * @var DefaultValueProvider|MockObject
105
+ */
106
+ private $ defaultValueProvider ;
107
+
102
108
/**
103
109
* Set up.
104
110
*
@@ -123,6 +129,7 @@ protected function setUp(): void
123
129
->disableOriginalConstructor ()
124
130
->getMockForAbstractClass ();
125
131
$ this ->deploymentConfig = $ this ->createMock (DeploymentConfig::class);
132
+ $ this ->defaultValueProvider = $ this ->createMock (DefaultValueProvider::class);
126
133
127
134
$ objectManager = new ObjectManager ($ this );
128
135
$ this ->poisonPillCompare = $ this ->getMockBuilder (PoisonPillCompareInterface::class)
@@ -135,7 +142,8 @@ protected function setUp(): void
135
142
$ this ->callbackInvoker = new CallbackInvoker (
136
143
$ this ->poisonPillRead ,
137
144
$ this ->poisonPillCompare ,
138
- $ this ->deploymentConfig
145
+ $ this ->deploymentConfig ,
146
+ $ this ->defaultValueProvider
139
147
);
140
148
$ this ->consumer = $ objectManager ->getObject (
141
149
Consumer::class,
@@ -182,12 +190,15 @@ protected function setUp(): void
182
190
public function testProcessWithNotFoundException ()
183
191
{
184
192
$ properties = ['topic_name ' => 'topic.name ' ];
185
- $ topicConfig = [];
193
+ $ topicConfig = [' is_synchronous ' => true ];
186
194
$ numberOfMessages = 1 ;
187
195
$ consumerName = 'consumer.name ' ;
188
196
$ exceptionPhrase = new Phrase ('Exception successfully thrown ' );
189
197
$ this ->poisonPillRead ->expects ($ this ->atLeastOnce ())->method ('getLatestVersion ' )->willReturn ('version-1 ' );
190
198
$ this ->poisonPillCompare ->expects ($ this ->atLeastOnce ())->method ('isLatestVersion ' )->willReturn (true );
199
+ $ this ->defaultValueProvider ->expects ($ this ->once ())->method ('getConnection ' )->willReturn ('db ' );
200
+ $ this ->deploymentConfig ->expects ($ this ->any ())->method ('get ' )
201
+ ->with ('queue/consumers_wait_for_messages ' , 1 )->willReturn (1 );
191
202
$ queue = $ this ->getMockBuilder (QueueInterface::class)
192
203
->disableOriginalConstructor ()
193
204
->getMockForAbstractClass ();
@@ -200,14 +211,6 @@ public function testProcessWithNotFoundException()
200
211
$ this ->communicationConfig ->expects ($ this ->once ())->method ('getTopic ' )->with ($ properties ['topic_name ' ])
201
212
->willReturn ($ topicConfig );
202
213
$ this ->configuration ->expects ($ this ->atLeastOnce ())->method ('getConsumerName ' )->willReturn ($ consumerName );
203
- $ consumerConfigItem = $ this ->getMockBuilder (
204
- \Magento \Framework \MessageQueue \Consumer \Config \ConsumerConfigItemInterface::class
205
- )
206
- ->disableOriginalConstructor ()
207
- ->getMockForAbstractClass ();
208
- $ consumerConfigItem ->expects ($ this ->once ())->method ('getConnection ' )->willReturn ('connection_name ' );
209
- $ this ->consumerConfig ->expects ($ this ->once ())->method ('getConsumer ' )->with ($ consumerName )
210
- ->willReturn ($ consumerConfigItem );
211
214
$ this ->messageController ->expects ($ this ->once ())->method ('lock ' )->with ($ envelope , $ consumerName )
212
215
->willThrowException (
213
216
new NotFoundException (
@@ -228,23 +231,17 @@ public function testProcessWithNotFoundException()
228
231
public function testProcessWithGetMaxIdleTimeAndGetSleepConsumerConfigurations ()
229
232
{
230
233
$ numberOfMessages = 1 ;
231
- $ this ->poisonPillRead ->expects ($ this ->atLeastOnce ())->method ('getLatestVersion ' );
234
+ $ this ->poisonPillRead ->expects ($ this ->atLeastOnce ())->method ('getLatestVersion ' )->willReturn ('version-1 ' );
235
+ $ this ->poisonPillCompare ->expects ($ this ->any ())->method ('isLatestVersion ' )->willReturn (true );
236
+ $ this ->defaultValueProvider ->expects ($ this ->once ())->method ('getConnection ' )->willReturn ('db ' );
237
+ $ this ->deploymentConfig ->expects ($ this ->any ())->method ('get ' )
238
+ ->with ('queue/consumers_wait_for_messages ' , 1 )->willReturn (1 );
232
239
$ queue = $ this ->getMockBuilder (\Magento \Framework \MessageQueue \QueueInterface::class)
233
240
->disableOriginalConstructor ()->getMock ();
234
241
$ this ->configuration ->expects ($ this ->once ())->method ('getQueue ' )->willReturn ($ queue );
235
242
$ queue ->expects ($ this ->atMost (2 ))->method ('dequeue ' )->willReturn (null );
236
243
$ this ->configuration ->expects ($ this ->once ())->method ('getMaxIdleTime ' )->willReturn ('2 ' );
237
244
$ this ->configuration ->expects ($ this ->once ())->method ('getSleep ' )->willReturn ('2 ' );
238
- $ consumerName = 'consumer.name ' ;
239
- $ this ->configuration ->expects ($ this ->once ())->method ('getConsumerName ' )->willReturn ($ consumerName );
240
- $ consumerConfigItem = $ this ->getMockBuilder (
241
- \Magento \Framework \MessageQueue \Consumer \Config \ConsumerConfigItemInterface::class
242
- )
243
- ->disableOriginalConstructor ()
244
- ->getMockForAbstractClass ();
245
- $ consumerConfigItem ->expects ($ this ->once ())->method ('getConnection ' )->willReturn ('connection_name ' );
246
- $ this ->consumerConfig ->expects ($ this ->once ())->method ('getConsumer ' )->with ($ consumerName )
247
- ->willReturn ($ consumerConfigItem );
248
245
$ this ->consumer ->process ($ numberOfMessages );
249
246
}
250
247
}
0 commit comments