Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix error on resource assertion if message has a second placeholder #300

Merged
merged 1 commit into from
Oct 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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