Skip to content

Exception assertion tweaks #6425

@theofidry

Description

@theofidry

Two common use cases I encounter with the exception expectations API is:

Exact message check instead of partial

As of now expectExceptionObject() uses expectExceptionMessage() which uses the ExceptionMessageIsOrContains() constraint. It would be nice to have the option for both to make it stricter.

Ideally, we could have expectExceptionMessage() + expectExceptionMessageIsOrContains() and make the former stricter, but that's more annoying BC wise. But either way, for expectExceptionObject() this would require an additional parameter at least...

I'm a bit conflicted because I do like to use expectExceptionObject(), but if there is not choice but to use the underlying method and use expectExceptionMessageIs() or however a new method would be called, so be it.

Exact exception instance.

Sometimes it makes more sense to check that the exception thrown is the exact one previously configured:

$exception = new FancyExceptionType();

// reset of the setup

$this->expectExceptionIdentical($exception);

// act

Kinda lost at what the name should be there but that's the idea.

Metadata

Metadata

Assignees

No one assigned

    Labels

    feature/assertionIssues related to assertions and expectationstype/enhancementA new idea that should be implemented

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions