pest icon indicating copy to clipboard operation
pest copied to clipboard

Missing expectation: expectWarning()?

Open withinboredom opened this issue 1 year ago • 1 comments

I see a nice yellow WARN:

image

But I'm explicitly expecting a warning here. My test covers this through error_get_last as a workaround; however, it would be nice to simply:

it('emits a warning', function() {
  trigger_error('warn', E_USER_WARNING);
})->expectWarningMessage('warn');

Similar to how exceptions can be checked.

I'd prefer to throw an exception in my library; however, that would be disastrous since nothing would break unless the library is used in a particular way. So, a warning is emitted so that the developer can either ignore it or choose to throw an exception if it effects them.

withinboredom avatar Feb 25 '24 12:02 withinboredom

This would be helpful to avoid warnings in our Pest output, as we have some tests which involve intentionally passing bad data to PHP's unserialize, which emits a warning. Currently there is no way to tell Pest that we expect this warning, and there is no way to tell PHP to stop emitting this warning.

I'd like to enable some of the stricter flags, such as "fail test on (unexpected) warning", but currently we must allow warnings to allow tests like these to function.

Image

maples3 avatar Jan 28 '25 22:01 maples3

you can make a pull request or just use the methods from phpujnit: https://github.com/sebastianbergmann/phpunit/issues/3775.

nunomaduro avatar Aug 03 '25 15:08 nunomaduro