Skip to content

Commit a744e18

Browse files
julienfalquealanpoulain
authored andcommitted
Fix purging HTTP cache for unreadable relations
1 parent 4cc8871 commit a744e18

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
@@ -125,7 +125,9 @@ private function gatherRelationTags(EntityManagerInterface $em, $entity): void
125125
{
126126
$associationMappings = $em->getClassMetadata(ClassUtils::getClass($entity))->getAssociationMappings();
127127
foreach (array_keys($associationMappings) as $property) {
128-
$this->addTagsFor($this->propertyAccessor->getValue($entity, $property));
128+
if ($this->propertyAccessor->isReadable($entity, $property)) {
129+
$this->addTagsFor($this->propertyAccessor->getValue($entity, $property));
130+
}
129131
}
130132
}
131133

tests/Bridge/Doctrine/EventListener/PurgeHttpCacheListenerTest.php

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

3334
/**
3435
* @author Kévin Dunglas <[email protected]>
@@ -78,11 +79,22 @@ public function testOnFlush()
7879

7980
$emProphecy = $this->prophesize(EntityManagerInterface::class);
8081
$emProphecy->getUnitOfWork()->willReturn($uowProphecy->reveal())->shouldBeCalled();
81-
$emProphecy->getClassMetadata(Dummy::class)->willReturn(new ClassMetadata(Dummy::class))->shouldBeCalled();
82+
$dummyClassMetadata = new ClassMetadata(Dummy::class);
83+
$dummyClassMetadata->associationMappings = [
84+
'relatedDummy' => [],
85+
'relatedOwningDummy' => [],
86+
];
87+
$emProphecy->getClassMetadata(Dummy::class)->willReturn($dummyClassMetadata)->shouldBeCalled();
8288
$emProphecy->getClassMetadata(DummyNoGetOperation::class)->willReturn(new ClassMetadata(DummyNoGetOperation::class))->shouldBeCalled();
8389
$eventArgs = new OnFlushEventArgs($emProphecy->reveal());
8490

85-
$listener = new PurgeHttpCacheListener($purgerProphecy->reveal(), $iriConverterProphecy->reveal(), $resourceClassResolverProphecy->reveal());
91+
$propertyAccessorProphecy = $this->prophesize(PropertyAccessorInterface::class);
92+
$propertyAccessorProphecy->isReadable(Argument::type(Dummy::class), 'relatedDummy')->willReturn(true);
93+
$propertyAccessorProphecy->isReadable(Argument::type(Dummy::class), 'relatedOwningDummy')->willReturn(false);
94+
$propertyAccessorProphecy->getValue(Argument::type(Dummy::class), 'relatedDummy')->shouldBeCalled();
95+
$propertyAccessorProphecy->getValue(Argument::type(Dummy::class), 'relatedOwningDummy')->shouldNotBeCalled();
96+
97+
$listener = new PurgeHttpCacheListener($purgerProphecy->reveal(), $iriConverterProphecy->reveal(), $resourceClassResolverProphecy->reveal(), $propertyAccessorProphecy->reveal());
8698
$listener->onFlush($eventArgs);
8799
$listener->postFlush();
88100
}

0 commit comments

Comments
 (0)