One thing I learned to love with Docker was the easy ability to run phpunit with the exact same environment that will be used in production. Whenever I'm setting up a release pipeline, I like to build a Docker image, start a container from that image, enter it and run the project test code.
Yes, if one of my dev dependencies is not actually a dev dependency things can still break.
But the point is to minimize, as much as possible, the difference between production and the test environment.
Bref comes with a handy Docker image for tests which we can find at https://hub.docker.com/r/bref/php-74.