Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

krystian2160's avatar

Laravel Testing - PHPUnit and PHP Fatal error: Allowed memory size

...........\php.exe ............../phpunit --configuration .............\phpunit.xml --teamcity
Testing started at 18:53 ...
PHPUnit 7.1.5 by Sebastian Bergmann and contributors.

PHP Fatal error:  Allowed memory size of 134217728 bytes exhausted (tried to allocate 790528 bytes) in ...................\vendor\fzaninotto\faker\src\Faker\Provider\Text.php on line 84
PHP Stack trace:
PHP   1. {main}() ..............\vendor\phpunit\phpunit\phpunit:0
PHP   2. PHPUnit\TextUI\Command::main() ..............\vendor\phpunit\phpunit\phpunit:53
PHP   3. PHPUnit\TextUI\Command->run() ..............\vendor\phpunit\phpunit\src\TextUI\Command.php:151
PHP   4. PHPUnit\TextUI\TestRunner->doRun() ..............\vendor\phpunit\phpunit\src\TextUI\Command.php:198

I have something like this after running many tests and assertions. What to do with it? Is it okay to have this kind of error in testing? And the right solution is to higher the memory?

0 likes
2 replies
ejdelmonico's avatar

Seems like you have a memory leak somewhere in your test setup. I suppose you could just bump up the max allowable memory but I would have to say that the error will occur again if it is a memory leak.

krystian2160's avatar

This is my setUp

protected function setUp()
    {
        parent::setUp();
        $this->withoutMiddleware([VerifyCsrfToken::class]);
        $this->followingRedirects();
    }

Please or to participate in this conversation.