up vote 0 down vote favorite
share [g+] share [fb]

I've just started using PHP Unit with Zend Framework and I have a problem with the memory_limit. Currently, the memory limit is set to 32M and when running all tests I get an fatal error:

Allowed memory size of 33554432 bytes exhausted.

Currently, I have: 7 files, 125 tests, 332 assertions. I only test the controllers. I use @dataProvider for some tests, with the 1 to 5 sets of data (at first I was reading them from file, I've tried to put the data directly in the tests files, but it still hits the memory limit)

So my question is what is your usual memory limit for phpunit based testing? Where should I look to improve the memory testing? Any advice will be great.

Thanks, Gabriel

link|improve this question
What's PHPUnit version and ZS version? – FractalizeR Nov 18 '10 at 14:59
PHP Version 5.2.8, PHPUnit 3.4.2, Zend Framework Version 1.10.8 – Gabriel Croitoru Nov 18 '10 at 15:04
feedback

3 Answers

up vote 1 down vote accepted

I've run into a similar issue after my test suite exceeded 300 cases with 128M memory limit.
What helped me was running test cases in isolated processes. You can do this either from command line:

phpunit --process-isolation

or add it to your phpunit.xml config:

<phpunit bootstrap="./application/bootstrap.php"
    processIsolation="true">
link|improve this answer
Great, that solved my problem. Now the unit test are running a little to slow, but that's a problem I can live with. Thanks. – Gabriel Croitoru Nov 19 '10 at 11:02
feedback

Another Solution would be to turn off backing up and restoring the global state after every test. PHPUnit does this by default, this reduced the Memory Usage of our Test Suite from 1000 MB to 90 MB ... (yeah we have a big fat application)

600 Tests, ? Assertions, 80 000 lines of code, around 1200 files without libraries

link|improve this answer
feedback

I run PHP 5.3.3 with the default memory setting (128M) and never had an issue with unit testing applications on Zend Framework.

link|improve this answer
How huge are your applications? How many tests there? – FractalizeR Nov 18 '10 at 14:59
One in particular, the code base is about 20MB, and I have about 300 test cases right now. – netcoder Nov 18 '10 at 15:06
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.