Request Object Changes in Lumen 5.4

Request Object Changes in Lumen 5.4

A couple of weeks ago the Lumen core team managed to fix an issue with the request object when being called in unit tests, before the fix the request appears to be empty and all input data were not present in unit tests.

The problem was related to how Lumen is bootstrapped, simply put, the request was being instantiated as a Singleton too early in the bootstrap sequence. Creating requests in unit tests won’t be able to modify the request object since it’s already instantiated as a Singleton, and that’s why we were unable to reconstruct it for unit tests.

To solve the issue we deferred creating the request instance until the application starts dispatching the request to the router, this is the same approach Laravel follows while bootstrapping.

The issue with this change is that Lumen users will not be able to use the request instance in your Service Providers anymore. That’s because by the time Lumen registers the providers the request object isn’t instantiated yet.

The alternative solution is to copy whatever code you put in your Service Providers that uses the request object, and move it to a global middleware; the middleware will run directly after the request is captured.

Filed in: News / Lumen


Join the weekly newsletter and never miss out on new tips, tutorials, and more.

Laravel News Partners

Laravel Jobs

Senior PHP/Laravel Developer: Your Dream Work Environment
iPhone Photography School
In-house Laravel Developer.
Gold Coast / Australia
Laravel Developer
Oak Brook, IL
Tidal Commerce
Senior Backend Engineer
Santa Monica only
Saatchi Art
Senior Laravel Developer
San Francisco
Stitch Labs
Senior Software Developer
South Jordan, UT
Full-Stack Developer
Paris, France