requestMock = $this->createMock(\Magento\Framework\App\Request\Http::class); $this->helperMock = $this->createMock(\Magento\Persistent\Helper\Data::class); $this->sessionHelperMock = $this->createMock(\Magento\Persistent\Helper\Session::class); $this->customerSessionMock = $this->createMock(\Magento\Customer\Model\Session::class); $this->observerMock = $this->createMock(\Magento\Framework\Event\Observer::class); $eventMethods = ['getRequest', '__wakeUp']; $this->eventManagerMock = $this->createPartialMock(\Magento\Framework\Event::class, $eventMethods); $this->sessionMock = $this->createMock(\Magento\Persistent\Model\Session::class); $this->model = new \Magento\Persistent\Observer\SynchronizePersistentInfoObserver( $this->helperMock, $this->sessionHelperMock, $this->customerSessionMock ); } public function testSynchronizePersistentInfoWhenPersistentDataNotEnabled() { $this->helperMock->expects($this->once())->method('isEnabled')->will($this->returnValue(false)); $this->sessionHelperMock->expects($this->never())->method('getSession'); $this->model->execute($this->observerMock); } public function testSynchronizePersistentInfoWhenPersistentDataIsEnabled() { $this->helperMock->expects($this->once())->method('isEnabled')->will($this->returnValue(true)); $this->sessionHelperMock->expects($this->once())->method('isPersistent')->will($this->returnValue(true)); $this->sessionHelperMock ->expects($this->once()) ->method('getSession') ->will($this->returnValue($this->sessionMock)); $this->observerMock ->expects($this->once()) ->method('getEvent') ->will($this->returnValue($this->eventManagerMock)); $this->eventManagerMock ->expects($this->once()) ->method('getRequest') ->will($this->returnValue($this->requestMock)); $this->customerSessionMock->expects($this->once())->method('isLoggedIn')->will($this->returnValue(false)); $this->requestMock ->expects($this->once()) ->method('getFullActionName') ->will($this->returnValue('customer_account_logout')); $this->sessionMock->expects($this->once())->method('save'); $this->model->execute($this->observerMock); } }