fix: not->toHaveKeys() with nested keys (#2094)

This commit is contained in:
Mr PHP
2026-12-03 15:00:01 +01:00
committed by GitHub
parent 8c635c5ba0
commit edb56ae412
4 changed files with 19 additions and 7 deletions
+7 -5
View File
@@ -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;
}
+3 -1
View File
@@ -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)
+8
View File
@@ -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);
+1 -1
View File
@@ -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}")