Add body matches function
This commit is contained in:
parent
f3c7fbed50
commit
bd26458041
|
@ -56,4 +56,30 @@ abstract class Fake
|
||||||
{
|
{
|
||||||
return Http::response('<html></html>');
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue