简体   繁体   中英

PHPUnit code coverage memory limit

I have a Symfony2 project with some functional tests.
When I run the test suite without code coverage enabled, there is no problem. But when I am trying to generate the code coverage I am getting a PHP Fatal error :

Generating code coverage report, this may take a moment.
PHP Fatal error:  Allowed memory size of 209715200 bytes exhausted 
(tried to allocate 79 bytes) in /usr/share/php/PHP/Token/Stream.php on line 205
PHP Stack trace:
PHP   1. {main}() /usr/bin/phpunit:0
PHP   2. PHPUnit_TextUI_Command::main() /usr/bin/phpunit:46
PHP   3. PHPUnit_TextUI_Command->run() /usr/share/php/PHPUnit/TextUI/Command.php:130
PHP   4. PHPUnit_TextUI_TestRunner->doRun() /usr/share/php/PHPUnit/TextUI/Command.php:192
PHP   5. PHP_CodeCoverage_Report_HTML->process() /usr/share/php/PHPUnit/TextUI/TestRunner.php:373
PHP   6. PHP_CodeCoverage->getReport() /usr/share/php/PHP/CodeCoverage/Report/HTML.php:133
PHP   7. PHP_CodeCoverage_Report_Factory->create() /usr/share/php/PHP/CodeCoverage.php:141
PHP   8. PHP_CodeCoverage_Report_Factory->addItems() /usr/share/php/PHP/CodeCoverage/Report/Factory.php:76
PHP   9. PHP_CodeCoverage_Report_Factory->addItems() /usr/share/php/PHP/CodeCoverage/Report/Factory.php:98
PHP  10. PHP_CodeCoverage_Report_Node_Directory->addFile() /usr/share/php/PHP/CodeCoverage/Report/Factory.php:94
PHP  11. PHP_CodeCoverage_Report_Node_File->__construct() /usr/share/php/PHP /CodeCoverage/Report/Node/Directory.php:211
PHP  12. PHP_CodeCoverage_Util::getLinesToBeIgnored() /usr/share/php/PHP/CodeCoverage/Report/Node/File.php:166
PHP  13. PHP_Token_Stream_CachingFactory::get() /usr/share/php/PHP/CodeCoverage/Util.php:254
PHP  14. PHP_Token_Stream->__construct() /usr/share/php/PHP/Token/Stream/CachingFactory.php:68
PHP  15. PHP_Token_Stream->scan() /usr/share/php/PHP/Token/Stream.php:147

I already modified memory_limit for both cli and server php.ini.
I also already modified the memory_limit of suhosin.

When I print a phpinfo() in the cli I got these values :

memory_limit => 2048M => 2048M
suhosin.memory_limit => 2G => 2G

Does anyone has an idea of what may be causing this problem ? Has anyone faced such a situation ?

Looks like it stops at 200 Megabytes so either you need to look through your config more to allow more memory to be used or you have an include loop somewhere in the code. This has happened to me with twig includes a couple of times

Increase your PHP Memory Limit (I used 1744M to leave some safety space for PHP). I had the same problem before doing the extra memory. The next thing I changed was to exclude external libraries from the code-coverage (they are tested in their package by the author, so I do not need to know their code-coverage in my project). This allowed our project to then parse properly and get proper code coverage analysis.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM