Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

TJ Miller:
An Approach to Testing Middleware
Nov 29, 2017 @ 15:06:19

TJ Miller has posted an article where he shares some suggestions about testing middleware in your applications. Since middleware is usually only executed as a part of the normal request/response cycle it is difficult to test in isolation.

I’ve always tested middleware in one of two ways, a unit test with mocks and asserting the callback in the handle method or integration tests on application routes.

[...] I wanted to find a simple approach that verified the following: middleware is active and configured correctly (global, group, single use) [and that the] middleware is functioning correctly

He briefly discusses the difference between unit testing and integration testing before showing how to set up unit tests for a Laravel-based middleware: a check for a JSON response, testing to ensure logging is working as expected and that a middleware is correctly assigned to a route.

tagged: testing unittest integration middleware laravel tutorial

Link: https://medium.com/@sixlive/an-approach-to-testing-middleware-c547fc942848


Trending Topics: