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

Conversation

cs278
Copy link
Contributor

@cs278 cs278 commented Jun 13, 2024

Prior to this change code such as
Assert::resource(null, 'stream', 'Got: %s, type: %s') would fail as
the second placeholder was only passed into sprintf() if the value
supplied is a resource.

Test I've added without the code change fails with:

1) Webmozart\Assert\Tests\AssertTest::testResourceOfTypeCustomMessage
Failed asserting that exception of type "ArgumentCountError" matches expected exception "\InvalidArgumentException". Message was: "3 arguments are required, 2 given" at
<snip>/src/Assert.php:255
<snip>/tests/AssertTest.php:827

@cs278
Copy link
Contributor Author

cs278 commented Jun 13, 2024

I came to the conclusion a bespoke test was needed but I might have missed something.

Prior to this change code such as
`Assert::resource(null, 'stream', 'Got: %s, type: %s')` would fail as
the second placeholder was only passed into `sprintf()` if the value
supplied is a resource.

Test I've added without the code change fails with:

```
1) Webmozart\Assert\Tests\AssertTest::testResourceOfTypeCustomMessage
Failed asserting that exception of type "ArgumentCountError" matches expected exception "\InvalidArgumentException". Message was: "3 arguments are required, 2 given" at
<snip>/src/Assert.php:255
<snip>/tests/AssertTest.php:827
```
@cs278
Copy link
Contributor Author

cs278 commented Oct 16, 2024

Great to see some activity here again, I've rebased this to pickup the CI changes.

@shadowhand shadowhand merged commit 306905c into webmozarts:master Oct 16, 2024
11 checks passed
@shadowhand
Copy link
Collaborator

Thank you!

@cs278 cs278 deleted the fix-resource-assertion branch October 16, 2024 17:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants