Skip to content

Commit

Permalink
Handle mapping without mappedBy
Browse files Browse the repository at this point in the history
  • Loading branch information
VincentLanglet committed Aug 22, 2020
1 parent f46719b commit 8d3cbdb
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/Manipulator/ObjectManipulator.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public static function setObject(
object $object,
FieldDescriptionInterface $parentFieldDescription
): object {
$mappedBy = $parentFieldDescription->getAssociationMapping()['mappedBy'];
$mappedBy = $parentFieldDescription->getAssociationMapping()['mappedBy'] ?? null;
if (null === $mappedBy) {
return $instance;
}
Expand Down
10 changes: 9 additions & 1 deletion tests/Manipulator/ObjectManipulatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,14 +88,22 @@ public function testSetObject(): void
ObjectManipulator::setObject($instance, $object, $fieldDescription);
}

public function testSetObjectWithoutMappedBy(): void
public function testSetObjectWithNullMapped(): void
{
$fieldDescription = $this->createMock(FieldDescriptionInterface::class);
$fieldDescription->expects($this->once())->method('getAssociationMapping')->willReturn(['mappedBy' => null]);

ObjectManipulator::setObject(new \stdClass(), new \stdClass(), $fieldDescription);
}

public function testSetObjectWithoutMappedBy(): void
{
$fieldDescription = $this->createMock(FieldDescriptionInterface::class);
$fieldDescription->expects($this->once())->method('getAssociationMapping')->willReturn([]);

ObjectManipulator::setObject(new \stdClass(), new \stdClass(), $fieldDescription);
}

public function testSetObjectWithParentAssociation(): void
{
$fieldDescription = $this->createMock(FieldDescriptionInterface::class);
Expand Down

0 comments on commit 8d3cbdb

Please sign in to comment.