diff --git a/tests/Functional/TransactionTest.php b/tests/Functional/TransactionTest.php index 1421bd10a8a..77e2fd09cc9 100644 --- a/tests/Functional/TransactionTest.php +++ b/tests/Functional/TransactionTest.php @@ -2,26 +2,24 @@ namespace Doctrine\DBAL\Tests\Functional; +use Doctrine\DBAL\Connection; use Doctrine\DBAL\Driver\Exception as DriverException; use Doctrine\DBAL\Platforms\AbstractMySQLPlatform; +use Doctrine\DBAL\Schema\Table; use Doctrine\DBAL\Tests\FunctionalTestCase; +use Doctrine\DBAL\Types\Types; use PDOException; use function sleep; class TransactionTest extends FunctionalTestCase { - protected function setUp(): void + public function testCommitFalse(): void { - if ($this->connection->getDatabasePlatform() instanceof AbstractMySQLPlatform) { - return; + if (! $this->connection->getDatabasePlatform() instanceof AbstractMySQLPlatform) { + $this->markTestSkipped('Restricted to MySQL.'); } - $this->markTestSkipped('Restricted to MySQL.'); - } - - public function testCommitFalse(): void - { $this->connection->executeStatement('SET SESSION wait_timeout=1'); self::assertTrue($this->connection->beginTransaction()); @@ -40,4 +38,30 @@ public function testCommitFalse(): void $this->connection->close(); } } + + public function testNestedTransactionWalkthrough(): void + { + $table = new Table('storage'); + $table->addColumn('test_int', Types::INTEGER); + $table->setPrimaryKey(['test_int']); + + $this->dropAndCreateTable($table); + + $query = 'SELECT count(test_int) FROM storage'; + + self::assertSame('0', (string) $this->connection->fetchOne($query)); + + $result = $this->connection->transactional( + static fn (Connection $connection) => $connection->transactional( + static function (Connection $connection) use ($query) { + $connection->insert('storage', ['test_int' => 1]); + + return $connection->fetchOne($query); + }, + ), + ); + + self::assertSame('1', (string) $result); + self::assertSame('1', (string) $this->connection->fetchOne($query)); + } }