PHPUnit代码覆盖率生成导致内存耗尽 [英] PHPUnit code coverage generation causing memory exhaustion

查看:208
本文介绍了PHPUnit代码覆盖率生成导致内存耗尽的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在结合使用Zend Framework和PHPUnit在应用程序上进行单元测试.当Hudson执行PHPUnit shell命令时,在代码覆盖率生成期间的某个时候达到了最大PHP内存限制.我目前总共进行了41个测试,包含334个断言.

I'm currently using Zend Framework in conjunction with PHPUnit to conduct unit testing on an application. When Hudson executes the PHPUnit shell command, the maximum PHP memory limit is reached sometime during code coverage generation. I currently have a total of 41 tests with 334 assertions.

我已经成功地通过使用-d memory_limit=768M开关将memory_limit设置提高到768M来消除了该错误;但是,我担心随着复杂性以及测试/断言总数的增加,我将没有足够的内存来生成用于代码覆盖率统计的HTML.

I have successfully eliminated this error by raising the memory_limit setting to 768M using the -d memory_limit=768M switch; however, I am worried that as the complexity increases along with the total number of tests/assertions, I will not have enough memory to generate the HTML for code coverage statistics.

操作系统:CentOS 5.5
控制面板: WHM/cPanel
CI服务器:哈德逊

OS: CentOS 5.5
Control Panel: WHM/cPanel
CI Server: Hudson

/usr/local/bin/phpunit 
  --verbose  
  -d memory_limit=512M  
  --log-junit ../../build/logs/phpunit.xml   
  --coverage-clover ../../build/logs/coverage/clover.xml   
  --coverage-html ../../build/logs/coverage-html/  

致命错误:允许的内存大小为 536870912字节已耗尽

Fatal error: Allowed memory size of 536870912 bytes exhausted

在提交更改并让Hudson处理其余操作之前,我使用Windows 7进行开发.在W7中运行相同的命令时,内存使用量从未超过340MB.

Before committing my changes and letting Hudson handle the rest, I use Windows 7 for development. The memory usage never exceeded 340MB while running the same command within W7.

推荐答案

通过减少代码覆盖范围内包含的文件数量,以及增加PHP中的整体内存限制,我基本上可以消除此错误.整个Zend Framework都包含在代码覆盖范围内,这非常大.

By reducing the number of files included within code coverage, as well as increasing the overall memory limit in PHP, I was able to basically kill this error. The entire Zend Framework was being included within code coverage, which is very large.

这篇关于PHPUnit代码覆盖率生成导致内存耗尽的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆