-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
/
Copy pathTransactionTest.php
53 lines (40 loc) · 1.47 KB
/
TransactionTest.php
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<?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.');
}
}
}