Skip to content

Commit 6773a99

Browse files
committed
Fix purging HTTP cache for unreadable relations
1 parent 6907b51 commit 6773a99

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

src/Bridge/Doctrine/EventListener/PurgeHttpCacheListener.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,9 @@ private function gatherRelationTags(EntityManagerInterface $em, $entity): void
126126
{
127127
$associationMappings = $em->getClassMetadata(ClassUtils::getClass($entity))->getAssociationMappings();
128128
foreach (array_keys($associationMappings) as $property) {
129-
$this->addTagsFor($this->propertyAccessor->getValue($entity, $property));
129+
if ($this->propertyAccessor->isReadable($entity, $property)) {
130+
$this->addTagsFor($this->propertyAccessor->getValue($entity, $property));
131+
}
130132
}
131133
}
132134

tests/Bridge/Doctrine/EventListener/PurgeHttpCacheListenerTest.php

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
use Doctrine\ORM\UnitOfWork;
2929
use PHPUnit\Framework\TestCase;
3030
use Prophecy\Argument;
31+
use Symfony\Component\PropertyAccess\PropertyAccessorInterface;
3132

3233
/**
3334
* @author Kévin Dunglas <[email protected]>
@@ -75,11 +76,22 @@ public function testOnFlush()
7576

7677
$emProphecy = $this->prophesize(EntityManagerInterface::class);
7778
$emProphecy->getUnitOfWork()->willReturn($uowProphecy->reveal())->shouldBeCalled();
78-
$emProphecy->getClassMetadata(Dummy::class)->willReturn(new ClassMetadata(Dummy::class))->shouldBeCalled();
79+
$dummyClassMetadata = new ClassMetadata(Dummy::class);
80+
$dummyClassMetadata->associationMappings = [
81+
'relatedDummy' => [],
82+
'relatedOwningDummy' => [],
83+
];
84+
$emProphecy->getClassMetadata(Dummy::class)->willReturn($dummyClassMetadata)->shouldBeCalled();
7985
$emProphecy->getClassMetadata(DummyNoGetOperation::class)->willReturn(new ClassMetadata(DummyNoGetOperation::class))->shouldBeCalled();
8086
$eventArgs = new OnFlushEventArgs($emProphecy->reveal());
8187

82-
$listener = new PurgeHttpCacheListener($purgerProphecy->reveal(), $iriConverterProphecy->reveal(), $resourceClassResolverProphecy->reveal());
88+
$propertyAccessorProphecy = $this->prophesize(PropertyAccessorInterface::class);
89+
$propertyAccessorProphecy->isReadable(Argument::type(Dummy::class), 'relatedDummy')->willReturn(true);
90+
$propertyAccessorProphecy->isReadable(Argument::type(Dummy::class), 'relatedOwningDummy')->willReturn(false);
91+
$propertyAccessorProphecy->getValue(Argument::type(Dummy::class), 'relatedDummy')->shouldBeCalled();
92+
$propertyAccessorProphecy->getValue(Argument::type(Dummy::class), 'relatedOwningDummy')->shouldNotBeCalled();
93+
94+
$listener = new PurgeHttpCacheListener($purgerProphecy->reveal(), $iriConverterProphecy->reveal(), $resourceClassResolverProphecy->reveal(), $propertyAccessorProphecy->reveal());
8395
$listener->onFlush($eventArgs);
8496
$listener->postFlush();
8597
}

0 commit comments

Comments
 (0)