-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add functional test for comit() returning false
- Loading branch information
1 parent
9134cd4
commit e428509
Showing
1 changed file
with
46 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?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.'); | ||
} | ||
|
||
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.'); | ||
} | ||
} | ||
} |