phpunit memory_limit parameter does not apply

For those who reach this thread and need to get the configuration for phpunit.xml configuration file:

<php>
  <ini name="memory_limit" value="512M" />
</php>

More on section "Setting PHP INI settings, Constants and Global Variables" at https://phpunit.de/manual/6.5/en/appendixes.configuration.html


Yes you can set every php option with phpunit -d that can be set with ini_set.

You already opened a bug over in the phpunit bug tracker but well I'm going for the more verbose answer here

Reproduce to show it works in general:

echo "<?php var_dump(ini_get('memory_limit')); " > foo.php

phpunit -d memory_limit=12M --bootstrap foo.php 

Produces:

string(3) "12M"
PHPUnit 3.6.5 by Sebastian Bergmann.

But phpunit only applies this option once before the first test is run!

So chances are your code is somewhere changing the memory limit back to 32M which is something phpunit can't "fix".

Same goes for setting the memory limit in the phpunit.xml file.