Phpunit fails after a series of tests

I am running phpunit from command line for laravel website.

Output (first line):



However, all of these tests are performed individually. It's when I run them all together that most of them fail.

All errors show expected code 500, 200.


not ok 99 - Failure: TeamTest::testApiShow
message: 'A GET request to ''http://localhost/api/v1/teams/1'' failed. Got a 500 code instead.'
severity: fail


More details

Error on line 47 [..] vendor / laravel / framework / src / light / Database / Connectors / Connector.php

line 47: return new PDO($dsn, $username, $password, $options);


full output: config phpunit:


source to share

2 answers

There may be too many connections to the database. Both PostgreSQL and MySQL have a limit on the number of available connections, and phpUnit does not bind any pool connections, and does not return pool connections after using them.

I often have to increase the maximum connections for PostgreSQL on my Jenkins servers (unit test) to 500 or more to run a full unit test package.

More details here:



This is a case of too many SQL connections, and luckily there is a workaround: close MySQL connections during tearDown. In Laravel it looks like this:

public function tearDown()
    $this->beforeApplicationDestroyed(function () {
        foreach (\DB::getConnections() as $connection) {



based on:



All Articles