Add body matches function

This commit is contained in:
philipp lang 2025-04-06 16:59:50 +02:00
parent f3c7fbed50
commit bd26458041
1 changed files with 26 additions and 0 deletions

View File

@ -56,4 +56,30 @@ abstract class Fake
{
return Http::response('<html></html>');
}
public function assertBodyMatches(string $is, array|callable $should): bool
{
$requestBody = json_decode($is, true);
if (!is_array($requestBody)) {
return false;
}
if (is_callable($should)) {
return $should($requestBody);
}
foreach ($should as $key => $value) {
if (!array_key_exists($key, $requestBody)) {
return false;
}
if ($requestBody[$key] !== $value) {
return false;
}
}
return true;
}
}