Mike-e's avatar

[Unit Test - 5.1] How to disable middlewares

Hi,

In Laravel 5.1, we can disable middleware with WithoutMiddleware trait for all unit tests or with withoutMiddleware() method for single unit test.

But in Lumen 5.1, this trait does not exists and the withoutMiddleware() method exists but doesn't work.

Someone know how i can achieve this ?

Thanks. Regards.

0 likes
3 replies
JohnRivs's avatar

There's not a WithoutMiddleware trait because withoutMiddleware() doesn't exist in Laravel\Lumen\Testing\TestCase, and the trait is just a shortcut for calling said method.

Also, there's not a withoutMiddleware() method because there's no Illuminate\Foundation\Testing\CrawlerTrait when you use Lumen, which is the trait responsible for importing said method.

Try this in a setUp method:

$this->app->instance('middleware.disable', true);
1 like
Mike-e's avatar

Hi @JohnRivs,

You are wrong, the withoutMiddleware() method exists in CrailerTrait which it used in Laravel\Lumen\Testing\TestCase :

abstract class TestCase extends PHPUnit_Framework_TestCase
{
        use ApplicationTrait, AssertionsTrait, CrawlerTrait;
    // ...
}
JohnRivs's avatar

I was reading the TestCase class in test/, didn't notice.

Then why can't you use the method that it provides?

withoutMiddleware() method exists but doesn't work

Could you elaborate on that? Any error?

Please or to participate in this conversation.