customerSessionMock = $this->createMock(\Magento\Customer\Model\Session::class); $this->sessionHelperMock = $this->createMock(\Magento\Persistent\Helper\Session::class); $this->helperMock = $this->createMock(\Magento\Persistent\Helper\Data::class); $this->observerMock = $this->createMock(\Magento\Framework\Event\Observer::class); $this->eventMock = $this->createPartialMock(\Magento\Framework\Event::class, $eventMethods); $this->actionMock = $this->createMock(\Magento\Persistent\Controller\Index::class); $this->observerMock->expects($this->once())->method('getEvent')->will($this->returnValue($this->eventMock)); $this->model = new \Magento\Persistent\Observer\PreventClearCheckoutSessionObserver( $this->sessionHelperMock, $this->helperMock, $this->customerSessionMock ); } public function testExecuteWhenSessionIsPersist() { $this->eventMock ->expects($this->once()) ->method('getControllerAction') ->will($this->returnValue($this->actionMock)); $this->sessionHelperMock->expects($this->once())->method('isPersistent')->will($this->returnValue(true)); $this->customerSessionMock->expects($this->once())->method('isLoggedIn')->will($this->returnValue(false)); $this->helperMock->expects($this->never())->method('isShoppingCartPersist'); $this->actionMock->expects($this->once())->method('setClearCheckoutSession')->with(false); $this->model->execute($this->observerMock); } public function testExecuteWhenShoppingCartIsPersist() { $this->eventMock ->expects($this->once()) ->method('getControllerAction') ->will($this->returnValue($this->actionMock)); $this->sessionHelperMock->expects($this->once())->method('isPersistent')->will($this->returnValue(true)); $this->customerSessionMock->expects($this->once())->method('isLoggedIn')->will($this->returnValue(true)); $this->helperMock->expects($this->once())->method('isShoppingCartPersist')->will($this->returnValue(false)); $this->actionMock->expects($this->once())->method('setClearCheckoutSession')->with(false); $this->model->execute($this->observerMock); } public function testExecuteWhenActionIsNotPersistent() { $this->eventMock ->expects($this->once()) ->method('getControllerAction'); $this->sessionHelperMock->expects($this->never())->method('isPersistent'); $this->actionMock->expects($this->never())->method('setClearCheckoutSession'); $this->model->execute($this->observerMock); } }