2017-11-01 20:45:43 -05:00
|
|
|
<?php
|
|
|
|
|
|
2024-03-12 22:39:16 -04:00
|
|
|
namespace App\Tests\Traits\Http;
|
2017-11-01 20:45:43 -05:00
|
|
|
|
|
|
|
|
use Closure;
|
|
|
|
|
use Illuminate\Http\Request;
|
|
|
|
|
|
|
|
|
|
trait MocksMiddlewareClosure
|
|
|
|
|
{
|
|
|
|
|
/**
|
|
|
|
|
* Provide a closure to be used when validating that the response from the middleware
|
|
|
|
|
* is the same request object we passed into it.
|
|
|
|
|
*/
|
2026-03-17 09:09:01 +01:00
|
|
|
protected function getClosureAssertions(): Closure
|
2017-11-01 20:45:43 -05:00
|
|
|
{
|
|
|
|
|
if (is_null($this->request)) {
|
2023-02-23 12:30:16 -07:00
|
|
|
throw new \BadFunctionCallException('Calling getClosureAssertions without defining a request object is not supported.');
|
2017-11-01 20:45:43 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return function ($response) {
|
|
|
|
|
$this->assertInstanceOf(Request::class, $response);
|
|
|
|
|
$this->assertSame($this->request, $response);
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|