How do I test for an exact Exception message, rather than a substring, with PHPUnit?

后端 未结 6 1722
难免孤独
难免孤独 2021-01-12 07:14

According to the PHPUnit Documentation on @expectedExceptionMessage, the string must only be a substring of the actual Exception thrown.

In

6条回答
  •  失恋的感觉
    2021-01-12 07:22

    You can use $this->expectExceptionMessage to handle this.

    Example:

    $this->expectException(InvalidArgumentException::class);
    $this->expectExceptionMessage = "Some error message";
    

提交回复
热议问题