-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Handle lost connection during commit
- Loading branch information
Showing
3 changed files
with
58 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Doctrine\DBAL\Tests\Functional; | ||
|
||
use Doctrine\DBAL\Exception\ConnectionLost; | ||
use Doctrine\DBAL\Platforms\MySQLPlatform; | ||
use Doctrine\DBAL\Tests\FunctionalTestCase; | ||
|
||
use function sleep; | ||
|
||
use const E_ALL; | ||
use const E_WARNING; | ||
|
||
class TransactionTest extends FunctionalTestCase | ||
{ | ||
protected function setUp(): void | ||
{ | ||
parent::setUp(); | ||
|
||
if ($this->connection->getDatabasePlatform() instanceof MySQLPlatform) { | ||
return; | ||
} | ||
|
||
self::markTestSkipped('Restricted to MySQL.'); | ||
} | ||
|
||
public function testCommitFailure(): void | ||
{ | ||
$this->connection->executeStatement('SET SESSION wait_timeout=1'); | ||
|
||
$this->connection->beginTransaction(); | ||
|
||
// during the sleep MySQL will close the connection | ||
sleep(2); | ||
|
||
// prevent the PHPUnit error handler from handling the "MySQL server has gone away" warning | ||
$this->iniSet('error_reporting', (string) (E_ALL & ~E_WARNING)); | ||
|
||
$this->expectException(ConnectionLost::class); | ||
$this->connection->commit(); | ||
} | ||
} |