DEV Community

Discussion on: Laravel Test Driven Development

Collapse
 
rolandhesz profile image
Roland Hesz • Edited

Just a brief addition:
With Laravel 7.10.4
$this->withoutExceptionHandling();
results in Error: Call to undefined method Tests\Unit\ControllerTest::withoutExceptionHandling()

If you try the below (apparently the way to do it in Laravel 6):

use Illuminate\Foundation\Testing\Concerns\InteractsWithExceptionHandling;

class testClass () {
use InteractsWithExceptionHandling;
public function testFunction() {
$this->withoutExceptionHandling();
....

you will get the error:
Illuminate\Contracts\Container\BindingResolutionException: Target [Illuminate\Contracts\Debug\ExceptionHandler] is not instantiable.

Any idea how to get the real exceptions with Laravel 7?

Collapse
 
avsecdongol profile image
Abishek Dongol

I think cross test conflict may be the reason. Have you tried composer dump-autoload and still same error persist you can run the full test suite using the --process-isolation flag.

Collapse
 
rolandhesz profile image
Roland Hesz

Still, I put your advice away in my "things to know" folder, probably will come handy at some point.

Collapse
 
rolandhesz profile image
Roland Hesz

Hi, in the meantime I found out the issue.
It's a really silly thing, but no tutorial ever explains that while we use PHPUnit for testing, the tests should NOT extend the PHPUnit TestCase class but the one provided by Laravel (\Tests\TestCase).

For some reason, that small, but extremely important piece of information is never mentioned in the articles, Youtube videos, etc. I have seen. That's something people are expected to know.

I didn't. That was the issue. ¯_(ツ)_/¯

Thread Thread
 
jonjieviduya profile image
Jonjie Viduya

@rolandhesz That actually works for me. Not sure why