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

Connection::setNestTransactionsWithSavepoints() should not break lazy connection #6362

Merged
merged 1 commit into from
Apr 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 0 additions & 4 deletions src/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -1317,10 +1317,6 @@ public function setNestTransactionsWithSavepoints($nestTransactionsWithSavepoint
throw ConnectionException::mayNotAlterNestedTransactionWithSavepointsInTransaction();
}

if (! $this->getDatabasePlatform()->supportsSavepoints()) {
throw ConnectionException::savepointsNotSupported();
}

$this->nestTransactionsWithSavepoints = (bool) $nestTransactionsWithSavepoints;
}

Expand Down
42 changes: 42 additions & 0 deletions tests/ConnectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@

namespace Doctrine\DBAL\Tests;

use BadMethodCallException;
use Doctrine\Common\EventManager;
use Doctrine\DBAL\Cache\QueryCacheProfile;
use Doctrine\DBAL\Configuration;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\ConnectionException;
use Doctrine\DBAL\Driver;
use Doctrine\DBAL\Driver\API\ExceptionConverter;
use Doctrine\DBAL\Driver\Connection as DriverConnection;
use Doctrine\DBAL\Driver\ServerInfoAwareConnection;
use Doctrine\DBAL\DriverManager;
Expand Down Expand Up @@ -81,6 +83,46 @@ public function testNoTransactionActiveByDefault(): void
self::assertFalse($this->connection->isTransactionActive());
}

public function testSetNestTransactionsWithSavepointsDoesNotConnect(): void
{
$this->expectNotToPerformAssertions();

$connection = new Connection(
[],
new class implements VersionAwarePlatformDriver {
/** {@inheritDoc} */
public function connect(array $params): DriverConnection
{
throw new BadMethodCallException('The connection must not be opened');
}

public function getDatabasePlatform(): AbstractPlatform
{
throw new BadMethodCallException('The connection must not be opened');
}

public function getSchemaManager(Connection $conn, AbstractPlatform $platform): AbstractSchemaManager
{
throw new BadMethodCallException('The connection must not be opened');
}

public function getExceptionConverter(): ExceptionConverter
{
throw new BadMethodCallException('The connection must not be opened');
}

/** {@inheritDoc} */
public function createDatabasePlatformForVersion($version): AbstractPlatform
{
throw new BadMethodCallException('The connection must not be opened');
}
},
new Configuration(),
);

$connection->setNestTransactionsWithSavepoints(true);
}

public function testCommitWithNoActiveTransactionThrowsException(): void
{
$this->expectException(ConnectionException::class);
Expand Down
12 changes: 0 additions & 12 deletions tests/Functional/ConnectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -195,18 +195,6 @@ public function testTransactionIsInactiveAfterConnectionClose(): void
self::assertFalse($this->connection->isTransactionActive());
}

public function testSetNestedTransactionsThroughSavepointsNotSupportedThrowsException(): void
{
if ($this->connection->getDatabasePlatform()->supportsSavepoints()) {
self::markTestSkipped('This test requires the platform not to support savepoints.');
}

$this->expectException(ConnectionException::class);
$this->expectExceptionMessage('Savepoints are not supported by this driver.');

$this->connection->setNestTransactionsWithSavepoints(true);
}

public function testCreateSavepointsNotSupportedThrowsException(): void
{
if ($this->connection->getDatabasePlatform()->supportsSavepoints()) {
Expand Down