Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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) ]

like image 349
vivek Avatar asked Nov 19 '22 10:11

vivek


1 Answers

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/'.

like image 107
Alister Bulman Avatar answered Mar 23 '23 12:03

Alister Bulman