sessionMock = $this->getMockBuilder(Session::class) ->disableOriginalConstructor() ->setMethods(['getCustomerId', 'setCustomerData', 'setCustomerGroupId', 'regenerateId']) ->getMock(); $this->notificationStorageMock = $this->getMockBuilder(NotificationStorage::class) ->disableOriginalConstructor() ->setMethods(['isExists', 'remove']) ->getMock(); $this->customerRepositoryMock = $this->getMockBuilder(CustomerRepositoryInterface::class) ->getMockForAbstractClass(); $this->abstractActionMock = $this->getMockBuilder(AbstractAction::class) ->disableOriginalConstructor() ->getMockForAbstractClass(); $this->requestMock = $this->getMockBuilder(RequestInterface::class) ->setMethods(['isPost']) ->getMockForAbstractClass(); $this->appStateMock = $this->getMockBuilder(State::class) ->disableOriginalConstructor() ->setMethods(['getAreaCode']) ->getMock(); $this->loggerMock = $this->getMockForAbstractClass(LoggerInterface::class); $this->appStateMock->method('getAreaCode')->willReturn(Area::AREA_FRONTEND); $this->requestMock->method('isPost')->willReturn(true); $this->sessionMock->method('getCustomerId')->willReturn(self::$customerId); $this->notificationStorageMock->expects($this->any()) ->method('isExists') ->with(NotificationStorage::UPDATE_CUSTOMER_SESSION, self::$customerId) ->willReturn(true); $this->plugin = new CustomerNotification( $this->sessionMock, $this->notificationStorageMock, $this->appStateMock, $this->customerRepositoryMock, $this->loggerMock ); } public function testBeforeDispatch() { $customerGroupId =1; $customerMock = $this->getMockForAbstractClass(CustomerInterface::class); $customerMock->method('getGroupId')->willReturn($customerGroupId); $customerMock->method('getId')->willReturn(self::$customerId); $this->customerRepositoryMock->expects($this->once()) ->method('getById') ->with(self::$customerId) ->willReturn($customerMock); $this->notificationStorageMock->expects($this->once()) ->method('remove') ->with(NotificationStorage::UPDATE_CUSTOMER_SESSION, self::$customerId); $this->sessionMock->expects($this->once())->method('setCustomerData')->with($customerMock); $this->sessionMock->expects($this->once())->method('setCustomerGroupId')->with($customerGroupId); $this->sessionMock->expects($this->once())->method('regenerateId'); $this->plugin->beforeDispatch($this->abstractActionMock, $this->requestMock); } public function testBeforeDispatchWithNoCustomerFound() { $this->customerRepositoryMock->method('getById') ->with(self::$customerId) ->willThrowException(new NoSuchEntityException()); $this->loggerMock->expects($this->once()) ->method('error'); $this->plugin->beforeDispatch($this->abstractActionMock, $this->requestMock); } }