quoteMock = $this->createPartialMock(\Magento\Quote\Model\Quote::class, $quoteMethods); $this->helperMock = $this->createMock(\Magento\Persistent\Helper\Data::class); $this->sessionHelperMock = $this->createMock(\Magento\Persistent\Helper\Session::class); $this->eventManagerMock = $this->createPartialMock(\Magento\Framework\Event::class, $eventMethods); $this->customerSessionMock = $this->createMock(\Magento\Customer\Model\Session::class); $this->observerMock = $this->createMock(\Magento\Framework\Event\Observer::class); $this->quoteManagerMock = $this->createMock(\Magento\Persistent\Model\QuoteManager::class); $this->model = new \Magento\Persistent\Observer\SetQuotePersistentDataObserver( $this->sessionHelperMock, $this->helperMock, $this->quoteManagerMock, $this->customerSessionMock ); } public function testExecuteWhenSessionIsNotPersistent() { $this->sessionHelperMock->expects($this->once())->method('isPersistent')->will($this->returnValue(false)); $this->observerMock->expects($this->never())->method('getEvent'); $this->model->execute($this->observerMock); } public function testExecuteWhenQuoteNotExist() { $this->sessionHelperMock->expects($this->once())->method('isPersistent')->will($this->returnValue(true)); $this->observerMock ->expects($this->once()) ->method('getEvent') ->will($this->returnValue($this->eventManagerMock)); $this->eventManagerMock->expects($this->once())->method('getQuote'); $this->customerSessionMock->expects($this->never())->method('isLoggedIn'); $this->model->execute($this->observerMock); } public function testExecuteWhenSessionIsPersistent() { $this->sessionHelperMock->expects($this->exactly(2))->method('isPersistent')->will($this->returnValue(true)); $this->observerMock ->expects($this->once()) ->method('getEvent') ->will($this->returnValue($this->eventManagerMock)); $this->eventManagerMock ->expects($this->once()) ->method('getQuote') ->will($this->returnValue($this->quoteMock)); $this->customerSessionMock->expects($this->once())->method('isLoggedIn')->will($this->returnValue(false)); $this->helperMock->expects($this->once())->method('isShoppingCartPersist')->will($this->returnValue(false)); $this->quoteManagerMock->expects($this->once())->method('isPersistent')->will($this->returnValue(true)); $this->quoteMock->expects($this->once())->method('setIsPersistent')->with(true); $this->model->execute($this->observerMock); } }