Scenario
When writing feature tests, you sometimes need to fake $_SERVER variables – for example, changing REMOTE_ADDR to test IP-related logic.
How To
Laravel’s test methods natively support passing server variables.
GET Requests
The second parameter is for server variables:
| |
POST Requests
The third parameter is for server variables (the second is the request body):
| |
Shared Across an Entire Test
If you don’t want to pass them on every request, use withServerVariables() to set them once:
| |
All subsequent requests within the same test method will use these values.
