123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156 |
- <?php
- /**
- * Copyright © Magento, Inc. All rights reserved.
- * See COPYING.txt for license details.
- */
- namespace Magento\Analytics\Test\Unit\Controller\Adminhtml\Subscription;
- use Magento\Analytics\Controller\Adminhtml\Subscription\Retry;
- use Magento\Analytics\Model\Config\Backend\Enabled\SubscriptionHandler;
- use Magento\Framework\Controller\Result\Redirect;
- use Magento\Framework\Controller\ResultFactory;
- use Magento\Framework\Exception\LocalizedException;
- use Magento\Framework\Message\ManagerInterface;
- use Magento\Framework\Phrase;
- use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper;
- class RetryTest extends \PHPUnit\Framework\TestCase
- {
- /**
- * @var ResultFactory|\PHPUnit_Framework_MockObject_MockObject
- */
- private $resultFactoryMock;
- /**
- * @var Redirect|\PHPUnit_Framework_MockObject_MockObject
- */
- private $resultRedirectMock;
- /**
- * @var SubscriptionHandler|\PHPUnit_Framework_MockObject_MockObject
- */
- private $subscriptionHandlerMock;
- /**
- * @var ManagerInterface|\PHPUnit_Framework_MockObject_MockObject
- */
- private $messageManagerMock;
- /**
- * @var ObjectManagerHelper
- */
- private $objectManagerHelper;
- /**
- * @var Retry
- */
- private $retryController;
- /**
- * @return void
- */
- protected function setUp()
- {
- $this->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.')
- ],
- ];
- }
- }
|