From ed94498963b984d87ce3784f4ddbf0d753e86927 Mon Sep 17 00:00:00 2001 From: Woody Gilk Date: Tue, 17 Feb 2026 06:00:39 -0600 Subject: [PATCH] Use custom message for object checks --- CHANGELOG.md | 6 ++++++ src/Assert.php | 10 +++++----- tests/AssertTest.php | 25 +++++++++++++++++++++++++ 3 files changed, 36 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f8092f1e..538c8463 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,12 @@ Changelog ========= +## 2.1.4 + +### Fixed + +- Use custom message for more internal calls + ## 2.1.3 ### Fixed diff --git a/src/Assert.php b/src/Assert.php index 4c5c8d37..65a45a98 100644 --- a/src/Assert.php +++ b/src/Assert.php @@ -484,7 +484,7 @@ public static function isIterable(mixed $value, string $message = ''): iterable */ public static function isInstanceOf(mixed $value, mixed $class, string $message = ''): object { - static::object($value); + static::object($value, $message); static::string($class, 'Expected class as a string. Got: %s'); if (!($value instanceof $class)) { @@ -510,7 +510,7 @@ public static function isInstanceOf(mixed $value, mixed $class, string $message */ public static function notInstanceOf(mixed $value, mixed $class, string $message = ''): object { - static::object($value); + static::object($value, $message); static::string($class, 'Expected class as a string. Got: %s'); if ($value instanceof $class) { @@ -537,7 +537,7 @@ public static function notInstanceOf(mixed $value, mixed $class, string $message */ public static function isInstanceOfAny(mixed $value, mixed $classes, string $message = ''): object { - static::object($value); + static::object($value, $message); static::isIterable($classes); foreach ($classes as $class) { @@ -596,7 +596,7 @@ public static function isAOf(mixed $value, mixed $class, string $message = ''): */ public static function isNotA(mixed $value, mixed $class, string $message = ''): object|string { - static::objectish($value); + static::objectish($value, $message); static::string($class, 'Expected class as a string. Got: %s'); if (\is_a($value, $class, \is_string($value))) { @@ -621,7 +621,7 @@ public static function isNotA(mixed $value, mixed $class, string $message = ''): */ public static function isAnyOf(mixed $value, mixed $classes, string $message = ''): object|string { - static::objectish($value); + static::objectish($value, $message); static::isIterable($classes); foreach ($classes as $class) { diff --git a/tests/AssertTest.php b/tests/AssertTest.php index 104d3936..5b3d0a39 100644 --- a/tests/AssertTest.php +++ b/tests/AssertTest.php @@ -943,6 +943,31 @@ public static function getMethodsThatUseOtherMethods(): array 'args' => [111, 'test', 'Value must be an array without key test. Got: %s'], 'exceptionMessage' => 'Value must be an array without key test. Got: integer', ], + [ + 'method' => 'isInstanceOf', + 'args' => [111, 'stdClass', 'Value must be an instance of stdClass. Got: %s'], + 'exceptionMessage' => 'Value must be an instance of stdClass. Got: integer', + ], + [ + 'method' => 'notInstanceOf', + 'args' => [111, 'stdClass', 'Value must be an instance of stdClass. Got: %s'], + 'exceptionMessage' => 'Value must be an instance of stdClass. Got: integer', + ], + [ + 'method' => 'isInstanceOfAny', + 'args' => [111, 'stdClass', 'Value must be an instance of stdClass. Got: %s'], + 'exceptionMessage' => 'Value must be an instance of stdClass. Got: integer', + ], + [ + 'method' => 'isNotA', + 'args' => [111, 'stdClass', 'Value must be an instance of stdClass. Got: %s'], + 'exceptionMessage' => 'Value must be an instance of stdClass. Got: integer', + ], + [ + 'method' => 'isAnyOf', + 'args' => [111, 'stdClass', 'Value must be an instance of stdClass. Got: %s'], + 'exceptionMessage' => 'Value must be an instance of stdClass. Got: integer', + ], ]; } }