master

laravel/framework

Last updated at: 29/12/2023 09:23

WithoutMiddleware.php

TLDR

This file contains a trait called WithoutMiddleware which provides a method disableMiddlewareForAllTests to disable all middleware execution for a test class.

Methods

disableMiddlewareForAllTests

This method is used to prevent all middleware from being executed for the test class.

If the class that uses this trait has a method named withoutMiddleware, this method will be called to disable middleware. If the class does not have the withoutMiddleware method, an exception will be thrown with the message "Unable to disable middleware. MakesHttpRequests trait not used."

##Classes None

<?php

namespace Illuminate\Foundation\Testing;

use Exception;

trait WithoutMiddleware
{
    /**
     * Prevent all middleware from being executed for this test class.
     *
     * @throws \Exception
     */
    public function disableMiddlewareForAllTests()
    {
        if (method_exists($this, 'withoutMiddleware')) {
            $this->withoutMiddleware();
        } else {
            throw new Exception('Unable to disable middleware. MakesHttpRequests trait not used.');
        }
    }
}