resultFactoryMock = $this->getMockBuilder(ResultFactory::class) ->disableOriginalConstructor() ->getMock(); $this->resultRedirectMock = $this->getMockBuilder(Redirect::class) ->disableOriginalConstructor() ->getMock(); $this->subscriptionHandlerMock = $this->getMockBuilder(SubscriptionHandler::class) ->disableOriginalConstructor() ->getMock(); $this->messageManagerMock = $this->getMockBuilder(ManagerInterface::class) ->disableOriginalConstructor() ->getMock(); $this->objectManagerHelper = new ObjectManagerHelper($this); $this->retryController = $this->objectManagerHelper->getObject( Retry::class, [ 'resultFactory' => $this->resultFactoryMock, 'subscriptionHandler' => $this->subscriptionHandlerMock, 'messageManager' => $this->messageManagerMock, ] ); } /** * @return void */ public function testExecute() { $this->resultFactoryMock ->expects($this->once()) ->method('create') ->with(ResultFactory::TYPE_REDIRECT) ->willReturn($this->resultRedirectMock); $this->resultRedirectMock ->expects($this->once()) ->method('setPath') ->with('adminhtml') ->willReturnSelf(); $this->subscriptionHandlerMock ->expects($this->once()) ->method('processEnabled') ->with() ->willReturn(true); $this->assertSame( $this->resultRedirectMock, $this->retryController->execute() ); } /** * @dataProvider executeExceptionsDataProvider * * @param \Exception $exception * @param Phrase $message */ public function testExecuteWithException(\Exception $exception, Phrase $message) { $this->resultFactoryMock ->expects($this->once()) ->method('create') ->with(ResultFactory::TYPE_REDIRECT) ->willReturn($this->resultRedirectMock); $this->resultRedirectMock ->expects($this->once()) ->method('setPath') ->with('adminhtml') ->willReturnSelf(); $this->subscriptionHandlerMock ->expects($this->once()) ->method('processEnabled') ->with() ->willThrowException($exception); $this->messageManagerMock ->expects($this->once()) ->method('addExceptionMessage') ->with($exception, $message); $this->assertSame( $this->resultRedirectMock, $this->retryController->execute() ); } /** * @return array */ public function executeExceptionsDataProvider() { return [ [new LocalizedException(__('TestMessage')), __('TestMessage')], [ new \Exception('TestMessage'), __('Sorry, there has been an error processing your request. Please try again later.') ], ]; } }