Phpunit runs out of memory

When using Phpunit in the IDE, I can specify a directory with tests to run.  However the directory I have has lots of tests, and I get a Fatal Exception due to running out of memory after about 270 tests run.

Is there any way to get it to run them serially but in different memory spaces or something so they don't stack up and crap out?  (I can do this with Ant, but I don't see any way to use Ant in PhpStorm).

Thanks!

7 comments

Hello Ben,

What PhpStorm version do you use?

When using Phpunit in the IDE, I can specify a directory with tests to run.  However the directory I have has lots of tests, and I get a Fatal Exception due to running out of memory after about 270 tests run.

Could you please attach a stacktrace?

Thank you for feedback!

0

I'm using the latest 3.0 release.

Just as an fyi, I discovered the "--process-isolation" flag you can put in the phpunit command line box, but that has an unfortunate side effect.  It's retaining something between tests, so tests that pass individually will fail when run with this option.  I think some variable isn't getting cleared that way.

In any case, using Ant from the command line works great for running all the tests and they all pass.  I'm hoping there is some way to have PhpStorm run them all serially so I don't have to have Ant installed or go to the command line.

0

Ben,

It is quite critical problem. Please submit an issue - http://youtrack.jetbrains.net/issues/WI#newissue=yes.
What do you mean under Fatal Exception - PHP interpreter exception or PhpStorm exception?

Thank you for feedback!

0

Well, with Nikolay's help I think the issues I had are resolved!


Summary of issues and solutions:


Problem: Inconsistent test results between Mac and PC

Cause:  PC tests were run without an SMTP server running which caused some mail related tests to fail.

Solution:  Run an SMTP server :p


Problem:  Mac tests would run out of memory before completing when using the Directory option

Cause:  If you do not use the --process-isolation command line parameter in the Edit Config dialog, all tests in the directory are run in the same process.  On our Macs, this caused PHP to run out of memory since we had so many tests.

Solution: Increase memory allocated to PHP in the php.ini (what we did) OR add a command line option in the Edit Config dialog to do so (-dmemory_limit=256M)


Problem:  Some tests which pass when running PhpUnit from the command line would fail when run from PhpStorm.

Cause:  These tests used relative paths.  They were looking for particular files to pass the test.  When you run a test from PhpStorm, it by default sets the current directory to a temporary directory that it created, not the directory where the tests are located.  So tests that had always worked before we tried PhpStorm would fail since the relative paths to the temp directory pointed to nothing.

Solution:  Change your tests to remove relative paths (what we did) OR use the Custom Working Directory in the Edit Config dialog of your tests and set the directory to the place where the relative paths work.


Thanks so much to Nikolay for helping me work through these! And for educating me about some PhpStorm functionality I didn't know about :)


Suggestions: Perhaps in a future release, some of the PhpUnit command line settings can be explicitly turned into GUI options in the config dialog.  (Like a checkbox for turning on Process Isolation, field for putting a custom temporary memory limit increase, etc.)  Being someone that's just learning how to use PhpUnit, many of these options were not known to me so having them visible the UI would be helpful.

0

Well, with Nikolay's help I think the issues I had are resolved!


Summary of issues and solutions:


Problem: Inconsistent test results between Mac and PC

Cause:  PC tests were run without an SMTP server running which caused some mail related tests to fail.

Solution:  Run an SMTP server :p


Problem:  Mac tests would run out of memory before completing when using the Directory option

Cause:  If you do not use the --process-isolation command line parameter in the Edit Config dialog, all tests in the directory are run in the same process.  On our Macs, this caused PHP to run out of memory since we had so many tests.

Solution: Increase memory allocated to PHP in the php.ini (what we did) OR add a command line option in the Edit Config dialog to do so (-dmemory_limit=256M)


Problem:  Some tests which pass when running PhpUnit from the command line would fail when run from PhpStorm.

Cause:  These tests used relative paths.  They were looking for particular files to pass the test.  When you run a test from PhpStorm, it by default sets the current directory to a temporary directory that it created, not the directory where the tests are located.  So tests that had always worked before we tried PhpStorm would fail since the relative paths to the temp directory pointed to nothing.

Solution:  Change your tests to remove relative paths (what we did) OR use the Custom Working Directory in the Edit Config dialog of your tests and set the directory to the place where the relative paths work.


Thanks so much to Nikolay for helping me work through these! And for educating me about some PhpStorm functionality I didn't know about :)


Suggestions: Perhaps in a future release, some of the PhpUnit command line settings can be explicitly turned into GUI options in the config dialog.  (Like a checkbox for turning on Process Isolation, field for putting a custom temporary memory limit increase, etc.)  Being someone that's just learning how to use PhpUnit, many of these options were not known to me so having them visible the UI would be helpful.

0

Please sign in to leave a comment.