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] Fix the LockStoreSchemaListener #57944

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 1 commit into from
Aug 13, 2024
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,7 +12,6 @@
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 @@ -30,20 +29,12 @@ public function postGenerateSchema(GenerateSchemaEventArgs $event): void
{
$connection = $event->getEntityManager()->getConnection();

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

$store->configureSchema($event->getSchema(), $this->getIsSameDatabaseChecker($connection));
} catch (InvalidArgumentException) {
// no-op
foreach ($this->stores as $store) {
if (!$store instanceof DoctrineDbalStore) {
continue;
}

$storesIterator->next();
$store->configureSchema($event->getSchema(), $this->getIsSameDatabaseChecker($connection));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
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 @@ -37,23 +36,7 @@ public function testPostGenerateSchemaLockPdo()
->method('configureSchema')
->with($schema, fn () => true);

$subscriber = new LockStoreSchemaListener([$lockStore]);
$subscriber->postGenerateSchema($event);
}

public function testPostGenerateSchemaWithInvalidLockStore()
Copy link
Member

Choose a reason for hiding this comment

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

Maybe I'm a bit late to the party and missed an important part of the discussion of the previous PR. But… could you recap why we delete a test for a bugfix? I would've expected a new test instead that covers the bug that we want to fix.

Copy link
Member

Choose a reason for hiding this comment

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

@MatTheCat wrote done his reasoning here: #54407 (comment)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

(I updated the testPostGenerateSchemaLockPdo so that it would fail.)

Copy link
Contributor Author

@MatTheCat MatTheCat Aug 8, 2024

Choose a reason for hiding this comment

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

You can see testPostGenerateSchemaWithInvalidLockStore is wrong because the function creating the generator is static, but its body is using $this. That means it only passes because the generator is not started and the LockStoreSchemaListener does not get any store.

{
$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 = new LockStoreSchemaListener((static fn () => yield $lockStore)());
$subscriber->postGenerateSchema($event);
}
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.