Gabriel Croitoru Gabriel Croitoru - 1 year ago 160
PHP Question

PhpUnit with Zend Framework memory problem

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.


Answer Source

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"