Skip to content
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

fix EventArgs::getEntityManger deprecation #2639

Merged
merged 6 commits into from
Oct 29, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
8 changes: 8 additions & 0 deletions src/Mapping/Event/Adapter/ORM.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ public function getObjectManager()
throw new \LogicException(sprintf('Event args must be set before calling "%s()".', __METHOD__));
}

if (\method_exists($this->args, 'getObjectManager')) {
DubbleClick marked this conversation as resolved.
Show resolved Hide resolved
return $this->args->getObjectManager();
}

return $this->args->getEntityManager();
}

Expand All @@ -104,6 +108,10 @@ public function getObject(): object
throw new \LogicException(sprintf('Event args must be set before calling "%s()".', __METHOD__));
}

if (\method_exists($this->args, 'getObject')) {
return $this->args->getObject();
}

return $this->args->getEntity();
}

Expand Down
4 changes: 2 additions & 2 deletions tests/Gedmo/Mapping/MappingEventAdapterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@ public function testAdapterBehavior(): void
->disableOriginalConstructor()
->getMock();
$eventArgsMock->expects(static::once())
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe we could even replace these mocks to use a class that is no deprecated, like Doctrine\ORM\Event\PrePersistEventArgs or Doctrine\ORM\Event\PreUpdateEventArgs.

->method('getEntityManager');
->method('getObjectManager');

$eventArgsMock->expects(static::once())
->method('getEntity')
->method('getObject')
->willReturn(new \stdClass());

$eventAdapter = new EventAdapterORM();
Expand Down