Skip to content

Commit dbe56f2

Browse files
committed
test: allow falsy keys
1 parent 62e5a04 commit dbe56f2

File tree

1 file changed

+60
-0
lines changed

1 file changed

+60
-0
lines changed

pkg/rdkafka/Tests/RdKafkaProducerTest.php

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,66 @@ public function testShouldGetPartitionFromDestination(): void
323323
$producer->send($destination, $message);
324324
}
325325

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+
326386
/**
327387
* @return \PHPUnit\Framework\MockObject\MockObject|ProducerTopic
328388
*/

0 commit comments

Comments
 (0)