Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[DoctrineBridge] Ignore invalid stores in LockStoreSchemaListener raised by StoreFactory #50761

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
namespace Symfony\Bridge\Doctrine\SchemaListener;

use Doctrine\ORM\Tools\Event\GenerateSchemaEventArgs;
use Symfony\Component\Lock\Exception\InvalidArgumentException;
use Symfony\Component\Lock\PersistingStoreInterface;
use Symfony\Component\Lock\Store\DoctrineDbalStore;

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

foreach ($this->stores as $store) {
if (!$store instanceof DoctrineDbalStore) {
continue;
$storesIterator = new \ArrayIterator($this->stores);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be IteratorIterator ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hum, no, because arrays

while ($storesIterator->valid()) {
try {
$store = $storesIterator->current();
if (!$store instanceof DoctrineDbalStore) {
continue;
}

$store->configureSchema($event->getSchema(), $this->getIsSameDatabaseChecker($connection));
} catch (InvalidArgumentException) {
// no-op
}

$store->configureSchema($event->getSchema(), $this->getIsSameDatabaseChecker($connection));
$storesIterator->next();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use Doctrine\ORM\Tools\Event\GenerateSchemaEventArgs;
use PHPUnit\Framework\TestCase;
use Symfony\Bridge\Doctrine\SchemaListener\LockStoreSchemaListener;
use Symfony\Component\Lock\Exception\InvalidArgumentException;
use Symfony\Component\Lock\Store\DoctrineDbalStore;

class LockStoreSchemaListenerTest extends TestCase
Expand All @@ -39,4 +40,20 @@ public function testPostGenerateSchemaLockPdo()
$subscriber = new LockStoreSchemaListener([$lockStore]);
$subscriber->postGenerateSchema($event);
}

public function testPostGenerateSchemaWithInvalidLockStore()
{
$entityManager = $this->createMock(EntityManagerInterface::class);
$entityManager->expects($this->once())
->method('getConnection')
->willReturn($this->createMock(Connection::class));
$event = new GenerateSchemaEventArgs($entityManager, new Schema());

$subscriber = new LockStoreSchemaListener((static function (): \Generator {
yield $this->createMock(DoctrineDbalStore::class);

throw new InvalidArgumentException('Unsupported Connection');
})());
$subscriber->postGenerateSchema($event);
}
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.