Skip to content

Commit b05e48a

Browse files
authored
Connection::setNestTransactionsWithSavepoints() should not break lazy connection (#6362)
| Q | A |------------- | ----------- | Type | bug | Fixed issues | N/A #### Summary When calling `Connection::setNestTransactionsWithSavepoints()`, the platform is fetched to check if savepoints are actually supported. This is a problem because it might cause the connection to be opened. I've removed the check which will postpone the exception to the first time we attempt to create a savepoint.
1 parent ad2fee0 commit b05e48a

File tree

3 files changed

+42
-16
lines changed

3 files changed

+42
-16
lines changed

src/Connection.php

-4
Original file line numberDiff line numberDiff line change
@@ -1317,10 +1317,6 @@ public function setNestTransactionsWithSavepoints($nestTransactionsWithSavepoint
13171317
throw ConnectionException::mayNotAlterNestedTransactionWithSavepointsInTransaction();
13181318
}
13191319

1320-
if (! $this->getDatabasePlatform()->supportsSavepoints()) {
1321-
throw ConnectionException::savepointsNotSupported();
1322-
}
1323-
13241320
$this->nestTransactionsWithSavepoints = (bool) $nestTransactionsWithSavepoints;
13251321
}
13261322

tests/ConnectionTest.php

+42
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@
22

33
namespace Doctrine\DBAL\Tests;
44

5+
use BadMethodCallException;
56
use Doctrine\Common\EventManager;
67
use Doctrine\DBAL\Cache\QueryCacheProfile;
78
use Doctrine\DBAL\Configuration;
89
use Doctrine\DBAL\Connection;
910
use Doctrine\DBAL\ConnectionException;
1011
use Doctrine\DBAL\Driver;
12+
use Doctrine\DBAL\Driver\API\ExceptionConverter;
1113
use Doctrine\DBAL\Driver\Connection as DriverConnection;
1214
use Doctrine\DBAL\Driver\ServerInfoAwareConnection;
1315
use Doctrine\DBAL\DriverManager;
@@ -81,6 +83,46 @@ public function testNoTransactionActiveByDefault(): void
8183
self::assertFalse($this->connection->isTransactionActive());
8284
}
8385

86+
public function testSetNestTransactionsWithSavepointsDoesNotConnect(): void
87+
{
88+
$this->expectNotToPerformAssertions();
89+
90+
$connection = new Connection(
91+
[],
92+
new class implements VersionAwarePlatformDriver {
93+
/** {@inheritDoc} */
94+
public function connect(array $params): DriverConnection
95+
{
96+
throw new BadMethodCallException('The connection must not be opened');
97+
}
98+
99+
public function getDatabasePlatform(): AbstractPlatform
100+
{
101+
throw new BadMethodCallException('The connection must not be opened');
102+
}
103+
104+
public function getSchemaManager(Connection $conn, AbstractPlatform $platform): AbstractSchemaManager
105+
{
106+
throw new BadMethodCallException('The connection must not be opened');
107+
}
108+
109+
public function getExceptionConverter(): ExceptionConverter
110+
{
111+
throw new BadMethodCallException('The connection must not be opened');
112+
}
113+
114+
/** {@inheritDoc} */
115+
public function createDatabasePlatformForVersion($version): AbstractPlatform
116+
{
117+
throw new BadMethodCallException('The connection must not be opened');
118+
}
119+
},
120+
new Configuration(),
121+
);
122+
123+
$connection->setNestTransactionsWithSavepoints(true);
124+
}
125+
84126
public function testCommitWithNoActiveTransactionThrowsException(): void
85127
{
86128
$this->expectException(ConnectionException::class);

tests/Functional/ConnectionTest.php

-12
Original file line numberDiff line numberDiff line change
@@ -195,18 +195,6 @@ public function testTransactionIsInactiveAfterConnectionClose(): void
195195
self::assertFalse($this->connection->isTransactionActive());
196196
}
197197

198-
public function testSetNestedTransactionsThroughSavepointsNotSupportedThrowsException(): void
199-
{
200-
if ($this->connection->getDatabasePlatform()->supportsSavepoints()) {
201-
self::markTestSkipped('This test requires the platform not to support savepoints.');
202-
}
203-
204-
$this->expectException(ConnectionException::class);
205-
$this->expectExceptionMessage('Savepoints are not supported by this driver.');
206-
207-
$this->connection->setNestTransactionsWithSavepoints(true);
208-
}
209-
210198
public function testCreateSavepointsNotSupportedThrowsException(): void
211199
{
212200
if ($this->connection->getDatabasePlatform()->supportsSavepoints()) {

0 commit comments

Comments
 (0)