customerSessionMock = $this->createMock(Session::class); $this->observerMock = $this->createMock(Observer::class); $this->quoteManagerMock = $this->createMock(QuoteManager::class); $this->requestMock = $this->getMockForAbstractClass(RequestInterface::class); $this->model = new CustomerAuthenticatedEventObserver( $this->customerSessionMock, $this->requestMock, $this->quoteManagerMock ); } public function testExecute() { $this->customerSessionMock ->expects($this->once()) ->method('setCustomerId') ->with(null)->willReturnSelf(); $this->customerSessionMock ->expects($this->once()) ->method('setCustomerGroupId') ->with(null)->willReturnSelf(); $this->requestMock ->expects($this->once()) ->method('getParam') ->with('context') ->willReturn('not_checkout'); $this->quoteManagerMock->expects($this->once())->method('expire'); $this->quoteManagerMock->expects($this->never())->method('setGuest'); $this->model->execute($this->observerMock); } public function testExecuteDuringCheckout() { $this->customerSessionMock ->expects($this->once()) ->method('setCustomerId') ->with(null)->willReturnSelf(); $this->customerSessionMock ->expects($this->once()) ->method('setCustomerGroupId') ->with(null)->willReturnSelf(); $this->requestMock ->expects($this->once()) ->method('getParam') ->with('context') ->willReturn('checkout'); $this->quoteManagerMock->expects($this->never())->method('expire'); $this->quoteManagerMock->expects($this->once())->method('setGuest'); $this->model->execute($this->observerMock); } }