I am running functional tests in Laravel 5.1 against a MySQL database on a staging server and get the following error:
PDOException: SQLSTATE[HY000] [1226] User 'username' has exceeded the 'max_user_connections' resource (current value: 20)
The TestCase class looks like:
<?php
use Illuminate\Support\Facades\Artisan;
use Illuminate\Foundation\Testing\DatabaseTransactions;
class TestCase extends Illuminate\Foundation\Testing\TestCase
{
/**
* Rollback and execute migrations for each test.
*/
use DatabaseTransactions;
/**
* The base URL to use while testing the application.
*
* @var string
*/
protected $baseUrl = 'http://localhost';
/**
* Is this the first test.
*
* @var bool
*/
protected static $isInitialTest = true;
/**
* Creates the application.
*
* @return \Illuminate\Foundation\Application
*/
public function createApplication()
{
$app = require __DIR__.'/../bootstrap/app.php';
$app->make(Illuminate\Contracts\Console\Kernel::class)->bootstrap();
return $app;
}
/**
* If this is the first test of the actual test suite:
* Delete all test table records and run migrations.
*
* @return void
*/
public function setUp()
{
parent::setUp();
if(self::$isInitialTest){
self::$isInitialTest = false;
Artisan::call('migrate');
}
}
}
And a failing test (after a lot of other tests ran successfully) looks like
use Illuminate\Foundation\Testing\WithoutMiddleware;
class AreasTest extends TestCase
{
/**
* Add a new area to a tenant.
*/
public function testAddArea()
{
$tenant = factory('XXX\Tenant', 'xxx')->create();
$this->visit("admin/tenants/{$tenant->id}")
->click('…')
->click('N…')
->type('…', 'name')
->press('…')
->see('…');
}
…
}
I am running the tests like this
vendor/phpunit/phpunit/phpunit --bootstrap ./bootstrap/autoload.php ./tests/
Is there anything beside raising max_user_connections
I can do to control how much parallel db connections are open? If possible I do not want to slow down the tests :)
On my local dev machine max_user_connections
is set to 0
so there is no limitation and no error.