Skip to content

Commit b27b15d

Browse files
[DoctrineBridge] Ignore invalid stores in LockStoreSchemaListener raised by StoreFactory
1 parent 594263c commit b27b15d

File tree

2 files changed

+30
-4
lines changed

2 files changed

+30
-4
lines changed

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
}

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)