Phpunit fails after a series of tests

I am running phpunit from command line for laravel website.

Output (first line):

.................FFFFFFFFFFFFFFFFF.FFFFFFFFF.FFFFFFFFFFFFFFFFF.  63 / 105 ( 60%)

      

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.

Example:

<pre>
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
</pre>

      

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: http://pastebin.com/bt29w7Lz config phpunit: http://pastebin.com/pBT59aXM

+3


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:



https://dev.mysql.com/doc/refman/5.5/en/too-many-connections.html

https://wiki.postgresql.org/wiki/Number_Of_Database_Connections

+1


source


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) {
            $connection->disconnect();
        }
    });

    parent::tearDown();
}

      



based on: https://www.neontsunami.com/posts/too-many-connections-using-phpunit-for-testing-laravel-51

+1


source







All Articles