Make 'toHaveKeys' accept multi-dimensional associative arrays

This commit is contained in:
Francescu Garoby
2022-04-29 09:54:12 +02:00
parent 6e120d60f6
commit 77b7181b08
4 changed files with 49 additions and 6 deletions

View File

@ -595,14 +595,18 @@ final class Expectation
/**
* Asserts that the value array has the provided $keys.
*
* @param array<int, int|string> $keys
* @param array<int, int|string|array> $keys
*
* @return Expectation<TValue>
*/
public function toHaveKeys(array $keys): Expectation
{
foreach ($keys as $key) {
$this->toHaveKey($key);
foreach ($keys as $k => $key) {
if (is_array($key)) {
$this->toHaveKeys(array_keys(Arr::dot($key, $k . '.')));
} else {
$this->toHaveKey($key);
}
}
return $this;