Skip to content

Commit

Permalink
Add functional test for comit() returning false
Browse files Browse the repository at this point in the history
  • Loading branch information
pulzarraider committed Jun 25, 2019
1 parent 9134cd4 commit 7205a51
Showing 1 changed file with 53 additions and 0 deletions.
53 changes: 53 additions & 0 deletions tests/Doctrine/Tests/DBAL/Functional/TransactionTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,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.');
}
}
}

0 comments on commit 7205a51

Please sign in to comment.