Multiple calls to expectExceptionMessage
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.
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());
}
}
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.