From 54ae58f62c551a1c73498b053bd11697aac16abe Mon Sep 17 00:00:00 2001 From: Sebastian Bergmann Date: Thu, 12 Dec 2024 07:30:58 +0100 Subject: [PATCH] Closes #6082 --- ChangeLog-10.5.md | 7 +++++++ src/Framework/Assert.php | 6 +++--- src/Framework/Assert/Functions.php | 6 +++--- src/Framework/Constraint/Traversable/ArrayHasKey.php | 4 ++-- 4 files changed, 15 insertions(+), 8 deletions(-) diff --git a/ChangeLog-10.5.md b/ChangeLog-10.5.md index 074337bf29d..862d1370d17 100644 --- a/ChangeLog-10.5.md +++ b/ChangeLog-10.5.md @@ -2,6 +2,12 @@ All notable changes of the PHPUnit 10.5 release series are documented in this file using the [Keep a CHANGELOG](https://keepachangelog.com/) principles. +## [10.5.40] - 2024-MM-DD + +### Fixed + +* [#6082](https://github.com/sebastianbergmann/phpunit/issues/6082): `assertArrayHasKey()`, `assertArrayNotHasKey()`, `arrayHasKey()`, and `ArrayHasKey::__construct()` do not support all possible key types + ## [10.5.39] - 2024-12-11 ### Added @@ -356,6 +362,7 @@ All notable changes of the PHPUnit 10.5 release series are documented in this fi * [#5563](https://github.com/sebastianbergmann/phpunit/issues/5563): `createMockForIntersectionOfInterfaces()` does not automatically register mock object for expectation verification +[10.5.40]: https://github.com/sebastianbergmann/phpunit/compare/10.5.39...10.5 [10.5.39]: https://github.com/sebastianbergmann/phpunit/compare/10.5.38...10.5.39 [10.5.38]: https://github.com/sebastianbergmann/phpunit/compare/10.5.37...10.5.38 [10.5.37]: https://github.com/sebastianbergmann/phpunit/compare/10.5.36...10.5.37 diff --git a/src/Framework/Assert.php b/src/Framework/Assert.php index 6694fb6c024..dd248772d97 100644 --- a/src/Framework/Assert.php +++ b/src/Framework/Assert.php @@ -78,7 +78,7 @@ abstract class Assert * @throws Exception * @throws ExpectationFailedException */ - final public static function assertArrayHasKey(int|string $key, array|ArrayAccess $array, string $message = ''): void + final public static function assertArrayHasKey(mixed $key, array|ArrayAccess $array, string $message = ''): void { $constraint = new ArrayHasKey($key); @@ -91,7 +91,7 @@ final public static function assertArrayHasKey(int|string $key, array|ArrayAcces * @throws Exception * @throws ExpectationFailedException */ - final public static function assertArrayNotHasKey(int|string $key, array|ArrayAccess $array, string $message = ''): void + final public static function assertArrayNotHasKey(mixed $key, array|ArrayAccess $array, string $message = ''): void { $constraint = new LogicalNot( new ArrayHasKey($key), @@ -2120,7 +2120,7 @@ final public static function containsOnlyInstancesOf(string $className): Travers return new TraversableContainsOnly($className, false); } - final public static function arrayHasKey(int|string $key): ArrayHasKey + final public static function arrayHasKey(mixed $key): ArrayHasKey { return new ArrayHasKey($key); } diff --git a/src/Framework/Assert/Functions.php b/src/Framework/Assert/Functions.php index cc26cee513c..41e9c32a6ad 100644 --- a/src/Framework/Assert/Functions.php +++ b/src/Framework/Assert/Functions.php @@ -80,7 +80,7 @@ * * @see Assert::assertArrayHasKey */ - function assertArrayHasKey(int|string $key, array|ArrayAccess $array, string $message = ''): void + function assertArrayHasKey(mixed $key, array|ArrayAccess $array, string $message = ''): void { Assert::assertArrayHasKey(...func_get_args()); } @@ -97,7 +97,7 @@ function assertArrayHasKey(int|string $key, array|ArrayAccess $array, string $me * * @see Assert::assertArrayNotHasKey */ - function assertArrayNotHasKey(int|string $key, array|ArrayAccess $array, string $message = ''): void + function assertArrayNotHasKey(mixed $key, array|ArrayAccess $array, string $message = ''): void { Assert::assertArrayNotHasKey(...func_get_args()); } @@ -2379,7 +2379,7 @@ function containsOnlyInstancesOf(string $className): TraversableContainsOnly } if (!function_exists('PHPUnit\Framework\arrayHasKey')) { - function arrayHasKey(int|string $key): ArrayHasKey + function arrayHasKey(mixed $key): ArrayHasKey { return Assert::arrayHasKey(...func_get_args()); } diff --git a/src/Framework/Constraint/Traversable/ArrayHasKey.php b/src/Framework/Constraint/Traversable/ArrayHasKey.php index 07bfa4fd734..db8251e1725 100644 --- a/src/Framework/Constraint/Traversable/ArrayHasKey.php +++ b/src/Framework/Constraint/Traversable/ArrayHasKey.php @@ -19,9 +19,9 @@ */ final class ArrayHasKey extends Constraint { - private readonly int|string $key; + private readonly mixed $key; - public function __construct(int|string $key) + public function __construct(mixed $key) { $this->key = $key; }