quoteMock = $this->getMockBuilder(Quote::class) ->addMethods(['setIsPersistent']) ->onlyMethods(['setIsActive']) ->disableOriginalConstructor() ->getMock(); $this->helperMock = $this->createMock(Data::class); $this->sessionHelperMock = $this->createMock(Session::class); $this->eventManagerMock = $this->getMockBuilder(Event::class) ->addMethods(['getQuote']) ->disableOriginalConstructor() ->getMock(); $this->customerSessionMock = $this->createMock(\Magento\Customer\Model\Session::class); $this->observerMock = $this->createMock(Observer::class); $this->quoteManagerMock = $this->createMock(QuoteManager::class); $this->model = new SetQuotePersistentDataObserver( $this->sessionHelperMock, $this->helperMock, $this->quoteManagerMock, $this->customerSessionMock ); } public function testExecuteWhenSessionIsNotPersistent() { $this->sessionHelperMock->expects($this->once())->method('isPersistent')->willReturn(false); $this->observerMock->expects($this->never())->method('getEvent'); $this->model->execute($this->observerMock); } public function testExecuteWhenQuoteNotExist() { $this->sessionHelperMock->expects($this->once())->method('isPersistent')->willReturn(true); $this->observerMock ->expects($this->once()) ->method('getEvent') ->willReturn($this->eventManagerMock); $this->eventManagerMock->expects($this->once())->method('getQuote'); $this->model->execute($this->observerMock); } public function testExecuteWhenSessionIsPersistent() { $this->sessionHelperMock->expects($this->exactly(2))->method('isPersistent')->willReturn(true); $this->observerMock ->expects($this->once()) ->method('getEvent') ->willReturn($this->eventManagerMock); $this->eventManagerMock ->expects($this->once()) ->method('getQuote') ->willReturn($this->quoteMock); $this->helperMock->expects($this->once())->method('isShoppingCartPersist')->willReturn(true); $this->quoteManagerMock->expects($this->once())->method('isPersistent')->willReturn(true); $this->quoteMock->expects($this->once())->method('setIsPersistent')->with(true); $this->model->execute($this->observerMock); } }