May Sale! All accounts are 40% off this week.

suteam's avatar
Level 1

Check multiple exception message

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.

1 like
4 replies
tykus's avatar

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?

What problem are you trying to solve?

suteam's avatar
Level 1

@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!

1 like

Please or to participate in this conversation.