diff --git a/src/Expectations/OppositeExpectation.php b/src/Expectations/OppositeExpectation.php index 9a8cf14a..a1018239 100644 --- a/src/Expectations/OppositeExpectation.php +++ b/src/Expectations/OppositeExpectation.php @@ -48,12 +48,14 @@ final readonly class OppositeExpectation public function toHaveKeys(array $keys): Expectation { foreach ($keys as $k => $key) { + if (is_array($key)) { + $this->toHaveKeys(array_keys(Arr::dot($key, $k.'.'))); + + continue; + } + try { - if (is_array($key)) { - $this->toHaveKeys(array_keys(Arr::dot($key, $k.'.'))); - } else { - $this->original->toHaveKey($key); - } + $this->original->toHaveKey($key); } catch (ExpectationFailedException) { continue; } diff --git a/tests/.snapshots/success.txt b/tests/.snapshots/success.txt index 06b35572..8ff50fc4 100644 --- a/tests/.snapshots/success.txt +++ b/tests/.snapshots/success.txt @@ -1021,6 +1021,8 @@ ✓ failures with multi-dimensional arrays and custom message ✓ not failures ✓ not failures with multi-dimensional arrays + ✓ not pass with multi-dimensional arrays + ✓ not failures with only multi-dimensional arrays PASS Tests\Features\Expect\toHaveLength ✓ it passes with ('Fortaleza') @@ -2845,4 +2847,4 @@ ✓ pass with dataset with ('my-datas-set-value') ✓ within describe → pass with dataset with ('my-datas-set-value') - Tests: 2 deprecated, 4 warnings, 5 incomplete, 2 notices, 40 todos, 44 skipped, 2111 passed (4652 assertions) + Tests: 2 deprecated, 4 warnings, 5 incomplete, 2 notices, 40 todos, 44 skipped, 2113 passed (4657 assertions) diff --git a/tests/Features/Expect/toHaveKeys.php b/tests/Features/Expect/toHaveKeys.php index 95f61460..ad0da963 100644 --- a/tests/Features/Expect/toHaveKeys.php +++ b/tests/Features/Expect/toHaveKeys.php @@ -33,3 +33,11 @@ test('not failures', function (): void { test('not failures with multi-dimensional arrays', function (): void { expect(['a' => 1, 'b', 'c' => 'world', 'foo' => ['bar' => ['bir' => 'biz']]])->not->toHaveKeys(['foo' => ['bar' => 'bir'], 'c', 'z']); })->throws(ExpectationFailedException::class); + +test('not pass with multi-dimensional arrays', function (): void { + expect(['a' => 1, 'b', 'c' => 'world', 'foo' => ['bar' => ['bir' => 'biz']]])->not->toHaveKeys(['foo' => ['bar' => ['baz']], 'z']); +}); + +test('not failures with only multi-dimensional arrays', function (): void { + expect(['a' => 1, 'b', 'c' => 'world', 'foo' => ['bar' => ['bir' => 'biz']]])->not->toHaveKeys(['foo' => ['bar' => ['bir']]]); +})->throws(ExpectationFailedException::class); diff --git a/tests/Visual/Parallel.php b/tests/Visual/Parallel.php index ad31332e..f7c2e4c4 100644 --- a/tests/Visual/Parallel.php +++ b/tests/Visual/Parallel.php @@ -21,7 +21,7 @@ test('parallel', function () use ($run): void { $output = implode("\n", array_slice(explode("\n", (string) $output), -10)); $profileOutput = $run('tests/Fixtures/Suites/SuccessOnly.php', '--profile'); - $expected = '2 deprecated, 4 warnings, 5 incomplete, 3 notices, 40 todos, 36 skipped, 1980 passed (4122 assertions)'; + $expected = '2 deprecated, 4 warnings, 5 incomplete, 3 notices, 40 todos, 36 skipped, 1982 passed (4127 assertions)'; expect($output) ->toContain("Tests: {$expected}")