Completed
Pull Request — master (#3588)
by Andrej
19:46
created

TransactionTest::testCommitFalse()   A

Complexity

Conditions 2
Paths 5

Size

Total Lines 20
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 13
c 1
b 0
f 0
dl 0
loc 20
rs 9.8333
cc 2
nc 5
nop 0
1
<?php
2
3
namespace Doctrine\Tests\DBAL\Functional;
4
5
use Doctrine\DBAL\Schema\Table;
6
use Doctrine\Tests\DbalFunctionalTestCase;
7
use Throwable;
8
use function in_array;
9
use function sleep;
10
11
class TransactionTest extends DbalFunctionalTestCase
12
{
13
    protected function setUp() : void
14
    {
15
        parent::setUp();
16
17
        if (in_array($this->connection->getDatabasePlatform()->getName(), ['mysql'])) {
18
            return;
19
        }
20
21
        $this->markTestSkipped('Restricted to MySQL.');
22
    }
23
24
    protected function tearDown() : void
25
    {
26
        $this->resetSharedConn();
27
28
        parent::tearDown();
29
    }
30
31
    public function testCommitFalse() : void
32
    {
33
        $this->connection->query('SET SESSION wait_timeout=1');
34
35
        $table = new Table('foo');
36
        $table->addColumn('id', 'integer');
37
        $table->setPrimaryKey(['id']);
38
39
        $this->connection->getSchemaManager()->createTable($table);
40
41
        self::assertEquals('foo', $table->getName());
42
        try {
43
            $this->assertTrue($this->connection->beginTransaction());
44
            $this->connection->executeUpdate('INSERT INTO foo (id) VALUES(1)');
45
46
            sleep(2); // during the sleep mysql will close the connection
47
48
            $this->assertFalse(@$this->connection->commit()); // we will ignore `MySQL server has gone away` warnings
49
        } catch (Throwable $exception) {
50
            $this->fail('Is the PHP/PDO bug https://bugs.php.net/bug.php?id=66528 fixed? Normally no exception is thrown.');
51
        }
52
    }
53
}
54