0

I keep getting a memory exhausted error when trying to run infection tests using phpdbg. I've tried setting the -d memory_limit but it seems to get ignored.

Below is some sample output:

$ phpdbg -qrr -d memory_limit=1G vendor/bin/infection
You are running Infection with phpdbg enabled.
     ____      ____          __  _
    /  _/___  / __/__  _____/ /_(_)___  ____
    / // __ \/ /_/ _ \/ ___/ __/ / __ \/ __ \
  _/ // / / / __/  __/ /__/ /_/ / /_/ / / / /
 /___/_/ /_/_/  \___/\___/\__/_/\____/_/ /_/

Running initial test suite...

PHPUnit version: 7.5.11

    4 [============================]  1 sec

 [ERROR] Project tests must be in a passing state before running Infection.

         Infection runs the test suite in a RANDOM order. Make sure your tests do not have hidden dependencies.

         You can add these attributes to `phpunit.xml` to check it: <phpunit executionOrder="random"
         resolveDependencies="true" ...

         If you don't want to let Infection run tests in a random order, set the `executionOrder` to some value, for
         example <phpunit executionOrder="default"

         Check the executed command to identify the problem: '/usr/local/Cellar/php@7.2/7.2.18/bin/phpdbg' '-qrr'
         '~/Project/vendor/phpunit/phpunit/phpunit' '--configuration'
         '/var/folders/05/qbcbz9cn08jdty7r35dwkgdm0000gn/T/infection/phpunitConfiguration.initial.infection.xml'

         PHPUnit reported an exit code of 255.

         Refer to the PHPUnit's output below:

         STDOUT:

         PHPUnit 7.5.11 by Sebastian Bergmann and contributors.

         Random seed:   1560152243

         [PHP Fatal error:  Allowed memory size of 134217728 bytes exhausted (tried to allocate 65536 bytes) in
         ~/Project/vendor/sebastian/exporter/src/Exporter.php on line
         219]
         [PHP Stack trace:]
         [PHP   1. {main}()
         ~/Project/vendor/phpunit/phpunit/phpunit:0]

With my infection.json.dist file:

{
    "timeout": 10,
    "source": {
        "directories": [
            "src"
        ]
    },
    "logs": {
        "text": "infection.log"
    },
    "mutators": {
        "@default": true
    }
}
sanmai
  • 29,083
  • 12
  • 64
  • 76
Xethron
  • 1,116
  • 9
  • 24

2 Answers2

0

You want memory_limit=-1 in your development environment's php.ini configuration file.

Sebastian Bergmann
  • 7,837
  • 1
  • 27
  • 35
  • This is running in our CI. I have looked at changing the values in the ini, but was hoping there's an "easier" way to simply update the command. But I think infection runs the phpunit tests without the memory limit setting, so was hoping for a setting in the config file. Guess I'll have to update the CI. – Xethron Jun 10 '19 at 09:02
0

You can collect the coverage beforehand, and then feed it to the Infection.

vendor/bin/phpunit --coverage-xml=build/logs/coverage-xml \
                   --log-junit=build/logs/junit.xml
vendor/bin/infection --coverage=build/logs --show-mutations

As you won't be running both Infection and PHPUnit at once you may avoid the memory limit problem altogether. And if not, running either of the programs with a higher memory limit should be as easy as:

php -d memory_limit=-1 vendor/bin/...

This way you can also re-run Infection after fixing tests to see if you killed a mutation without the need to recollect coverage data.

sanmai
  • 29,083
  • 12
  • 64
  • 76