mateusjunges/laravel-kafka
Laravel Kafka makes it easy to produce and consume Kafka messages in Laravel with a clean, expressive API and improved testability. Build producers and consumers quickly, integrate with your app workflows, and avoid painful Kafka testing setups.
When you want to assert that a message was published into kafka, you can make use of the assertPublished method:
use Junges\Kafka\Facades\Kafka;
use PHPUnit\Framework\TestCase;
class MyTest extends TestCase
{
public function testMyAwesomeApp()
{
Kafka::fake();
$producer = Kafka::publish('broker')
->onTopic('topic')
->withHeaders(['key' => 'value'])
->withBodyKey('foo', 'bar');
$producer->send();
Kafka::assertPublished($producer->getMessage());
}
}
You can also use assertPublished without passing the message argument:
use Junges\Kafka\Facades\Kafka;
use PHPUnit\Framework\TestCase;
class MyTest extends TestCase
{
public function testMyAwesomeApp()
{
Kafka::fake();
Kafka::publish('broker')
->onTopic('topic')
->withHeaders(['key' => 'value'])
->withBodyKey('foo', 'bar');
Kafka::assertPublished();
}
}
<x-sponsors.request-sponsor/>
How can I help you explore Laravel packages today?