vivek
vivek

Reputation: 147

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

Upvotes: 5

Views: 1451

Answers (1)

Alister Bulman
Alister Bulman

Reputation: 35169

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

Upvotes: 1

Related Questions