Skip to content

Commit

Permalink
Merge pull request #11 from tienvx/handle-no-message-dispatched
Browse files Browse the repository at this point in the history
Handle no message dispatched
  • Loading branch information
tienvx authored Mar 11, 2023
2 parents 07805d0 + f7a4a96 commit 59d6404
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/EventListener/DispatchMessageRequestListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function __invoke(RequestEvent $event): void
[$description, $providerStates] = $this->getParameters($request);

$this->handle($providerStates, Action::SETUP);
$event->setResponse($this->getReponse($description));
$this->setReponse($event, $description);
$this->handle($providerStates, Action::TEARDOWN);
}
}
Expand Down Expand Up @@ -65,13 +65,15 @@ private function handle(array $providerStates, string $action): void
}
}

private function getReponse(string $description): Response
private function setReponse(RequestEvent $event, string $description): void
{
$message = $this->messageDispatcherManager->dispatch($description);

return new Response($message->contents, Response::HTTP_OK, [
'Content-Type' => $message->contentType,
'pact_message_metadata' => \base64_encode($message->metadata),
]);
if ($message) {
$event->setResponse(new Response($message->contents, Response::HTTP_OK, [
'Content-Type' => $message->contentType,
'pact_message_metadata' => \base64_encode($message->metadata),
]));
}
}
}

0 comments on commit 59d6404

Please sign in to comment.