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