Does Laravel automatically load .env.testing variables when Http::fake() is active?
27.9K reputation · 17 Nov 2020, 21:38 UTC
When testing Laravel applications that call external APIs, developers often use Http::fake() to stub outbound requests and avoid sending real calls or exposing production credentials. The goal is to confirm that the test suite uses only the credentials defined in .env.testing while Http::fake() is active, ensuring no accidental use of live keys.
However, it is unclear whether Laravel automatically loads the .env.testing environment file when Http::fake() is invoked, or whether the application continues to rely on the existing configuration cache and may inadvertently read production values unless the developer manually overrides the relevant config entries.
Should developers rely on Laravel to automatically load .env.testing variables when Http::fake() is active, or must they explicitly override configuration values to guarantee test-only credentials are used?