/**
  * @param Customer $customer
  *
  * @return array
  *
  * @throws UnsupportedClassException
  */
 public function serialize($customer) : array
 {
     if (!$customer instanceof Customer) {
         throw new UnsupportedClassException();
     }
     return ['id' => $customer->getId(), 'name' => $customer->getName()];
 }
 public function it_add_pageview_with_created_anonymous_customer(CustomerEventRepository $repository, \TDCrm\Component\CustomerEvent\App\Factory $factory, PageviewEvent $event, AnonymousCustomerFactory $anonCustomerFactory, Customer $anonymousCustomer, CustomerRepository $anonCustomerRepo, TrackedCustomerStorage $trackedCustomerStorage)
 {
     $command = new AddNewPageviewEventCommand($trackedCustomerStorage->getWrappedObject());
     $command->eventId = self::EVENT_ID;
     $command->ip = self::IP;
     $command->url = self::URL;
     $anonymousCustomer->getId()->willReturn(self::ANONYMOUS_CUSTOMER_ID);
     $factory->createPageview(['id' => self::EVENT_ID, 'customerId' => null, 'anonymousCustomerId' => self::ANONYMOUS_CUSTOMER_ID, 'url' => self::URL, 'ip' => self::IP, 'referrer' => null])->willReturn($event);
     $anonCustomerFactory->create()->willReturn($anonymousCustomer)->shouldBeCalled();
     $anonCustomerRepo->add($anonymousCustomer)->shouldBeCalled();
     $repository->add($event)->shouldBeCalled();
     $trackedCustomerStorage->saveAnonymous(self::ANONYMOUS_CUSTOMER_ID)->shouldBeCalled();
     $this->handle($command);
 }
 public function findAllByCustomer(Customer $customer) : array
 {
     return $this->storage->findAllBy(['type' => OrderEvent::TYPE, 'customerId' => $customer->getId()]);
 }
 public function findAllByCustomer(Customer $customer)
 {
     $customerField = $customer->isAnonymous() ? 'anonymousCustomerId' : 'customerId';
     return $this->storage->findAllBy([$customerField => $customer->getId()]);
 }
 public function findAllWithReferrer(Customer $customer) : array
 {
     $customerIdField = $customer->isAnonymous() ? 'anonymousCustomerId' : 'customerId';
     return $this->storage->findAllBy(['type' => PageviewEvent::TYPE, 'data' => new ArrayValuesContains([PageviewEvent::REFERRER_FIELD => new NotEmpty()]), $customerIdField => $customer->getId()]);
 }