diff --git a/src/Fakes/Fake.php b/src/Fakes/Fake.php index a3395d5..91af1d4 100644 --- a/src/Fakes/Fake.php +++ b/src/Fakes/Fake.php @@ -56,4 +56,30 @@ abstract class Fake { return Http::response(''); } + + 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; + } + }