Skip to content

Commit

Permalink
wip: test without passing message object
Browse files Browse the repository at this point in the history
  • Loading branch information
mateusjunges committed Nov 14, 2021
1 parent 22815fd commit 9ec5eea
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions src/Support/Testing/Fakes/KafkaFake.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ public function publishOn(string $topic, string $broker = null): ProducerBuilder
/**
* Assert if a messages was published based on a truth-test callback.
*
* @param KafkaProducerMessage $message
* @param KafkaProducerMessage|null $message
* @param null $callback
*/
public function assertPublished(KafkaProducerMessage $message, $callback = null)
public function assertPublished(KafkaProducerMessage $message = null, $callback = null)
{
PHPUnit::assertTrue(
condition: $this->published($message, $callback)->count() > 0,
Expand All @@ -56,11 +56,19 @@ public function assertPublished(KafkaProducerMessage $message, $callback = null)
* Assert that a message was published on a specific topic.
*
* @param string $topic
* @param KafkaProducerMessage $message
* @param KafkaProducerMessage|null $message
* @param callable|null $callback
*/
public function assertPublishedOn(string $topic, KafkaProducerMessage $message, callable $callback = null)
public function assertPublishedOn(string $topic, KafkaProducerMessage $message = null, callable $callback = null)
{
if ($message === null) {
$this->assertPublished(null, function ($messageArray, $publishedTopic) use ($topic) {
return $topic === $publishedTopic;
});

return;
}

$this->assertPublished($message, function ($messageArray, $publishedTopic) use ($callback, $topic, $message) {
if ($publishedTopic !== $topic) {
return false;
Expand All @@ -83,11 +91,11 @@ public function assertNothingPublished()
/**
* Get all messages matching a truth-test callback.
*
* @param KafkaProducerMessage $message
* @param KafkaProducerMessage|null $message
* @param null $callback
* @return \Illuminate\Support\Collection
*/
private function published(KafkaProducerMessage $message, $callback = null): Collection
private function published(KafkaProducerMessage $message = null, $callback = null): Collection
{
if (! $this->hasPublished()) {
return collect();
Expand Down

0 comments on commit 9ec5eea

Please sign in to comment.