From 0b2cf658eba09cf436e7252f6c8358bf1f7c4547 Mon Sep 17 00:00:00 2001 From: Ihor Sviziev Date: Tue, 31 Mar 2020 21:33:43 +0300 Subject: [PATCH] Upgrade to phpunit 8 Update unit tests in AdminNotification module --- .../Unit/Block/Grid/Renderer/ActionsTest.php | 9 +-- .../Unit/Block/Grid/Renderer/NoticeTest.php | 5 +- .../Unit/Block/Grid/Renderer/SeverityTest.php | 7 ++- .../Test/Unit/Block/ToolbarEntryTest.php | 27 ++++---- .../Test/Unit/Model/FeedTest.php | 61 +++++++++++-------- .../Unit/Model/NotificationServiceTest.php | 32 ++++++---- .../System/Message/CacheOutdatedTest.php | 30 +++++---- .../Media/Synchronization/ErrorTest.php | 37 ++++++----- .../Model/System/Message/SecurityTest.php | 35 +++++++---- 9 files changed, 145 insertions(+), 98 deletions(-) diff --git a/app/code/Magento/AdminNotification/Test/Unit/Block/Grid/Renderer/ActionsTest.php b/app/code/Magento/AdminNotification/Test/Unit/Block/Grid/Renderer/ActionsTest.php index 781734186ce6b..7199d1f44222d 100644 --- a/app/code/Magento/AdminNotification/Test/Unit/Block/Grid/Renderer/ActionsTest.php +++ b/app/code/Magento/AdminNotification/Test/Unit/Block/Grid/Renderer/ActionsTest.php @@ -18,6 +18,7 @@ use Magento\Framework\Escaper; use Magento\Framework\Url\Helper\Data; use Magento\Framework\UrlInterface; +use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; class ActionsTest extends TestCase @@ -32,20 +33,20 @@ protected function setUp() : void { parent::setUp(); - /** @var Escaper | \PHPUnit_Framework_MockObject_MockObject $escaperMock */ + /** @var Escaper|MockObject $escaperMock */ $escaperMock = $this->getMockBuilder(Escaper::class)->disableOriginalConstructor()->getMock(); $escaperMock->expects($this->once())->method('escapeUrl')->willReturn('https://magento.com'); - /** @var UrlInterface | \PHPUnit_Framework_MockObject_MockObject $urlBuilder */ + /** @var UrlInterface|MockObject $urlBuilder */ $urlBuilder = $this->getMockBuilder(UrlInterface::class)->getMock(); $urlBuilder->expects($this->once())->method('getUrl')->willReturn('http://magento.com'); - /** @var Context | \PHPUnit_Framework_MockObject_MockObject $contextMock */ + /** @var Context|MockObject $contextMock */ $contextMock = $this->getMockBuilder(Context::class)->disableOriginalConstructor()->getMock(); $contextMock->expects($this->once())->method('getEscaper')->willReturn($escaperMock); $contextMock->expects($this->once())->method('getUrlBuilder')->willReturn($urlBuilder); - /** @var Data | \PHPUnit_Framework_MockObject_MockObject $urlHelperMock */ + /** @var Data|MockObject $urlHelperMock */ $urlHelperMock = $this->getMockBuilder(Data::class)->disableOriginalConstructor()->getMock(); $urlHelperMock->expects($this->once())->method('getEncodedUrl')->willReturn('http://magento.com'); diff --git a/app/code/Magento/AdminNotification/Test/Unit/Block/Grid/Renderer/NoticeTest.php b/app/code/Magento/AdminNotification/Test/Unit/Block/Grid/Renderer/NoticeTest.php index 7b4b0a0f66e96..a4fb6227ecdc7 100644 --- a/app/code/Magento/AdminNotification/Test/Unit/Block/Grid/Renderer/NoticeTest.php +++ b/app/code/Magento/AdminNotification/Test/Unit/Block/Grid/Renderer/NoticeTest.php @@ -15,6 +15,7 @@ use Magento\Framework\DataObject; use Magento\Framework\Escaper; use Magento\Backend\Block\Context; +use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; class NoticeTest extends TestCase @@ -30,11 +31,11 @@ protected function setUp() : void { parent::setUp(); - /** @var Escaper | \PHPUnit_Framework_MockObject_MockObject $escaperMock */ + /** @var Escaper|MockObject $escaperMock */ $escaperMock = $this->getMockBuilder(Escaper::class)->disableOriginalConstructor()->getMock(); $escaperMock->expects($this->exactly(2))->method('escapeHtml')->willReturn('
Some random html
'); - /** @var Context | \PHPUnit_Framework_MockObject_MockObject $contextMock */ + /** @var Context|MockObject $contextMock */ $contextMock = $this->getMockBuilder(Context::class)->disableOriginalConstructor()->getMock(); $contextMock->expects($this->once())->method('getEscaper')->willReturn($escaperMock); diff --git a/app/code/Magento/AdminNotification/Test/Unit/Block/Grid/Renderer/SeverityTest.php b/app/code/Magento/AdminNotification/Test/Unit/Block/Grid/Renderer/SeverityTest.php index 2a30be02f173b..c2e109cff130e 100644 --- a/app/code/Magento/AdminNotification/Test/Unit/Block/Grid/Renderer/SeverityTest.php +++ b/app/code/Magento/AdminNotification/Test/Unit/Block/Grid/Renderer/SeverityTest.php @@ -17,6 +17,7 @@ use Magento\Backend\Block\Widget\Grid\Column; use Magento\Framework\DataObject; use Magento\Framework\Escaper; +use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; class SeverityTest extends TestCase @@ -32,10 +33,10 @@ protected function setUp() : void { parent::setUp(); - /** @var Inbox |\PHPUnit_Framework_MockObject_MockObject $inboxMock */ + /** @var Inbox|MockObject $inboxMock */ $inboxMock = $this->getMockBuilder(Inbox::class)->disableOriginalConstructor()->getMock(); - /** @var Context | \PHPUnit_Framework_MockObject_MockObject $contextMock */ + /** @var Context|MockObject $contextMock */ $contextMock = $this->getMockBuilder(Context::class)->disableOriginalConstructor()->getMock(); $this->sut = new Severity($contextMock, $inboxMock); @@ -43,7 +44,7 @@ protected function setUp() : void public function testShouldRenderSeverity() : void { - /** @var Column | \PHPUnit_Framework_MockObject_MockObject $columnMock */ + /** @var Column|MockObject $columnMock */ $columnMock = $this->getMockBuilder(Column::class) ->disableOriginalConstructor() ->setMethods(['getIndex']) diff --git a/app/code/Magento/AdminNotification/Test/Unit/Block/ToolbarEntryTest.php b/app/code/Magento/AdminNotification/Test/Unit/Block/ToolbarEntryTest.php index 2afa9eced1d95..eb45a9af6beb2 100644 --- a/app/code/Magento/AdminNotification/Test/Unit/Block/ToolbarEntryTest.php +++ b/app/code/Magento/AdminNotification/Test/Unit/Block/ToolbarEntryTest.php @@ -9,26 +9,31 @@ */ namespace Magento\AdminNotification\Test\Unit\Block; -class ToolbarEntryTest extends \PHPUnit\Framework\TestCase +use Magento\AdminNotification\Block\ToolbarEntry; +use Magento\AdminNotification\Model\ResourceModel\Inbox\Collection\Unread; +use Magento\Framework\TestFramework\Unit\Helper\ObjectManager; +use PHPUnit\Framework\TestCase; + +class ToolbarEntryTest extends TestCase { /** * Retrieve toolbar entry block instance * * @param int $unreadNotifications number of unread notifications - * @return \Magento\AdminNotification\Block\ToolbarEntry + * @return ToolbarEntry */ protected function _getBlockInstance($unreadNotifications) { - $objectManagerHelper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); + $objectManagerHelper = new ObjectManager($this); // mock collection of unread notifications $notificationList = $this->createPartialMock( - \Magento\AdminNotification\Model\ResourceModel\Inbox\Collection\Unread::class, + Unread::class, ['getSize', 'setCurPage', 'setPageSize'] ); $notificationList->expects($this->any())->method('getSize')->will($this->returnValue($unreadNotifications)); $block = $objectManagerHelper->getObject( - \Magento\AdminNotification\Block\ToolbarEntry::class, + ToolbarEntry::class, ['notificationList' => $notificationList] ); @@ -44,25 +49,23 @@ public function testGetUnreadNotificationCount() public function testGetLatestUnreadNotifications() { - $helper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); + $helper = new ObjectManager($this); // 1. Create mocks - $notificationList = $this->getMockBuilder( - \Magento\AdminNotification\Model\ResourceModel\Inbox\Collection\Unread::class - ) + $notificationList = $this->getMockBuilder(Unread::class) ->disableOriginalConstructor() ->getMock(); - /** @var \Magento\AdminNotification\Block\ToolbarEntry $model */ + /** @var ToolbarEntry $model */ $model = $helper->getObject( - \Magento\AdminNotification\Block\ToolbarEntry::class, + ToolbarEntry::class, ['notificationList' => $notificationList] ); // 2. Set expectations $notificationList->expects($this->atLeastOnce()) ->method('setPageSize') - ->with(\Magento\AdminNotification\Block\ToolbarEntry::NOTIFICATIONS_NUMBER) + ->with(ToolbarEntry::NOTIFICATIONS_NUMBER) ->will($this->returnSelf()); // 3. Run tested method diff --git a/app/code/Magento/AdminNotification/Test/Unit/Model/FeedTest.php b/app/code/Magento/AdminNotification/Test/Unit/Model/FeedTest.php index 2b3eb6247e899..604d33ccf9092 100644 --- a/app/code/Magento/AdminNotification/Test/Unit/Model/FeedTest.php +++ b/app/code/Magento/AdminNotification/Test/Unit/Model/FeedTest.php @@ -6,66 +6,79 @@ namespace Magento\AdminNotification\Test\Unit\Model; +use Magento\AdminNotification\Model\Feed; +use Magento\AdminNotification\Model\Inbox; +use Magento\AdminNotification\Model\InboxFactory; +use Magento\Backend\App\ConfigInterface; +use Magento\Framework\App\CacheInterface; +use Magento\Framework\App\DeploymentConfig; +use Magento\Framework\App\ProductMetadata; +use Magento\Framework\App\State; use Magento\Framework\Config\ConfigOptionsListConstants; +use Magento\Framework\HTTP\Adapter\Curl; +use Magento\Framework\HTTP\Adapter\CurlFactory; use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper; +use Magento\Framework\UrlInterface; +use PHPUnit\Framework\MockObject\MockObject; +use PHPUnit\Framework\TestCase; /** * @SuppressWarnings(PHPMD.CouplingBetweenObjects) */ -class FeedTest extends \PHPUnit\Framework\TestCase +class FeedTest extends TestCase { - /** @var \Magento\AdminNotification\Model\Feed */ + /** @var Feed */ protected $feed; /** @var ObjectManagerHelper */ protected $objectManagerHelper; - /** @var \Magento\AdminNotification\Model\InboxFactory|\PHPUnit_Framework_MockObject_MockObject */ + /** @var InboxFactory|MockObject */ protected $inboxFactory; - /** @var \Magento\AdminNotification\Model\Inbox|\PHPUnit_Framework_MockObject_MockObject */ + /** @var Inbox|MockObject */ protected $inboxModel; - /** @var \Magento\Framework\HTTP\Adapter\CurlFactory|\PHPUnit_Framework_MockObject_MockObject */ + /** @var CurlFactory|MockObject */ protected $curlFactory; - /** @var \Magento\Framework\HTTP\Adapter\Curl|\PHPUnit_Framework_MockObject_MockObject */ + /** @var Curl|MockObject */ protected $curl; - /** @var \Magento\Backend\App\ConfigInterface|\PHPUnit_Framework_MockObject_MockObject */ + /** @var ConfigInterface|MockObject */ protected $backendConfig; - /** @var \Magento\Framework\App\CacheInterface|\PHPUnit_Framework_MockObject_MockObject */ + /** @var CacheInterface|MockObject */ protected $cacheManager; - /** @var \Magento\Framework\App\State|\PHPUnit_Framework_MockObject_MockObject */ + /** @var State|MockObject */ protected $appState; - /** @var \Magento\Framework\App\DeploymentConfig|\PHPUnit_Framework_MockObject_MockObject */ + /** @var DeploymentConfig|MockObject */ protected $deploymentConfig; - /** @var \Magento\Framework\App\ProductMetadata|\PHPUnit_Framework_MockObject_MockObject */ + /** @var ProductMetadata|MockObject */ protected $productMetadata; - /** @var \Magento\Framework\UrlInterface|\PHPUnit_Framework_MockObject_MockObject */ + /** @var UrlInterface|MockObject */ protected $urlBuilder; - protected function setUp() + protected function setUp(): void { $this->inboxFactory = $this->createPartialMock( - \Magento\AdminNotification\Model\InboxFactory::class, + InboxFactory::class, ['create'] ); - $this->curlFactory = $this->createPartialMock(\Magento\Framework\HTTP\Adapter\CurlFactory::class, ['create']); - $this->curl = $this->getMockBuilder(\Magento\Framework\HTTP\Adapter\Curl::class) + $this->curlFactory = $this->createPartialMock(CurlFactory::class, ['create']); + $this->curl = $this->getMockBuilder(Curl::class) ->disableOriginalConstructor()->getMock(); - $this->appState = $this->createPartialMock(\Magento\Framework\App\State::class, ['getInstallDate']); - $this->inboxModel = $this->createPartialMock(\Magento\AdminNotification\Model\Inbox::class, [ + $this->appState = $this->createPartialMock(State::class, []); + $this->inboxModel = $this->createPartialMock(Inbox::class, [ '__wakeup', 'parse' ]); $this->backendConfig = $this->createPartialMock( - \Magento\Backend\App\ConfigInterface::class, + ConfigInterface::class, [ 'getValue', 'setValue', @@ -73,7 +86,7 @@ protected function setUp() ] ); $this->cacheManager = $this->createPartialMock( - \Magento\Framework\App\CacheInterface::class, + CacheInterface::class, [ 'load', 'getFrontend', @@ -83,18 +96,18 @@ protected function setUp() ] ); - $this->deploymentConfig = $this->getMockBuilder(\Magento\Framework\App\DeploymentConfig::class) + $this->deploymentConfig = $this->getMockBuilder(DeploymentConfig::class) ->disableOriginalConstructor()->getMock(); $this->objectManagerHelper = new ObjectManagerHelper($this); - $this->productMetadata = $this->getMockBuilder(\Magento\Framework\App\ProductMetadata::class) + $this->productMetadata = $this->getMockBuilder(ProductMetadata::class) ->disableOriginalConstructor()->getMock(); - $this->urlBuilder = $this->createMock(\Magento\Framework\UrlInterface::class); + $this->urlBuilder = $this->createMock(UrlInterface::class); $this->feed = $this->objectManagerHelper->getObject( - \Magento\AdminNotification\Model\Feed::class, + Feed::class, [ 'backendConfig' => $this->backendConfig, 'cacheManager' => $this->cacheManager, diff --git a/app/code/Magento/AdminNotification/Test/Unit/Model/NotificationServiceTest.php b/app/code/Magento/AdminNotification/Test/Unit/Model/NotificationServiceTest.php index f8485847ccae2..68070add6cd98 100644 --- a/app/code/Magento/AdminNotification/Test/Unit/Model/NotificationServiceTest.php +++ b/app/code/Magento/AdminNotification/Test/Unit/Model/NotificationServiceTest.php @@ -9,27 +9,33 @@ */ namespace Magento\AdminNotification\Test\Unit\Model; -class NotificationServiceTest extends \PHPUnit\Framework\TestCase +use Magento\AdminNotification\Model\Inbox; +use Magento\AdminNotification\Model\InboxFactory; +use Magento\AdminNotification\Model\NotificationService; +use Magento\Framework\Exception\LocalizedException; +use PHPUnit\Framework\MockObject\MockObject; +use PHPUnit\Framework\TestCase; + +class NotificationServiceTest extends TestCase { /** * Retrieve instance of notification service model * * @param $notificationId - * @return \Magento\AdminNotification\Model\NotificationService + * @return NotificationService */ protected function _getServiceInstanceForMarkAsReadTest($notificationId) { /** - * @var - * $notificationFactory \PHPUnit_Framework_MockObject_MockObject|\Magento\AdminNotification\Model\InboxFactory + * @var $notificationFactory MockObject|InboxFactory */ $notificationFactory = $this->createPartialMock( - \Magento\AdminNotification\Model\InboxFactory::class, + InboxFactory::class, ['create'] ); $notification = $this->createPartialMock( - \Magento\AdminNotification\Model\Inbox::class, - ['load', 'getId', 'save', 'setIsRead', '__sleep', '__wakeup'] + Inbox::class, + ['load', 'getId', 'save', 'setData', '__sleep', '__wakeup'] ); $notification->expects($this->once())->method('load')->with($notificationId)->will($this->returnSelf()); $notification->expects($this->once())->method('getId')->will($this->returnValue($notificationId)); @@ -37,11 +43,12 @@ protected function _getServiceInstanceForMarkAsReadTest($notificationId) // when notification Id is valid, add additional expectations if ($notificationId) { $notification->expects($this->once())->method('save')->will($this->returnSelf()); - $notification->expects($this->once())->method('setIsRead')->with(1)->will($this->returnSelf()); + $notification->expects($this->once())->method('setData') + ->with('is_read', 1)->will($this->returnSelf()); } $notificationFactory->expects($this->once())->method('create')->will($this->returnValue($notification)); - return new \Magento\AdminNotification\Model\NotificationService($notificationFactory); + return new NotificationService($notificationFactory); } public function testMarkAsRead() @@ -51,12 +58,11 @@ public function testMarkAsRead() $service->markAsRead($notificationId); } - /** - * @expectedException \Magento\Framework\Exception\LocalizedException - * @expectedExceptionMessage Wrong notification ID specified. - */ public function testMarkAsReadThrowsExceptionWhenNotificationIdIsInvalid() { + $this->expectException(LocalizedException::class); + $this->expectExceptionMessage('Wrong notification ID specified.'); + $notificationId = null; $service = $this->_getServiceInstanceForMarkAsReadTest($notificationId); $service->markAsRead($notificationId); diff --git a/app/code/Magento/AdminNotification/Test/Unit/Model/System/Message/CacheOutdatedTest.php b/app/code/Magento/AdminNotification/Test/Unit/Model/System/Message/CacheOutdatedTest.php index f49911c3e7a93..381e3fff3d080 100644 --- a/app/code/Magento/AdminNotification/Test/Unit/Model/System/Message/CacheOutdatedTest.php +++ b/app/code/Magento/AdminNotification/Test/Unit/Model/System/Message/CacheOutdatedTest.php @@ -5,42 +5,50 @@ */ namespace Magento\AdminNotification\Test\Unit\Model\System\Message; -class CacheOutdatedTest extends \PHPUnit\Framework\TestCase +use Magento\AdminNotification\Model\System\Message\CacheOutdated; +use Magento\Framework\App\Cache\TypeListInterface; +use Magento\Framework\AuthorizationInterface; +use Magento\Framework\TestFramework\Unit\Helper\ObjectManager; +use Magento\Framework\UrlInterface; +use PHPUnit\Framework\MockObject\MockObject; +use PHPUnit\Framework\TestCase; + +class CacheOutdatedTest extends TestCase { /** - * @var \PHPUnit_Framework_MockObject_MockObject + * @var MockObject */ protected $_authorizationMock; /** - * @var \PHPUnit_Framework_MockObject_MockObject + * @var MockObject */ protected $_cacheTypeListMock; /** - * @var \PHPUnit_Framework_MockObject_MockObject + * @var MockObject */ protected $_urlInterfaceMock; /** - * @var \Magento\AdminNotification\Model\System\Message\CacheOutdated + * @var CacheOutdated */ protected $_messageModel; - protected function setUp() + protected function setUp(): void { - $this->_authorizationMock = $this->createMock(\Magento\Framework\AuthorizationInterface::class); - $this->_urlInterfaceMock = $this->createMock(\Magento\Framework\UrlInterface::class); - $this->_cacheTypeListMock = $this->createMock(\Magento\Framework\App\Cache\TypeListInterface::class); + $this->_authorizationMock = $this->createMock(AuthorizationInterface::class); + $this->_urlInterfaceMock = $this->createMock(UrlInterface::class); + $this->_cacheTypeListMock = $this->createMock(TypeListInterface::class); - $objectManagerHelper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); + $objectManagerHelper = new ObjectManager($this); $arguments = [ 'authorization' => $this->_authorizationMock, 'urlBuilder' => $this->_urlInterfaceMock, 'cacheTypeList' => $this->_cacheTypeListMock, ]; $this->_messageModel = $objectManagerHelper->getObject( - \Magento\AdminNotification\Model\System\Message\CacheOutdated::class, + CacheOutdated::class, $arguments ); } diff --git a/app/code/Magento/AdminNotification/Test/Unit/Model/System/Message/Media/Synchronization/ErrorTest.php b/app/code/Magento/AdminNotification/Test/Unit/Model/System/Message/Media/Synchronization/ErrorTest.php index b490efd8e9683..91595732bdb58 100644 --- a/app/code/Magento/AdminNotification/Test/Unit/Model/System/Message/Media/Synchronization/ErrorTest.php +++ b/app/code/Magento/AdminNotification/Test/Unit/Model/System/Message/Media/Synchronization/ErrorTest.php @@ -5,37 +5,44 @@ */ namespace Magento\AdminNotification\Test\Unit\Model\System\Message\Media\Synchronization; -class ErrorTest extends \PHPUnit\Framework\TestCase +use Magento\AdminNotification\Model\System\Message\Media\Synchronization\Error; +use Magento\Framework\Notification\MessageInterface; +use Magento\Framework\TestFramework\Unit\Helper\ObjectManager; +use Magento\MediaStorage\Model\File\Storage\Flag; +use PHPUnit\Framework\MockObject\MockObject; +use PHPUnit\Framework\TestCase; + +class ErrorTest extends TestCase { /** - * @var \PHPUnit_Framework_MockObject_MockObject + * @var MockObject */ protected $_syncFlagMock; /** - * @var \PHPUnit_Framework_MockObject_MockObject + * @var MockObject */ protected $_fileStorage; /** - * @var \Magento\AdminNotification\Model\System\Message\Media\Synchronization\Error + * @var Error */ protected $_model; - protected function setUp() + protected function setUp(): void { $this->_syncFlagMock = $this->createPartialMock( - \Magento\MediaStorage\Model\File\Storage\Flag::class, - ['setState', 'save', 'getFlagData'] + Flag::class, + ['save', 'getFlagData'] ); - $this->_fileStorage = $this->createMock(\Magento\MediaStorage\Model\File\Storage\Flag::class); + $this->_fileStorage = $this->createMock(Flag::class); $this->_fileStorage->expects($this->any())->method('loadSelf')->will($this->returnValue($this->_syncFlagMock)); - $objectManagerHelper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); + $objectManagerHelper = new ObjectManager($this); $arguments = ['fileStorage' => $this->_fileStorage]; $this->_model = $objectManagerHelper->getObject( - \Magento\AdminNotification\Model\System\Message\Media\Synchronization\Error::class, + Error::class, $arguments ); } @@ -43,7 +50,6 @@ protected function setUp() public function testGetText() { $messageText = 'We were unable to synchronize one or more media files.'; - $this->assertContains($messageText, (string)$this->_model->getText()); } @@ -55,15 +61,14 @@ public function testGetText() public function testIsDisplayed($expectedFirstRun, $data) { $arguments = ['fileStorage' => $this->_fileStorage]; - $objectManagerHelper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); + $objectManagerHelper = new ObjectManager($this); // create new instance to ensure that it hasn't been displayed yet (var $this->_isDisplayed is unset) - /** @var $model \Magento\AdminNotification\Model\System\Message\Media\Synchronization\Error */ + /** @var $model Error */ $model = $objectManagerHelper->getObject( - \Magento\AdminNotification\Model\System\Message\Media\Synchronization\Error::class, + Error::class, $arguments ); - $this->_syncFlagMock->expects($this->any())->method('setState'); $this->_syncFlagMock->expects($this->any())->method('save'); $this->_syncFlagMock->expects($this->any())->method('getFlagData')->will($this->returnValue($data)); //check first call @@ -92,7 +97,7 @@ public function testGetIdentity() public function testGetSeverity() { - $severity = \Magento\Framework\Notification\MessageInterface::SEVERITY_MAJOR; + $severity = MessageInterface::SEVERITY_MAJOR; $this->assertEquals($severity, $this->_model->getSeverity()); } } diff --git a/app/code/Magento/AdminNotification/Test/Unit/Model/System/Message/SecurityTest.php b/app/code/Magento/AdminNotification/Test/Unit/Model/System/Message/SecurityTest.php index c6f61fee862ba..3b679e442c60e 100644 --- a/app/code/Magento/AdminNotification/Test/Unit/Model/System/Message/SecurityTest.php +++ b/app/code/Magento/AdminNotification/Test/Unit/Model/System/Message/SecurityTest.php @@ -5,51 +5,60 @@ */ namespace Magento\AdminNotification\Test\Unit\Model\System\Message; -class SecurityTest extends \PHPUnit\Framework\TestCase +use Magento\AdminNotification\Model\System\Message\Security; +use Magento\Framework\App\CacheInterface; +use Magento\Framework\App\Config\ScopeConfigInterface; +use Magento\Framework\HTTP\Adapter\Curl; +use Magento\Framework\HTTP\Adapter\CurlFactory; +use Magento\Framework\TestFramework\Unit\Helper\ObjectManager; +use PHPUnit\Framework\MockObject\MockObject; +use PHPUnit\Framework\TestCase; + +class SecurityTest extends TestCase { /** - * @var \PHPUnit_Framework_MockObject_MockObject + * @var MockObject */ protected $_cacheMock; /** - * @var \PHPUnit_Framework_MockObject_MockObject + * @var MockObject */ protected $_scopeConfigMock; /** - * @var \PHPUnit_Framework_MockObject_MockObject + * @var MockObject */ protected $_configMock; /** - * @var \PHPUnit_Framework_MockObject_MockObject + * @var MockObject */ protected $_curlFactoryMock; /** - * @var \Magento\AdminNotification\Model\System\Message\Security + * @var Security */ protected $_messageModel; - protected function setUp() + protected function setUp(): void { //Prepare objects for constructor - $this->_cacheMock = $this->createMock(\Magento\Framework\App\CacheInterface::class); - $this->_scopeConfigMock = $this->createMock(\Magento\Framework\App\Config\ScopeConfigInterface::class); + $this->_cacheMock = $this->createMock(CacheInterface::class); + $this->_scopeConfigMock = $this->createMock(ScopeConfigInterface::class); $this->_curlFactoryMock = $this->createPartialMock( - \Magento\Framework\HTTP\Adapter\CurlFactory::class, + CurlFactory::class, ['create'] ); - $objectManagerHelper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); + $objectManagerHelper = new ObjectManager($this); $arguments = [ 'cache' => $this->_cacheMock, 'scopeConfig' => $this->_scopeConfigMock, 'curlFactory' => $this->_curlFactoryMock, ]; $this->_messageModel = $objectManagerHelper->getObject( - \Magento\AdminNotification\Model\System\Message\Security::class, + Security::class, $arguments ); } @@ -67,7 +76,7 @@ public function testIsDisplayed($expectedResult, $cached, $response) $this->_cacheMock->expects($this->any())->method('load')->will($this->returnValue($cached)); $this->_cacheMock->expects($this->any())->method('save')->will($this->returnValue(null)); - $httpAdapterMock = $this->createMock(\Magento\Framework\HTTP\Adapter\Curl::class); + $httpAdapterMock = $this->createMock(Curl::class); $httpAdapterMock->expects($this->any())->method('read')->will($this->returnValue($response)); $this->_curlFactoryMock->expects($this->any())->method('create')->will($this->returnValue($httpAdapterMock));