Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

assertArrayHasKey(), assertArrayNotHasKey(), arrayHasKey(), and ArrayHasKey::__construct() do not support all possible key types #6082

Closed
vudaltsov opened this issue Dec 11, 2024 · 0 comments
Assignees
Labels
feature/assertion Issues related to assertions and expectations type/bug Something is broken version/10 Something affects PHPUnit 10 version/11 Something affects PHPUnit 11 version/12 Something affects PHPUnit 12

Comments

@vudaltsov
Copy link

ArrayAccess can use mixed keys (see https://www.php.net/manual/en/class.arrayaccess.php), however, Assert::assertArrayHasKey(), Assert::assertArrayNotHasKey() accept only int|string keys, which does not allow to test collections with object keys.

I propose to change int|string $key to mixed $key. This will not break BC, since the methods are final.

@vudaltsov vudaltsov added the type/enhancement A new idea that should be implemented label Dec 11, 2024
@sebastianbergmann sebastianbergmann changed the title Allow to pass mixed keys to assertArrayHasKey(), assertArrayNotHasKey() assertArrayHasKey(), assertArrayNotHasKey(), and ArrayHasKey::__construct() do not support all possible key types Dec 12, 2024
@sebastianbergmann sebastianbergmann self-assigned this Dec 12, 2024
@sebastianbergmann sebastianbergmann added type/bug Something is broken feature/assertion Issues related to assertions and expectations version/10 Something affects PHPUnit 10 version/11 Something affects PHPUnit 11 version/12 Something affects PHPUnit 12 and removed type/enhancement A new idea that should be implemented labels Dec 12, 2024
@sebastianbergmann sebastianbergmann changed the title assertArrayHasKey(), assertArrayNotHasKey(), and ArrayHasKey::__construct() do not support all possible key types assertArrayHasKey(), assertArrayNotHasKey(), arrayHasKey(), and ArrayHasKey::__construct() do not support all possible key types Dec 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature/assertion Issues related to assertions and expectations type/bug Something is broken version/10 Something affects PHPUnit 10 version/11 Something affects PHPUnit 11 version/12 Something affects PHPUnit 12
Projects
None yet
Development

No branches or pull requests

2 participants