Hi, I have this test where I want to check with two exception message.
I have this test, but I am not sure how to extend!
/** @test */
public function it_throws_exception(): void
{
$this->expectException(ModelNotFoundException::class);
$this->expectException('Message A');
// Now my validation will through a seprate exception also with a message
// e.g.
// Message B
Post::create([
// some data
]);
}
Any suggestion will be really helpful. Thanks in advance.
Not sure what you're trying to achieve here. Why do you expect ModelNotFoundException; what action are you taking that should throw that? What does it mean validation will go through a separate exception; again, what action is being taken to throw it?
@tykus correct, I have a wired code where I don't allow to change them. Therefore I am write following the code to write the test only. I am fully agree with you that there is no sense to have multiple error message for that. But it's kind of exam for me to follow!