8000 bug #50761 [DoctrineBridge] Ignore invalid stores in `LockStoreSchema… · MatTheCat/symfony@69ef02e · GitHub
[go: up one dir, main page]

Skip to content

Commit 69ef02e

Browse files
bug symfony#50761 [DoctrineBridge] Ignore invalid stores in LockStoreSchemaListener raised by StoreFactory (alexandre-daubois)
This PR was merged into the 6.3 branch. Discussion ---------- [DoctrineBridge] Ignore invalid stores in `LockStoreSchemaListener` raised by `StoreFactory` | Q | A | ------------- | --- | Branch? | 6.3 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | _NA_ | License | MIT | Doc PR | _NA_ In our test environment, we're setting our `LOCK_DSN` env var at `null`. This works well in 6.2 but not in 6.3 anymore. The version 6.3 of DoctrineBridge is bringing this BC break. Indeed, lock stores are being injected in `Symfony\Bridge\Doctrine\SchemaListener\LockStoreSchemaListener`. At runtime, the `StoreFactory` is used to instantiate stores when they are needed in `postGenerateSchema`. Unfortunately, our `LOCK_DSN=null` doesn't match any case in `StoreFactory`, which has the effect to throw `Symfony\Component\Lock\Exception\InvalidArgumentException`, which is not catched in `LockStoreSchemaListener`. This PR takes care of this: at this time, `LockStoreSchemaListener` only deals with `DoctrineDbalStore`. I think it is safe to ignore any instantiation problem that may occur in the `StoreFactory`. Commits ------- 0acd403 [DoctrineBridge] Ignore invalid stores in `LockStoreSchemaListener` raised by `StoreFactory`
2 parents 04c7ccf + 0acd403 commit 69ef02e

File tree

2 files changed

+30
-4
lines changed

2 files changed

+30
-4
lines changed

src/Symfony/Bridge/Doctrine/SchemaListener/LockStoreSchemaListener.php

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Bridge\Doctrine\SchemaListener;
1313

1414
use Doctrine\ORM\Tools\Event\GenerateSchemaEventArgs;
15+
use Symfony\Component\Lock\Exception\InvalidArgumentException;
1516
use Symfony\Component\Lock\PersistingStoreInterface;
1617
use Symfony\Component\Lock\Store\DoctrineDbalStore;
1718

@@ -28,12 +29,20 @@ public function postGenerateSchema(GenerateSchemaEventArgs $event): void
2829
{
2930
$connection = $event->getEntityManager()->getConnection();
3031

31-
foreach ($this->stores as $store) {
32-
if (!$store instanceof DoctrineDbalStore) {
33-
continue;
32+
$storesIterator = new \ArrayIterator($this->stores);
33+
while ($storesIterator->valid()) {
34+
try {
35+
$store = $storesIterator->current();
36+
if (!$store instanceof DoctrineDbalStore) {
37+
continue;
38+
}
39+
40+
$store->configureSchema($event->getSchema(), $this->getIsSameDatabaseChecker($connection));
41+
} catch (InvalidArgumentException) {
42+
// no-op
3443
}
3544

36-
$store->configureSchema($event->getSchema(), $this->getIsSameDatabaseChecker($connection));
45+
$storesIterator->next();
3746
}
3847
}
3948
}

src/Symfony/Bridge/Doctrine/Tests/SchemaListener/LockStoreSchemaListenerTest.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use Doctrine\ORM\Tools\Event\GenerateSchemaEventArgs;
1818
use PHPUnit\Framework\TestCase;
1919
use Symfony\Bridge\Doctrine\SchemaListener\LockStoreSchemaListener;
20+
use Symfony\Component\Lock\Exception\InvalidArgumentException;
2021
use Symfony\Component\Lock\Store\DoctrineDbalStore;
2122

2223
class LockStoreSchemaListenerTest extends TestCase
@@ -39,4 +40,20 @@ public function testPostGenerateSchemaLockPdo()
3940
$subscriber = new LockStoreSchemaListener([$lockStore]);
4041
$subscriber->postGenerateSchema($event);
4142
}
43+
44+
public function testPostGenerateSchemaWithInvalidLockStore()
45+
{
46+
$entityManager = $this->createMock(EntityManagerInterface::class);
47+
$entityManager->expects($this->once())
48+
->method('getConnection')
49+
->willReturn($this->createMock(Connection::class));
50+
$event = new GenerateSchemaEventArgs($entityManager, new Schema());
51+
52+
$subscriber = new LockStoreSchemaListener((static function (): \Generator {
53+
yield $this->createMock(DoctrineDbalStore::class);
54+
55+
throw new InvalidArgumentException('Unsupported Connection');
56+
})());
57+
$subscriber->postGenerateSchema($event);
58+
}
4259
}

0 commit comments

Comments
 (0)
0