feat: add toHaveSnakeCaseKeys

This commit is contained in:
Maurizio
2023-08-17 20:50:26 +02:00
parent 997b0e9368
commit 0b246f7a76
2 changed files with 53 additions and 0 deletions

View File

@ -740,4 +740,26 @@ final class Expectation
FileLineFinder::where(fn (string $line): bool => str_contains($line, 'class'))
);
}
/**
* Asserts that the given expectation is iterable and contains snake_case keys.
*
* @return self<TValue>
*/
public function toHaveSnakeCaseKeys(string $message = ''): self
{
if (! is_iterable($this->value)) {
InvalidExpectationValue::expected('iterable');
}
foreach ($this->value as $k => $item) {
$this->and($k)->toBeSnakeCase($message);
if (is_array($item)) {
$this->and($item)->toHaveSnakeCaseKeys($message);
}
}
return $this;
}
}