Hello, actually I had same questions. You can't just pass object of Closure type (and see if __invoke is called) as argument to spec method because it's final. So I ended up with this
https://gist.github.com/usernam3/78cfb1a7f97b583fe2fd
I don't know if it is only possible solution, or is it good. But it solves problem and you can actually track if next middleware is called.
It's also possible to just pass a return value and assert against it.
...
{
public function setUp()
{
parent::setUp();
$this->request = m::mock(\Illuminate\Http\Request::class);
$this->closure = (function() {return 'next';}); // Here's our Closure
}
public function test_closure()
{
// Mock additional calls as needed (like Auth)
$authenticate = new \App\Http\Middleware\Authenticate();
$this->assertEquals('next', $authenticate->handle($this->request, $this->closure));
}
}
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community