I noticed that when my laptop is connected to the Internet, my PHPUnit tests take from ~ 90 seconds to 200 seconds to the end. But when I disconnect it from the Internet, it works in less than 20 seconds! it makes me happy and sad at the same time!
In both cases, all tests pass, I am sure that I mock every request of external APIs.
I use Laravel and MySQL for real data storage and sqlite in memory for the testing environment. My development environment also runs on Docker.
This has something to do with PHPUnit or my code! anyone has an idea of what's going on. Thanks
Additional Information
My domain is something.dev
, and my API uses api.something.dev
. Each test makes at least one call for each API endpoint.
DNS! If you think this is related to DNS lookups: I completely changed the entire domain and subdomains to 127.0.0.1 to check it, and this did not help the tests still slow. If this removes the DNS lookup feature!
Also, I tried to mock DNS using PHPUnit Bridge with PHPUnit, but I think I couldn’t get it to work due to a lack so I didn’t know what to pass as the parameter to DnsMock::withMockedHosts([here!!])
after calling it from my setUp()
function.
Something else I think the problem is with data storage, since the delay occurs before and after the database query, mainly for data storage.
source share