phpunit: Make ExceptionMessage constraint strict

Q A
PHPUnit version ?
PHP version not related
Installation Method not related

Heavily descried in: https://github.com/sebastianbergmann/phpunit/pull/3309#discussion_r219665621

Constraint\ExceptionMessage, used under the hood by expectExceptionMessage and @expectedExceptionMessage is not strict about expected message.

Constraint does not check if expected message is same as actual one, but only if it’s somewhere present in actual one. Making those two calls equivalent:

$this->expectExceptionMessage('variadic');
$this->expectExceptionMessageRegExp('/^.*variadic.*$/');

Which is not obvious for developer and actually most of them are not aware about this.

I would like to change behaviour of Constraint to use === comparison instead of strpos.

For me, personally, it’s a bug, yet I can understood that requested change may be considered as bigger one and treated as BC breaker.

If this request will be approved, I’m all in implementing this change myself - either to lowest supported branch, if this would be treated as a bugfix, or later for 8.0 branch (which is not yet existing).

Thanks !

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 1
  • Comments: 15 (10 by maintainers)

Most upvoted comments

I would consider this a bugfix, too, and would appreciate a pull request for 6.5 (which will be merged to 7.4 and master).