-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathRetryConnectionTest.php
More file actions
39 lines (31 loc) · 1.35 KB
/
RetryConnectionTest.php
File metadata and controls
39 lines (31 loc) · 1.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<?php
namespace ipl\Tests\Sql;
use Exception;
use ipl\Sql\RetryConnection;
class RetryConnectionTest extends \PHPUnit\Framework\TestCase
{
public function testIsRetryable()
{
$db = $this->getConnection();
$this->assertTrue($db::isRetryable(new Exception('SQLState: Connection refused by the server')));
$this->assertTrue($db::isRetryable(new Exception('SQLState: Error writing data to the connection')));
$this->assertTrue($db::isRetryable(new Exception('SQLState: No such file or directory found')));
$this->assertFalse($db::isRetryable(new Exception('SQLState: Cannot start transaction')));
$this->assertFalse($db::isRetryable(new Exception('Cannot establish the connection to SQL server')));
$this->assertFalse($db::isRetryable(new Exception('Fatal error encountered during command execution')));
}
public function testExecutionRetriesGivesUpAfterMaxRetries()
{
$this->expectException(Exception::class);
$this->expectExceptionMessage('SQLSTATE[HY000] [2002] No such file or directory');
$this->getConnection(2)->transaction(function () {
});
}
protected function getConnection(int $retries = 1): RetryConnection
{
return new RetryConnection([
'db' => 'mysql',
'dbname' => 'foo',
], $retries);
}
}