public function __invoke(ContainerInterface $container, $requestedName, array $options = null) { $config = $container->get('config'); $config = $config['circlical']['user']; if (!isset($config['doctrine']['entity'])) { throw new ConfigurationException("No user provider is defined. Did you copy the dist config over to your project?"); } $entityClass = $config['doctrine']['entity']; if (!class_exists($entityClass)) { throw new ConfigurationException("The user entity defined does not exist: {$entityClass}"); } if (!in_array(UserInterface::class, class_implements($entityClass))) { throw new ConfigurationException("The user entity must implement " . UserInterface::class); } $mapper = new UserMapper($entityClass); $mapper->setEntityManager($container->get('doctrine.entitymanager.orm_default')); return $mapper; }
public function let(AuthenticationMapper $authenticationMapper, UserMapper $userMapper, User $user) { $hash = password_hash('abc', PASSWORD_DEFAULT); $key = KeyFactory::generateEncryptionKey(); $authenticationData = new Authentication(1, 'userA', $hash, $key->getRawKeyMaterial()); $this->authenticationData = $authenticationData; $orphanAuthData = new Authentication(2, 'orphan', $hash, $key->getRawKeyMaterial()); $authenticationMapper->findByUsername(Argument::any())->willReturn(null); $authenticationMapper->findByUsername('userA')->willReturn($authenticationData); $authenticationMapper->findByUsername('orphan')->willReturn($orphanAuthData); $authenticationMapper->findByUserId(Argument::any())->willReturn(null); $authenticationMapper->findByUserId(1)->willReturn($authenticationData); $authenticationMapper->update($authenticationData)->willReturn(true); $user->getId()->willReturn(1); $userMapper->findByEmail(Argument::any())->willReturn(null); $userMapper->findByEmail('*****@*****.**')->willReturn($user); $userMapper->getUser(Argument::any())->willReturn(null); $userMapper->getUser(1)->willReturn($user); $this->systemEncryptionKey = KeyFactory::generateEncryptionKey(); $this->beConstructedWith($authenticationMapper, $userMapper, $this->systemEncryptionKey->getRawKeyMaterial(), false, false); }