diff --git a/src/Assert.php b/src/Assert.php index cbf8ed8..7058112 100644 --- a/src/Assert.php +++ b/src/Assert.php @@ -266,7 +266,8 @@ public static function resource($value, $type = null, $message = '') if (!\is_resource($value)) { static::reportInvalidArgument(\sprintf( $message ?: 'Expected a resource. Got: %s', - static::typeToString($value) + static::typeToString($value), + $type // User supplied message might include the second placeholder. )); } diff --git a/tests/AssertTest.php b/tests/AssertTest.php index f094d79..b95eba1 100644 --- a/tests/AssertTest.php +++ b/tests/AssertTest.php @@ -820,6 +820,14 @@ public function testIsAOfExceptionMessages(array $args, string $exceptionMessage call_user_func_array(array('Webmozart\Assert\Assert', 'isAOf'), $args); } + + public function testResourceOfTypeCustomMessage(): void + { + $this->expectException('\InvalidArgumentException'); + $this->expectExceptionMessage('I want a resource of type curl. Got: NULL'); + + Assert::resource(null, 'curl', 'I want a resource of type %2$s. Got: %s'); + } } /**