mirror of
https://github.com/pestphp/pest.git
synced 2026-03-07 00:07:22 +01:00
Make 'toHaveKeys' accept multi-dimensional associative arrays
This commit is contained in:
@ -5,6 +5,7 @@ declare(strict_types=1);
|
||||
namespace Pest\Expectations;
|
||||
|
||||
use Pest\Expectation;
|
||||
use Pest\Support\Arr;
|
||||
use PHPUnit\Framework\ExpectationFailedException;
|
||||
use SebastianBergmann\Exporter\Exporter;
|
||||
|
||||
@ -29,15 +30,19 @@ final class OppositeExpectation
|
||||
/**
|
||||
* Asserts that the value array not 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) {
|
||||
foreach ($keys as $k => $key) {
|
||||
try {
|
||||
$this->original->toHaveKey($key);
|
||||
if (is_array($key)) {
|
||||
$this->toHaveKeys(array_keys(Arr::dot($key, $k . '.')));
|
||||
} else {
|
||||
$this->original->toHaveKey($key);
|
||||
}
|
||||
} catch (ExpectationFailedException) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user