51 $eventMethods = [
'getCustomerCookies',
'__wakeUp'];
52 $sessionMethods = [
'getId',
'getGroupId',
'getCustomerId',
'__wakeUp'];
53 $this->sessionHelperMock = $this->createMock(\
Magento\Persistent\Helper\Session::class);
54 $this->customerRepository = $this->getMockForAbstractClass(
55 \
Magento\Customer\Api\CustomerRepositoryInterface::class,
60 $this->observerMock = $this->createMock(\
Magento\Framework\Event\Observer::class);
61 $this->eventManagerMock = $this->createPartialMock(\
Magento\Framework\Event::class, $eventMethods);
62 $this->sessionMock = $this->createPartialMock(\
Magento\Persistent\Model\Session::class, $sessionMethods);
63 $this->customerMock = $this->getMockForAbstractClass(
64 \
Magento\Customer\Api\Data\CustomerInterface::class,
69 $this->model = new \Magento\Persistent\Observer\UpdateCustomerCookiesObserver(
70 $this->sessionHelperMock,
71 $this->customerRepository
77 $this->sessionHelperMock->expects($this->once())->method(
'isPersistent')->will($this->returnValue(
false));
78 $this->observerMock->expects($this->never())->method(
'getEvent');
79 $this->model->execute($this->observerMock);
86 $cookieMock = $this->createPartialMock(
87 \
Magento\Framework\DataObject::class,
88 [
'setCustomerId',
'setCustomerGroupId',
'__wakeUp']
90 $this->sessionHelperMock->expects($this->once())->method(
'isPersistent')->will($this->returnValue(
true));
92 ->expects($this->once())
94 ->will($this->returnValue($this->eventManagerMock));
95 $this->eventManagerMock
96 ->expects($this->once())
97 ->method(
'getCustomerCookies')
98 ->will($this->returnValue($cookieMock));
99 $this->sessionHelperMock
100 ->expects($this->once())
101 ->method(
'getSession')
102 ->will($this->returnValue($this->sessionMock));
103 $this->sessionMock->expects($this->once())->method(
'getCustomerId')->will($this->returnValue(
$customerId));
104 $this->customerRepository
105 ->expects($this->once())
107 ->will($this->returnValue($this->customerMock));
108 $this->customerMock->expects($this->once())->method(
'getId')->will($this->returnValue(
$customerId));
109 $this->customerMock->expects($this->once())->method(
'getGroupId')->will($this->returnValue($customerGroupId));
110 $cookieMock->expects($this->once())->method(
'setCustomerId')->with(
$customerId)->will($this->returnSelf());
112 ->expects($this->once())
113 ->method(
'setCustomerGroupId')
114 ->with($customerGroupId)
115 ->will($this->returnSelf());
116 $this->model->execute($this->observerMock);
testExecuteWhenSessionNotPersistent()
testExecuteWhenCustomerCookieExist()