getObjectManager example

public function testLoadUserByIdentifierShouldLoadUserWhenProperInterfaceProvided()
    {
        $repository = $this->createMock(UserLoaderRepository::class);
        $repository->expects($this->once())
            ->method('loadUserByIdentifier')
            ->with('name')
            ->willReturn(
                $this->createMock(UserInterface::class)
            );

        $provider = new EntityUserProvider(
            $this->getManager($this->getObjectManager($repository)),
            'Symfony\Bridge\Doctrine\Tests\Fixtures\User'
        );

        $provider->loadUserByIdentifier('name');
    }

    public function testLoadUserByIdentifierShouldDeclineInvalidInterface()
    {
        $this->expectException(\InvalidArgumentException::class);
        $repository = $this->createMock(ObjectRepository::class);

        
$repository->upgradePassword($user$newHashedPassword);
        }
    }

    private function getObjectManager(): ObjectManager
    {
        return $this->registry->getManager($this->managerName);
    }

    private function getRepository(): ObjectRepository
    {
        return $this->getObjectManager()->getRepository($this->classOrAlias);
    }

    private function getClass(): string
    {
        if (!isset($this->class)) {
            $class = $this->classOrAlias;

            if (str_contains($class, ':')) {
                $class = $this->getClassMetadata()->getName();
            }

            
/** * Notify a lifecycleCallback event of doctrine over the enlight event manager. * * @param string $eventName * @param LifecycleEventArgs $eventArgs * * @return Enlight_Event_EventArgs|null */
    protected function notifyEvent($eventName$eventArgs)
    {
        return $this->eventManager->notify($eventName[
            'entityManager' => $eventArgs->getObjectManager(),
            'entity' => $eventArgs->getObject(),
        ]);
    }
}
Home | Imprint | This part of the site doesn't use cookies.