Example #1
0
 /**
  * @Transform /^this order made by "([^"]+)"$/
  */
 public function getOrderByCustomer($email)
 {
     $customer = $this->customerRepository->findOneBy(['email' => $email]);
     Assert::notNull($customer, sprintf('Cannot find customer with email %s.', $email));
     $orders = $this->orderRepository->findByCustomer($customer);
     Assert::notEmpty($orders);
     return end($orders);
 }
 function it_obtains_order_and_customer_statistics_from_the_repositories(OrderRepositoryInterface $orderRepository, CustomerRepositoryInterface $customerRepository)
 {
     $expectedStats = new DashboardStatistics(450, 2, 6);
     $orderRepository->getTotalSales()->willReturn(450);
     $orderRepository->count()->willReturn(2);
     $customerRepository->count()->willReturn(6);
     $this->getStatistics()->shouldBeLike($expectedStats);
 }
Example #3
0
 /**
  * @Transform :customer
  */
 public function getOrCreateCustomerByEmail($email)
 {
     /** @var CustomerInterface $customer */
     $customer = $this->customerRepository->findOneBy(['email' => $email]);
     if (null === $customer) {
         $customer = $this->customerFactory->createNew();
         $customer->setEmail($email);
         $this->customerRepository->add($customer);
     }
     return $customer;
 }
Example #4
0
 /**
  * @param string $email
  * @param string $password
  * @param bool $enabled
  * @param string|null $firstName
  * @param string|null $lastName
  */
 private function createCustomerWithUserAccount($email, $password, $enabled = true, $firstName = null, $lastName = null)
 {
     $user = $this->userFactory->createNew();
     /** @var CustomerInterface $customer */
     $customer = $this->customerFactory->createNew();
     $customer->setFirstName($firstName);
     $customer->setLastName($lastName);
     $customer->setEmail($email);
     $user->setUsername($email);
     $user->setPlainPassword($password);
     $user->setEnabled($enabled);
     $customer->setUser($user);
     $this->sharedStorage->set('customer', $customer);
     $this->customerRepository->add($customer);
 }
 function it_provides_new_customer_from_repository_if_it_exists(CustomerInterface $customer, CustomerRepositoryInterface $customerRepository)
 {
     $customerRepository->findOneBy(['email' => '*****@*****.**'])->willReturn($customer);
     $this->getOrCreateCustomerByEmail('*****@*****.**')->shouldReturn($customer);
 }
 /**
  * {@inheritdoc}
  */
 public function getStatistics()
 {
     return new DashboardStatistics($this->orderRepository->getTotalSales(), $this->orderRepository->count(), $this->customerRepository->count());
 }