File tree Expand file tree Collapse file tree 2 files changed +30
-4
lines changed Expand file tree Collapse file tree 2 files changed +30
-4
lines changed Original file line number Diff line number Diff line change 12
12
namespace Symfony \Bridge \Doctrine \SchemaListener ;
13
13
14
14
use Doctrine \ORM \Tools \Event \GenerateSchemaEventArgs ;
15
+ use Symfony \Component \Lock \Exception \InvalidArgumentException ;
15
16
use Symfony \Component \Lock \PersistingStoreInterface ;
16
17
use Symfony \Component \Lock \Store \DoctrineDbalStore ;
17
18
@@ -28,12 +29,20 @@ public function postGenerateSchema(GenerateSchemaEventArgs $event): void
28
29
{
29
30
$ connection = $ event ->getEntityManager ()->getConnection ();
30
31
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
34
43
}
35
44
36
- $ store -> configureSchema ( $ event -> getSchema (), $ this -> getIsSameDatabaseChecker ( $ connection ) );
45
+ $ storesIterator -> next ( );
37
46
}
38
47
}
39
48
}
Original file line number Diff line number Diff line change 17
17
use Doctrine \ORM \Tools \Event \GenerateSchemaEventArgs ;
18
18
use PHPUnit \Framework \TestCase ;
19
19
use Symfony \Bridge \Doctrine \SchemaListener \LockStoreSchemaListener ;
20
+ use Symfony \Component \Lock \Exception \InvalidArgumentException ;
20
21
use Symfony \Component \Lock \Store \DoctrineDbalStore ;
21
22
22
23
class LockStoreSchemaListenerTest extends TestCase
@@ -39,4 +40,20 @@ public function testPostGenerateSchemaLockPdo()
39
40
$ subscriber = new LockStoreSchemaListener ([$ lockStore ]);
40
41
$ subscriber ->postGenerateSchema ($ event );
41
42
}
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
+ }
42
59
}
You can’t perform that action at this time.
0 commit comments