4
votes

I run phpunit from the command line for a laravel website.

The output (first line) is:

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

However, all those tests run fine individually. It's when I run them all together that most of them fail.

All errors show code 500, 200 expected.

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>

Details

Error occurs in line 47 of [..]vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php

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

full output: http://pastebin.com/bt29w7Lz config of phpunit: http://pastebin.com/pBT59aXM

2
Have you tried running phpunit --verbose to get more useful output?alariva
most show PDOException on [..]vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php line 47Michiel van der Blonk
Is that all? Try posting your full output to a pastebin.com and share the linkalariva
Can you do the same with phpunit.xml ? You can hide your password first.alariva

2 Answers

1
votes

It may be the case that there are too many database connections open. Both PostgreSQL and MySQL have a limit on the number of connections available, and phpUnit neither pools connections nor does it return connections to the pool once they are used.

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

See more here:

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

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

1
votes

This is a case of too many SQL connections and luckily there is a way to resolve it: close the MySQL connections during tearDown. On Laravel this looks like:

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