Skip to content

Commit c04375f

Browse files
authored
test: allow falsy keys
1 parent 62e5a04 commit c04375f

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

pkg/rdkafka/Tests/RdKafkaProducerTest.php

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,52 @@ 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+
$message = new RdKafkaMessage();
343+
$message->setKey($key);
344+
345+
$producer = new RdKafkaProducer($this->createKafkaProducerMock(), $this->createSerializerMock());
346+
$producer->send(new RdKafkaTopic(''), $message);
347+
}
348+
349+
public function testShouldAllowFalsyKeyFromDestination(): void
350+
{
351+
$key = 0;
352+
353+
$kafkaTopic = $this->createKafkaTopicMock();
354+
$kafkaTopic
355+
->expects($this->once())
356+
->method('producev')
357+
->with(
358+
RD_KAFKA_PARTITION_UA,
359+
0,
360+
'',
361+
$key
362+
)
363+
;
364+
365+
$destination = new RdKafkaTopic('');
366+
$destination->setKey($key);
367+
368+
$producer = new RdKafkaProducer($this->createKafkaProducerMock(), $this->createSerializerMock());
369+
$producer->send($destination, new RdKafkaMessage());
370+
}
371+
326372
/**
327373
* @return \PHPUnit\Framework\MockObject\MockObject|ProducerTopic
328374
*/

0 commit comments

Comments
 (0)