pestphp / pest

Pest is an elegant PHP testing Framework with a focus on simplicity, meticulously designed to bring back the joy of testing in PHP.
https://pestphp.com
MIT License
9.07k stars 315 forks source link

Missing expectation: expectWarning()? #1102

Open withinboredom opened 4 months ago

withinboredom commented 4 months ago

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.