@@ -323,6 +323,66 @@ public function testShouldGetPartitionFromDestination(): void
323
323
$ producer ->send ($ destination , $ message );
324
324
}
325
325
326
+ public function testShouldAllowFalsyKeyFromMessage (): void
327
+ {
328
+ $ key = 0 ;
329
+
330
+ $ kafkaTopic = $ this ->createKafkaTopicMock ();
331
+ $ kafkaTopic
332
+ ->expects ($ this ->once ())
333
+ ->method ('producev ' )
334
+ ->with (
335
+ RD_KAFKA_PARTITION_UA ,
336
+ 0 ,
337
+ '' ,
338
+ $ key
339
+ )
340
+ ;
341
+
342
+ $ kafkaProducer = $ this ->createKafkaProducerMock ();
343
+ $ kafkaProducer
344
+ ->expects ($ this ->once ())
345
+ ->method ('newTopic ' )
346
+ ->willReturn ($ kafkaTopic )
347
+ ;
348
+
349
+ $ message = new RdKafkaMessage ();
350
+ $ message ->setKey ($ key );
351
+
352
+ $ producer = new RdKafkaProducer ($ kafkaProducer , $ this ->createSerializerMock ());
353
+ $ producer ->send (new RdKafkaTopic ('' ), $ message );
354
+ }
355
+
356
+ public function testShouldAllowFalsyKeyFromDestination (): void
357
+ {
358
+ $ key = 0 ;
359
+
360
+ $ kafkaTopic = $ this ->createKafkaTopicMock ();
361
+ $ kafkaTopic
362
+ ->expects ($ this ->once ())
363
+ ->method ('producev ' )
364
+ ->with (
365
+ RD_KAFKA_PARTITION_UA ,
366
+ 0 ,
367
+ '' ,
368
+ $ key
369
+ )
370
+ ;
371
+
372
+ $ kafkaProducer = $ this ->createKafkaProducerMock ();
373
+ $ kafkaProducer
374
+ ->expects ($ this ->once ())
375
+ ->method ('newTopic ' )
376
+ ->willReturn ($ kafkaTopic )
377
+ ;
378
+
379
+ $ destination = new RdKafkaTopic ('' );
380
+ $ destination ->setKey ($ key );
381
+
382
+ $ producer = new RdKafkaProducer ($ kafkaProducer , $ this ->createSerializerMock ());
383
+ $ producer ->send ($ destination , new RdKafkaMessage ());
384
+ }
385
+
326
386
/**
327
387
* @return \PHPUnit\Framework\MockObject\MockObject|ProducerTopic
328
388
*/
0 commit comments