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

Make ExceptionMessage constraint strict #3325

Closed
keradus opened this issue Oct 5, 2018 · 15 comments
Closed

Make ExceptionMessage constraint strict #3325

keradus opened this issue Oct 5, 2018 · 15 comments

Comments

@keradus
Copy link
Contributor

keradus commented Oct 5, 2018

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

Heavily descried in:
#3309 (comment)

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 !

@keradus
Copy link
Contributor Author

keradus commented Oct 5, 2018

fyi @TomasVotruba

@sebastianbergmann
Copy link
Owner

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).

@pscheit
Copy link
Contributor

pscheit commented Oct 9, 2018

My 2 cents: this makes the (already screwed up) exception api so much more worse...
now I have to write a regexp for every "contains" check of my exception message?
Why would I want to test thee FULL assertion message in exceptions? Someone corrects a typo and the tests will fail.

at least add something like:
expectedExceptionMessageContains() or s.th.

@pscheit
Copy link
Contributor

pscheit commented Oct 9, 2018

imho this is a BC break and must not go to branch 6.5.x-dev right?

@TomasVotruba
Copy link

TomasVotruba commented Oct 9, 2018

@pscheit
Copy link
Contributor

pscheit commented Oct 10, 2018

I don't want to use annotations and still: i need to write a regexp for "contains". I'm just saying: this issue will decrease developer experience

@TomasVotruba
Copy link

I don't use annotations neither, as they're not recommended.

There is method:

public function test()
{
    $this->expectExceptionMessageRegExp('...');
    // ...
}

But still I prefer specific 100% exception match. Otherwise it has no value to test that exception contains some text.

@sebastianbergmann
Copy link
Owner

I have reverted the change(s) in the 6.5 branch.

@sebastianbergmann
Copy link
Owner

I decided to deprecate expecting exceptions through annotations in PHPUnit 8 and remove the annotations in PHPUnit 9.

@stale
Copy link

stale bot commented Dec 9, 2018

This issue has been automatically marked as stale because it has not had activity within the last 60 days. It will be closed after 7 days if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Dec 9, 2018
@keradus
Copy link
Contributor Author

keradus commented Dec 9, 2018

stale, go away
request for Constraint\ExceptionMessage is still valid

@stale stale bot removed the stale label Dec 9, 2018
@epdenouden
Copy link
Contributor

And stale bread is still good for croutons or bread pudding :D

@sebastianbergmann
Copy link
Owner

As I wrote in #3325 (comment), support for expecting exceptions through annotations will be removed in PHPUnit 9 (see #3332 and #3333). I am not sure how to properly address this before the annotation is issue is gone.

@stale
Copy link

stale bot commented Mar 5, 2019

This issue has been automatically marked as stale because it has not had activity within the last 60 days. It will be closed after 7 days if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Mar 5, 2019
@stale
Copy link

stale bot commented Mar 12, 2019

This issue has been automatically closed because it has not had activity since it was marked as stale. Thank you for your contributions.

@stale stale bot closed this as completed Mar 12, 2019
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

No branches or pull requests

5 participants