/** * @param UuidInterface $cartId * @param UuidInterface $userId * @throws EntityNotFoundException */ public function setUserById(UuidInterface $cartId, UuidInterface $userId) { $user = $this->userRepository->findOneById($userId); $cart = $this->cartRepository->findOneById($cartId); $cart->setUser($user); $this->cartRepository->update($cart); }
public function testChangePassword() { $user1 = $this->dummyData->getUser(); $this->userRepository->shouldReceive('findOneById')->with($user1->getid())->andReturn($user1)->once(); $this->userRepository->shouldReceive('update')->once(); $newPassword = '******'; $this->userService->changePassword($user1->getId(), $newPassword); $this->assertTrue($user1->verifyPassword($newPassword)); }
public function testSetUserById() { $user = $this->dummyData->getUser(); $this->userRepository->shouldReceive('findOneById')->with($user->getId())->andReturn($user)->once(); $cart = $this->getCartThatRepositoryWillFind(); $this->cartRepositoryShouldUpdateOnce($cart); $this->cartService->setUserById($cart->getId(), $user->getId()); $this->assertSame($user, $cart->getUser()); }
/** * @param Iterator $iterator * @return ImportResult */ public function import(Iterator $iterator) { $importResult = new ImportResult(); foreach ($iterator as $key => $row) { if ($key < 2 && $row[0] === 'order_ref') { continue; } $externalId = $row[0]; $date = $row[1]; $userExternalId = $row[2]; $subtotal = $this->convertDollarToCents($row[3]); $tax = $this->convertDollarToCents($row[4]); $total = $this->convertDollarToCents($row[5]); $cartTotal = new CartTotal(); $cartTotal->subtotal = $subtotal; $cartTotal->tax = $tax; $cartTotal->total = $total; $order = new Order(); $order->setIp4(null); $order->setExternalId($externalId); $order->setTotal($cartTotal); $order->setCreated(new DateTime($date)); if ($userExternalId !== null) { $user = $this->userRepository->findOneByExternalId($userExternalId); if ($user !== null) { $order->setUser($user); } } try { $this->throwValidationErrors($order); $this->orderRepository->create($order); $importResult->incrementSuccess(); } catch (KommerceException $e) { $importResult->addFailedRow($row); $importResult->addErrorMessage($e->getMessage()); } } return $importResult; }
/** * @param string $email * @param string $remoteIp * @return User * @throws UserLoginException */ private function getUserOrAssertAndRecordLoginFailure($email, $remoteIp) { try { $user = $this->userRepository->findOneByEmail($email); } catch (EntityNotFoundException $e) { $this->recordLogin($email, $remoteIp, UserLoginResultType::fail()); throw UserLoginException::userNotFound(); } if (!$user->getStatus()->isActive()) { $this->recordLogin($email, $remoteIp, UserLoginResultType::fail()); throw UserLoginException::userNotActive(); } return $user; }
/** * @param Iterator $iterator * @return ImportResult */ public function import(Iterator $iterator) { $importResult = new ImportResult(); foreach ($iterator as $key => $row) { if ($key < 2 && $row[0] === 'id') { continue; } $externalId = $this->extractNull($row[0]); $name = $this->extractNull($row[1]); $address = $this->extractNull($row[2]); $zip5 = $this->extractNull($row[3]); $city = $this->extractNull($row[4]); $phone = $this->extractNull($row[5]); $fax = $this->extractNull($row[6]); $url = $this->extractNull($row[7]); $email = $this->extractNull($row[8]); $firstName = $this->parseFirstName($name); $lastName = $this->parseLastName($name); $user = new User(); $user->setExternalId($externalId); $user->setFirstName($firstName); $user->setLastName($lastName); if (!empty($email)) { $user->setEmail($email); } try { $this->throwValidationErrors($user); $this->userRepository->create($user); $importResult->incrementSuccess(); } catch (KommerceException $e) { $importResult->addFailedRow($row); $importResult->addErrorMessage($e->getMessage()); } } return $importResult; }
public function testGetQueryBuilder() { $queryBuilder = $this->userRepository->getQueryBuilder(); $this->assertTrue($queryBuilder instanceof QueryBuilder); }
public function testFindOneByEmailThrowsException() { $this->setExpectedException(EntityNotFoundException::class, 'User not found'); $this->userRepository->findOneByEmail('*****@*****.**'); }