Skip to content

Commit

Permalink
Make getObjectManager protected (#423)
Browse files Browse the repository at this point in the history
  • Loading branch information
VincentLanglet authored May 29, 2022
1 parent 120d25e commit bed94df
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 21 deletions.
40 changes: 20 additions & 20 deletions src/Model/BaseManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,26 +34,6 @@ public function __construct(
) {
}

/**
* @throws \RuntimeException
*/
public function getObjectManager(): ObjectManager
{
$manager = $this->registry->getManagerForClass($this->class);

if (null === $manager) {
throw new \RuntimeException(sprintf(
'Unable to find the mapping information for the class %s.'
.' Please check the `auto_mapping` option'
.' (http://symfony.com/doc/current/reference/configuration/doctrine.html#configuration-overview)'
.' or add the bundle to the `mappings` section in the doctrine configuration.',
$this->class
));
}

return $manager;
}

public function getClass(): string
{
return $this->class;
Expand Down Expand Up @@ -138,4 +118,24 @@ protected function checkObject(object $object): void
));
}
}

/**
* @throws \RuntimeException
*/
protected function getObjectManager(): ObjectManager
{
$manager = $this->registry->getManagerForClass($this->class);

if (null === $manager) {
throw new \RuntimeException(sprintf(
'Unable to find the mapping information for the class %s.'
.' Please check the `auto_mapping` option'
.' (http://symfony.com/doc/current/reference/configuration/doctrine.html#configuration-overview)'
.' or add the bundle to the `mappings` section in the doctrine configuration.',
$this->class
));
}

return $manager;
}
}
2 changes: 1 addition & 1 deletion tests/Entity/BaseEntityManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public function testExceptionOnNonMappedEntity(): void

$this->registry->expects(static::once())->method('getManagerForClass')->willReturn(null);

$this->manager->getObjectManager();
$this->manager->clear(); // To trigger a getObjectManager call
}

public function testGetRepository(): void
Expand Down

0 comments on commit bed94df

Please sign in to comment.