This is the documentation for
v1.12 but the latest version is
v1.13
.
You can switch versions in the menu on the left/at the top.
Check your current version with the following command:
composer show mateusjunges/laravel-kafka
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::publishOn('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::publishOn('topic')
->withHeaders(['key' => 'value'])
->withBodyKey('foo', 'bar');
Kafka::assertPublished();
}
}