Skip to content

Commit fe8e7b8

Browse files
committed
Drop support for silencing errors about DDL in transactions
I hesitated between this and removing the transaction helper entirely, but I think this solution will result in less support for us.
1 parent 53303eb commit fe8e7b8

File tree

3 files changed

+31
-35
lines changed

3 files changed

+31
-35
lines changed

Diff for: UPGRADE.md

+5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
# Upgrade to 4.0
2+
3+
It is no longer possible to relying on silencing to enable transactional
4+
migrations when the platform does not allow DDL inside transactions.
5+
16
# Upgrade to 3.1
27

38
- The "version" is the FQCN of the migration class (existing entries in the migrations table will be automatically updated).

Diff for: lib/Doctrine/Migrations/Tools/TransactionHelper.php

+8-17
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
namespace Doctrine\Migrations\Tools;
66

77
use Doctrine\DBAL\Connection;
8-
use Doctrine\Deprecations\Deprecation;
98
use LogicException;
109
use PDO;
1110

@@ -19,19 +18,15 @@ final class TransactionHelper
1918
public static function commitIfInTransaction(Connection $connection): void
2019
{
2120
if (! self::inTransaction($connection)) {
22-
Deprecation::trigger(
23-
'doctrine/migrations',
24-
'https://github.com/doctrine/migrations/issues/1169',
25-
<<<'DEPRECATION'
21+
throw new LogicException(
22+
<<<'EXCEPTION'
2623
Context: trying to commit a transaction
27-
Problem: the transaction is already committed, relying on silencing is deprecated.
24+
Problem: the transaction is already committed.
2825
Solution: override `AbstractMigration::isTransactional()` so that it returns false.
2926
Automate that by setting `transactional` to false in the configuration.
3027
More details at https://www.doctrine-project.org/projects/doctrine-migrations/en/3.2/explanation/implicit-commits.html
31-
DEPRECATION
28+
EXCEPTION
3229
);
33-
34-
return;
3530
}
3631

3732
$connection->commit();
@@ -40,19 +35,15 @@ public static function commitIfInTransaction(Connection $connection): void
4035
public static function rollbackIfInTransaction(Connection $connection): void
4136
{
4237
if (! self::inTransaction($connection)) {
43-
Deprecation::trigger(
44-
'doctrine/migrations',
45-
'https://github.com/doctrine/migrations/issues/1169',
46-
<<<'DEPRECATION'
38+
throw new LogicException(
39+
<<<'EXCEPTION'
4740
Context: trying to rollback a transaction
48-
Problem: the transaction is already rolled back, relying on silencing is deprecated.
41+
Problem: the transaction is already rolled back.
4942
Solution: override `AbstractMigration::isTransactional()` so that it returns false.
5043
Automate that by setting `transactional` to false in the configuration.
5144
More details at https://www.doctrine-project.org/projects/doctrine-migrations/en/3.2/explanation/implicit-commits.html
52-
DEPRECATION
45+
EXCEPTION
5346
);
54-
55-
return;
5647
}
5748

5849
$connection->rollBack();

Diff for: tests/Doctrine/Migrations/Tests/Tools/TransactionHelperTest.php

+18-18
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,14 @@
55
namespace Doctrine\Migrations\Tests\Tools;
66

77
use Doctrine\DBAL\Connection;
8-
use Doctrine\Deprecations\PHPUnit\VerifyDeprecations;
98
use Doctrine\Migrations\Tools\TransactionHelper;
9+
use LogicException;
1010
use PDO;
1111
use PHPUnit\Framework\TestCase;
1212

1313
final class TransactionHelperTest extends TestCase
1414
{
15-
use VerifyDeprecations;
16-
17-
public function testItTriggersADeprecationWhenUseful(): void
15+
public function testItThrowsAnExceptionWhenAttemptingToCommitWhileNotInsideATransaction(): void
1816
{
1917
$connection = $this->createStub(Connection::class);
2018
$wrappedConnection = $this->createStub(PDO::class);
@@ -23,18 +21,27 @@ public function testItTriggersADeprecationWhenUseful(): void
2321

2422
$wrappedConnection->method('inTransaction')->willReturn(false);
2523

26-
$this->expectDeprecationWithIdentifier(
27-
'https://github.com/doctrine/migrations/issues/1169'
28-
);
24+
$this->expectException(LogicException::class);
2925
TransactionHelper::commitIfInTransaction($connection);
26+
}
27+
28+
public function testItThrowsAnExceptionWhenAttemptingToRollbackWhileNotInsideATransaction(): void
29+
{
30+
$connection = $this->createStub(Connection::class);
31+
$wrappedConnection = $this->createStub(PDO::class);
3032

31-
$this->expectDeprecationWithIdentifier(
32-
'https://github.com/doctrine/migrations/issues/1169'
33-
);
33+
$connection->method('getNativeConnection')->willReturn($wrappedConnection);
34+
35+
$wrappedConnection->method('inTransaction')->willReturn(false);
36+
37+
$this->expectException(LogicException::class);
3438
TransactionHelper::rollbackIfInTransaction($connection);
3539
}
3640

37-
public function testItDoesNotTriggerADeprecationWhenUseless(): void
41+
/**
42+
* @doesNotPerformAssertions
43+
*/
44+
public function testItDoesNotThrowAnExceptionWhenUseless(): void
3845
{
3946
$connection = $this->createStub(Connection::class);
4047
$wrappedConnection = $this->createStub(PDO::class);
@@ -43,14 +50,7 @@ public function testItDoesNotTriggerADeprecationWhenUseless(): void
4350

4451
$wrappedConnection->method('inTransaction')->willReturn(true);
4552

46-
$this->expectNoDeprecationWithIdentifier(
47-
'https://github.com/doctrine/migrations/issues/1169'
48-
);
4953
TransactionHelper::commitIfInTransaction($connection);
50-
51-
$this->expectNoDeprecationWithIdentifier(
52-
'https://github.com/doctrine/migrations/issues/1169'
53-
);
5454
TransactionHelper::rollbackIfInTransaction($connection);
5555
}
5656
}

0 commit comments

Comments
 (0)