Skip to content

Commit

Permalink
Fix error on resource assertion if message has a second placeholder (
Browse files Browse the repository at this point in the history
  • Loading branch information
cs278 authored Oct 16, 2024
1 parent 11d902c commit 306905c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/Assert.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
));
}

Expand Down
8 changes: 8 additions & 0 deletions tests/AssertTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
}

/**
Expand Down

0 comments on commit 306905c

Please sign in to comment.