phpdbg/phpunit throws error even when memory limit is -1

1.4k Views Asked by At

I have a 32GB machine and running over 2000 test cases using phpdbg for code coverage.

phpdbg -qrr -d memory_limit=-1./vendor/phpunit/phpunit/phpunit --debug --verbose

After running for some time, it throws the following error even memory_limit is -1

map() failed: [12] Cannot allocate memory [ PHP Fatal error: Out of memory (allocated 5830606848) (tried to allocate 65536 bytes) ]

1

There are 1 best solutions below

3
Alister Bulman On

You are likely leaking memory and not getting it cleaned up. There are plugins that will report how much memory each test uses, and others that will try to automatically clean up - though with the update to PHPunit v6+, some may need attention to work with the namespace testcase classes.

One that tries to free-up memory is 'mybuilder/phpunit-accelerator', but if you can find particularly memory-heavy test classes, you can manually null-out the variables being used in a teardown() function.

Making sure that you are only collecting coverage data for your own code (src/, and maybe tests/) will also save a huge amount of memory (and time) - but whitelist the 'src/' directory and don't try to blacklist/exclude 'vendor/'.