Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: cover nested transactions #6547

Merged
merged 1 commit into from
Oct 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 32 additions & 8 deletions tests/Functional/TransactionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand All @@ -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));
}
}
Loading