Skip to content

Commit b39f187

Browse files
authored
Use custom message for object checks (#348)
1 parent 6976757 commit b39f187

3 files changed

Lines changed: 36 additions & 5 deletions

File tree

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
Changelog
22
=========
33

4+
## 2.1.4
5+
6+
### Fixed
7+
8+
- Use custom message for more internal calls
9+
410
## 2.1.3
511

612
### Fixed

src/Assert.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,7 @@ public static function isIterable(mixed $value, string $message = ''): iterable
484484
*/
485485
public static function isInstanceOf(mixed $value, mixed $class, string $message = ''): object
486486
{
487-
static::object($value);
487+
static::object($value, $message);
488488
static::string($class, 'Expected class as a string. Got: %s');
489489

490490
if (!($value instanceof $class)) {
@@ -510,7 +510,7 @@ public static function isInstanceOf(mixed $value, mixed $class, string $message
510510
*/
511511
public static function notInstanceOf(mixed $value, mixed $class, string $message = ''): object
512512
{
513-
static::object($value);
513+
static::object($value, $message);
514514
static::string($class, 'Expected class as a string. Got: %s');
515515

516516
if ($value instanceof $class) {
@@ -537,7 +537,7 @@ public static function notInstanceOf(mixed $value, mixed $class, string $message
537537
*/
538538
public static function isInstanceOfAny(mixed $value, mixed $classes, string $message = ''): object
539539
{
540-
static::object($value);
540+
static::object($value, $message);
541541
static::isIterable($classes);
542542

543543
foreach ($classes as $class) {
@@ -596,7 +596,7 @@ public static function isAOf(mixed $value, mixed $class, string $message = ''):
596596
*/
597597
public static function isNotA(mixed $value, mixed $class, string $message = ''): object|string
598598
{
599-
static::objectish($value);
599+
static::objectish($value, $message);
600600
static::string($class, 'Expected class as a string. Got: %s');
601601

602602
if (\is_a($value, $class, \is_string($value))) {
@@ -621,7 +621,7 @@ public static function isNotA(mixed $value, mixed $class, string $message = ''):
621621
*/
622622
public static function isAnyOf(mixed $value, mixed $classes, string $message = ''): object|string
623623
{
624-
static::objectish($value);
624+
static::objectish($value, $message);
625625
static::isIterable($classes);
626626

627627
foreach ($classes as $class) {

tests/AssertTest.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -943,6 +943,31 @@ public static function getMethodsThatUseOtherMethods(): array
943943
'args' => [111, 'test', 'Value must be an array without key test. Got: %s'],
944944
'exceptionMessage' => 'Value must be an array without key test. Got: integer',
945945
],
946+
[
947+
'method' => 'isInstanceOf',
948+
'args' => [111, 'stdClass', 'Value must be an instance of stdClass. Got: %s'],
949+
'exceptionMessage' => 'Value must be an instance of stdClass. Got: integer',
950+
],
951+
[
952+
'method' => 'notInstanceOf',
953+
'args' => [111, 'stdClass', 'Value must be an instance of stdClass. Got: %s'],
954+
'exceptionMessage' => 'Value must be an instance of stdClass. Got: integer',
955+
],
956+
[
957+
'method' => 'isInstanceOfAny',
958+
'args' => [111, 'stdClass', 'Value must be an instance of stdClass. Got: %s'],
959+
'exceptionMessage' => 'Value must be an instance of stdClass. Got: integer',
960+
],
961+
[
962+
'method' => 'isNotA',
963+
'args' => [111, 'stdClass', 'Value must be an instance of stdClass. Got: %s'],
964+
'exceptionMessage' => 'Value must be an instance of stdClass. Got: integer',
965+
],
966+
[
967+
'method' => 'isAnyOf',
968+
'args' => [111, 'stdClass', 'Value must be an instance of stdClass. Got: %s'],
969+
'exceptionMessage' => 'Value must be an instance of stdClass. Got: integer',
970+
],
946971
];
947972
}
948973
}

0 commit comments

Comments
 (0)