@@ -188,7 +188,9 @@ public static function getTests(): array
188188 ['isInstanceOf ' , [null , 'stdClass ' ], false ],
189189 ['notInstanceOf ' , [new stdClass (), 'stdClass ' ], false ],
190190 ['notInstanceOf ' , [new Exception (), 'stdClass ' ], true ],
191+ ['notInstanceOf ' , [123 , 'stdClass ' ], false ],
191192 ['notInstanceOf ' , [[], 'stdClass ' ], false ],
193+ ['notInstanceOf ' , [null , 'stdClass ' ], false ],
192194 ['isInstanceOfAny ' , [new ArrayIterator (), ['Iterator ' , 'ArrayAccess ' ]], true ],
193195 ['isInstanceOfAny ' , [new Exception (), ['Exception ' , 'Countable ' ]], true ],
194196 ['isInstanceOfAny ' , [new Exception (), ['ArrayAccess ' , 'Countable ' ]], false ],
@@ -803,6 +805,38 @@ public function testConvertValuesToStrings(string $method, array $args, string $
803805 call_user_func_array (['Webmozart\Assert\Assert ' , $ method ], $ args );
804806 }
805807
808+ public static function getInvalidInstanceOfCases (): iterable
809+ {
810+ yield [
811+ [null , 'stdClass ' ],
812+ 'Expected an instance of stdClass. Got: NULL ' ,
813+ ];
814+
815+ yield [
816+ [123 , 'stdClass ' ],
817+ 'Expected an instance of stdClass. Got: integer ' ,
818+ ];
819+
820+ yield [
821+ [[], 'Iterator ' ],
822+ 'Expected an instance of Iterator. Got: array ' ,
823+ ];
824+
825+ yield [
826+ [new stdClass (), 'Iterator ' ],
827+ 'Expected an instance of Iterator. Got: stdClass ' ,
828+ ];
829+ }
830+
831+ #[DataProvider('getInvalidInstanceOfCases ' )]
832+ public function testInstanceOfExceptionMessages (array $ args , string $ exceptionMessage ): void
833+ {
834+ $ this ->expectException ('\InvalidArgumentException ' );
835+ $ this ->expectExceptionMessage ($ exceptionMessage );
836+
837+ call_user_func_array (['Webmozart\Assert\Assert ' , 'isInstanceOf ' ], $ args );
838+ }
839+
806840 public static function getInvalidIsAOfCases (): iterable
807841 {
808842 yield [
@@ -955,7 +989,7 @@ public static function getMethodsThatUseOtherMethods(): array
955989 ],
956990 [
957991 'method ' => 'isInstanceOfAny ' ,
958- 'args ' => [111 , 'stdClass ' , 'Value must be an instance of stdClass. Got: %s ' ],
992+ 'args ' => [111 , [ 'stdClass ' ] , 'Value must be an instance of stdClass. Got: %s ' ],
959993 'exceptionMessage ' => 'Value must be an instance of stdClass. Got: integer ' ,
960994 ],
961995 [
@@ -965,7 +999,7 @@ public static function getMethodsThatUseOtherMethods(): array
965999 ],
9661000 [
9671001 'method ' => 'isAnyOf ' ,
968- 'args ' => [111 , 'stdClass ' , 'Value must be an instance of stdClass. Got: %s ' ],
1002+ 'args ' => [111 , [ 'stdClass ' ] , 'Value must be an instance of stdClass. Got: %s ' ],
9691003 'exceptionMessage ' => 'Value must be an instance of stdClass. Got: integer ' ,
9701004 ],
9711005 ];
0 commit comments