RyanHavoc's avatar

PHPUnit stalling or exhausting memory since upgrading to Laravel 5.6

Hi,

I had a working test suite however two things have change on my local environment. 1) I've upgrade Homestead to version 7 and 2) I've upgraded my app to Laravel 5.6.

Now I'm having issues with PHPUnit exhausting memory allocation unless I add ini_set('memory_limit', '1024M'); to the start of my createApplication method. My test suite then progresses a bit further but eventually stalls entirely.

The strange thing is if I run the test that the suite stalls on in isolation it passes. In fact if I just test the entire file, which may contain 10 tests, the tests all pass. It only stalls when trying to test the entire suite in one go...

It's as if things aren't getting cleaned up between tests it's just filling up memory and freezing.

But I'm using the default TestCase tearDown method:

    /**
     * Clean up the testing environment before the next test.
     *
     * @return void
     */
    protected function tearDown()
    {
        if ($this->app) {
            foreach ($this->beforeApplicationDestroyedCallbacks as $callback) {
                call_user_func($callback);
            }

            $this->app->flush();

            $this->app = null;
        }

        $this->setUpHasRun = false;

        if (property_exists($this, 'serverVariables')) {
            $this->serverVariables = [];
        }

        if (property_exists($this, 'defaultHeaders')) {
            $this->defaultHeaders = [];
        }

        if (class_exists('Mockery')) {
            if ($container = Mockery::getContainer()) {
                $this->addToAssertionCount($container->mockery_getExpectationCount());
            }

            Mockery::close();
        }

        if (class_exists(Carbon::class)) {
            Carbon::setTestNow();
        }

        $this->afterApplicationCreatedCallbacks = [];
        $this->beforeApplicationDestroyedCallbacks = [];

        Artisan::forgetBootstrappers();
    }

Which from my understand so reset everything between tests.

I'm using sqlite in memory as my database for testing.

Anyone else experience problems since upgrading?

0 likes
11 replies
RyanHavoc's avatar

@crawdaddy Yeah it has done. Have you found a solution? Massively frustrating as everything ran fine and passes last week.

I've literally been trying to resolve this all day.

RyanHavoc's avatar

@Cronix Yes. Version 2.6.0. It appears to have come preinstall on Homestead 7.

crawdingle's avatar

@RyanHavoc woops, accidentally deleted my original comment.

No I have yet to find a solution, tried a whole lot of things as well, I switched out laptops last week and they ran fine on my old one but do not on my new laptop nor on my desktop.

RyanHavoc's avatar

@crawdaddy Same thing with me, had to reinstall my Mac and after that problems started. Seen as all the tests have worked in the past that suggests to me a config issue?

Cronix's avatar

Try disabling xdebug and see if that helps.

php5dismod xdebug and to reenable it php5enmod xdebug. You might have to run it as sudo.

restart nginx after either

RyanHavoc's avatar

@Cronix Exact same behaviour unfortunately. I've tried it with it disabled and again after reenabling it. No joy. Ensured I'd reprovisioned Homestead each time to ensure had been restarted and it was disabled as well.

Cronix's avatar

Last thing I can think of is making sure you're running the tests from the homestead cli, which you probably are.

crawdingle's avatar
Level 1

I switched back to php 7.1 in homestead cli and it fixed it for me just now!

I thought I had specified my PHP Version in my homestead.yaml but it wasn't the same version in the cli.

  1. Change to 7.1 in the homestead.yaml
  2. re-provision.
  3. sudo update-alternatives --config php choose 7.1 here.

I don't know if this'll help your specific problem but it fixed mine.

Just tried the same on my desktop pc and it fixed the issue there for me as well.

2 likes
RyanHavoc's avatar

@crawdaddy Thank you! That's fixed it for me as well. Looks like the issue centre's around PHP 7.2. sigh

1 like

Please or to participate in this conversation.