Http client and cURL ignores app_env during tests #54297
Unanswered
AlexKreatos
asked this question in
Q&A
Replies: 1 comment 1 reply
-
When you call |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Laravel Version
11.38.2
PHP Version
8.2.26
Database Driver & Version
No response
Description
I have a laravel API. I am trying to call itself using cURL or the Http client.
For context I have two databases. A normal one and a testing one. Both have their respective .env files to connect to the correct one.
To authenticate you need to request an init token using a store_id and an api_token. Both databases have a stores table that are identical except for the api_token fields.
My phpunit.xml file has the
<env name="APP_ENV" value="testing"/>
line and I run the command withphp artisan test --testsuite=Unit --env=testing
Example of normal call
This returns the expected response with the correct init token to make other calls. However when I try to make the same call using cURL or the Http client
this returns a stack trace with "message" => "Invalid api token". When I switch the api key from the testing database to the normal one I get the expected response. Dumping
env('DB_DATABASE')
,DB::connection()->getDatabaseName()
andconfig('database.connections.' . config('database.default') . '.database')
in the same test all return the testing database. This tells me the tests/application recognizes the correct .env.testing file but the Http client or cURL ignores it and uses the default .env file. I have cleared all caches.Im pretty sure this has worked in the past since all my previous tests used cURL to connect to the api (itself) and they all passed. I am not sure if I am getting late onset schizophrenia at this point.
Steps To Reproduce
Beta Was this translation helpful? Give feedback.
All reactions