Madriesen
Madriesen

Reputation: 619

Laravel test without exception, throws exception

I want to test a missing record in the database using Laravel and PHPUnit.

I have setup my tests and set that the method throws an exception. The test gives an error, because the exception has been thrown.

This is my test:

/** @test */
    public function myTest()
    {
        $this->withoutExceptionHandling();
        $this->_createMemberRequest(['email_address' => $this->email_address]);
    }

The testresults:

There was 1 error:

1) myTest

Exceptions\InvalidEmailException: Email already exists

What am I doing wrong?

Thanks for help!

Upvotes: 1

Views: 1261

Answers (1)

VeRJiL
VeRJiL

Reputation: 564

The whole point of $this->withoutExceptionHandling(); is when you get a funky error and you dont know what to do or the error is not clear enough but if you are trying to test your form validations ('name' => 'required') or something like that when storing a request then you have to remove $this->withoutExceptionHandling(); to get your test passed.

Upvotes: 1

Related Questions