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

Multiple calls to expectExceptionMessage #6020

Open
Seldaek opened this issue Oct 31, 2024 · 2 comments
Open

Multiple calls to expectExceptionMessage #6020

Seldaek opened this issue Oct 31, 2024 · 2 comments
Labels
type/enhancement A new idea that should be implemented

Comments

@Seldaek
Copy link
Contributor

Seldaek commented Oct 31, 2024

I have a long exception message which has a lot of garbage in, but a few elements I want to check the presence of.

So I figured I'd call self::expectExceptionMessage() several times to assert these elements, however it seems that only the last call takes effect. That makes sense as that method just sets the expectedExceptionMessage property, but I thought it might be nice if it would collect a list of assertions to make instead of just overwrite.

Anyway as a workaround to make two assertions I now have expectExceptionMessage + expectExceptionMessageMatches, as both are preserved and checked.

@Seldaek Seldaek added the type/enhancement A new idea that should be implemented label Oct 31, 2024
@staabm
Copy link
Contributor

staabm commented Oct 31, 2024

with the current means you could do something like

public function testMultipleMessages(): void {
	try {
	  $foo->doFoo();
      $this->fail('expected exception not thrown');
	} catch (MyException $e) {
	  $this->assertContains('string1', $e->getMessage());
	  $this->assertContains('another string', $e->getMessage());
	  $this->assertContains('a 3rd string', $e->getMessage());
	}
}

@Seldaek
Copy link
Contributor Author

Seldaek commented Oct 31, 2024

Right that'd have been my next option if I had to but I figured it could be nice if PHPUnit accepted multiple, or if not maybe it should throw if something is set already because it's kinda swallowing assertions silently right now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/enhancement A new idea that should be implemented
Projects
None yet
Development

No branches or pull requests

2 participants