Skip to content

Commit f26f411

Browse files
authored
fix: Implement publishAsync on KafkaFake (#340)
* fix: Implement publishAsync on KafkaFake * chore: add tests
1 parent 12b6afe commit f26f411

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

src/Support/Testing/Fakes/KafkaFake.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ public function publish(?string $broker = null): ProducerBuilderFake
3434
return $this->makeProducerBuilderFake($broker);
3535
}
3636

37+
public function asyncPublish(?string $broker = null): ProducerBuilderFake
38+
{
39+
return $this->publish($broker);
40+
}
41+
3742
/** Return a ConsumerBuilder instance. */
3843
public function consumer(array $topics = [], string $groupId = null, string $brokers = null): BuilderFake
3944
{

tests/KafkaFakeTest.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,30 @@ public function testItStorePublishedMessagesOnArray(): void
4040
$this->fake->assertPublished($producer->getMessage());
4141
}
4242

43+
public function testItStoresMultipleMessages(): void
44+
{
45+
for ($i = 0; $i < 3; $i++) {
46+
$this->fake->publish()
47+
->onTopic('topic')
48+
->withBody('test')
49+
->send();
50+
}
51+
52+
$this->fake->assertPublishedTimes(3);
53+
}
54+
55+
public function testItStoresMultipleMessagesWhenPublishingAsync(): void
56+
{
57+
for ($i = 0; $i < 3; $i++) {
58+
$this->fake->asyncPublish()
59+
->onTopic('topic')
60+
->withBody('test')
61+
->send();
62+
}
63+
64+
$this->fake->assertPublishedTimes(3);
65+
}
66+
4367
public function testAssertPublished(): void
4468
{
4569
try {

0 commit comments

Comments
 (0)