for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace Doctrine\Tests\DBAL\Functional;
use Doctrine\DBAL\Schema\Table;
use Doctrine\Tests\DbalFunctionalTestCase;
use Throwable;
use function in_array;
use function sleep;
class TransactionTest extends DbalFunctionalTestCase
{
protected function setUp() : void
parent::setUp();
if (in_array($this->connection->getDatabasePlatform()->getName(), ['mysql'])) {
return;
}
$this->markTestSkipped('Restricted to MySQL.');
protected function tearDown() : void
$this->resetSharedConn();
parent::tearDown();
public function testCommitFalse() : void
$this->connection->query('SET SESSION wait_timeout=1');
$table = new Table('foo');
$table->addColumn('id', 'integer');
$table->setPrimaryKey(['id']);
$this->connection->getSchemaManager()->createTable($table);
self::assertEquals('foo', $table->getName());
try {
$this->assertTrue($this->connection->beginTransaction());
$this->connection->executeUpdate('INSERT INTO foo (id) VALUES(1)');
sleep(2); // during the sleep mysql will close the connection
$this->assertFalse(@$this->connection->commit()); // we will ignore `MySQL server has gone away` warnings
} catch (Throwable $exception) {
$this->fail('Is the PHP/PDO bug https://bugs.php.net/bug.php?id=66528 fixed? Normally no exception is thrown.');