diff --git a/lib/Assert/Assertion.php b/lib/Assert/Assertion.php index 81bc978..cfdc63b 100644 --- a/lib/Assert/Assertion.php +++ b/lib/Assert/Assertion.php @@ -1950,6 +1950,8 @@ public static function implementsInterface($class, $interfaceName, $message = nu */ public static function isJsonString($value, $message = null, ?string $propertyPath = null): bool { + static::string($value, $message, $propertyPath); + if (null === \json_decode($value) && JSON_ERROR_NONE !== \json_last_error()) { $message = \sprintf( static::generateMessage($message ?: 'Value "%s" is not a valid JSON string.'), diff --git a/tests/Assert/Tests/AssertTest.php b/tests/Assert/Tests/AssertTest.php index 849d644..21ce828 100644 --- a/tests/Assert/Tests/AssertTest.php +++ b/tests/Assert/Tests/AssertTest.php @@ -1224,6 +1224,13 @@ public function isJsonStringInvalidStringDataprovider(): array ]; } + public function testIsJsonStringNotString() + { + $this->expectException('Assert\AssertionFailedException'); + $this->expectExceptionCode(\Assert\Assertion::INVALID_STRING); + Assertion::isJsonString(4); + } + /** * @dataProvider providesValidUuids *