Skip to content

Commit

Permalink
merge magento/2.4-develop-php74 into magento-tsg/2.4-develop-php74-pr38
Browse files Browse the repository at this point in the history
  • Loading branch information
magento-mts-svc authored May 4, 2020
2 parents d7e9c2c + 86677f6 commit a71f832
Show file tree
Hide file tree
Showing 5,108 changed files with 109,886 additions and 77,000 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\AdminAnalytics\Test\Unit\Condition;

use Magento\AdminAnalytics\Model\Condition\CanViewNotification;
use Magento\AdminAnalytics\Model\ResourceModel\Viewer\Logger;
use Magento\AdminAnalytics\Model\Viewer\Log;
use Magento\Framework\App\CacheInterface;
use Magento\Framework\App\ProductMetadataInterface;
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
use Magento\Framework\App\CacheInterface;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;

Expand All @@ -28,21 +30,16 @@ class CanViewNotificationTest extends TestCase
/** @var Log|MockObject */
private $logMock;

/** @var $cacheStorageMock MockObject|CacheInterface */
/** @var MockObject|CacheInterface $cacheStorageMock */
private $cacheStorageMock;

protected function setUp(): void
{
$this->cacheStorageMock = $this->getMockBuilder(CacheInterface::class)
->getMockForAbstractClass();
$this->logMock = $this->getMockBuilder(Log::class)
->getMock();
$this->viewerLoggerMock = $this->getMockBuilder(Logger::class)
->disableOriginalConstructor()
->getMock();
$this->productMetadataMock = $this->getMockBuilder(ProductMetadataInterface::class)
->disableOriginalConstructor()
->getMockForAbstractClass();
$this->logMock = $this->createMock(Log::class);
$this->viewerLoggerMock = $this->createMock(Logger::class);
$this->productMetadataMock = $this->createMock(ProductMetadataInterface::class);
$objectManager = new ObjectManager($this);
$this->canViewNotification = $objectManager->getObject(
CanViewNotification::class,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,20 +34,20 @@ protected function setUp(): void
parent::setUp();

/** @var Escaper|MockObject $escaperMock */
$escaperMock = $this->getMockBuilder(Escaper::class)->disableOriginalConstructor()->getMock();
$escaperMock = $this->createMock(Escaper::class);
$escaperMock->expects($this->once())->method('escapeUrl')->willReturn('https://magento.com');

/** @var UrlInterface|MockObject $urlBuilder */
$urlBuilder = $this->getMockBuilder(UrlInterface::class)->getMock();
$urlBuilder = $this->createMock(UrlInterface::class);
$urlBuilder->expects($this->once())->method('getUrl')->willReturn('http://magento.com');

/** @var Context|MockObject $contextMock */
$contextMock = $this->getMockBuilder(Context::class)->disableOriginalConstructor()->getMock();
$contextMock = $this->createMock(Context::class);
$contextMock->expects($this->once())->method('getEscaper')->willReturn($escaperMock);
$contextMock->expects($this->once())->method('getUrlBuilder')->willReturn($urlBuilder);

/** @var Data|MockObject $urlHelperMock */
$urlHelperMock = $this->getMockBuilder(Data::class)->disableOriginalConstructor()->getMock();
$urlHelperMock = $this->createMock(Data::class);
$urlHelperMock->expects($this->once())->method('getEncodedUrl')->willReturn('http://magento.com');

$this->sut = new Actions($contextMock, $urlHelperMock);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
namespace Magento\AdminNotification\Test\Unit\Block\Grid\Renderer;

use Magento\AdminNotification\Block\Grid\Renderer\Notice;
use Magento\Backend\Block\Context;
use Magento\Framework\DataObject;
use Magento\Framework\Escaper;
use Magento\Backend\Block\Context;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;

Expand All @@ -32,11 +32,11 @@ protected function setUp(): void
parent::setUp();

/** @var Escaper|MockObject $escaperMock */
$escaperMock = $this->getMockBuilder(Escaper::class)->disableOriginalConstructor()->getMock();
$escaperMock = $this->createMock(Escaper::class);
$escaperMock->expects($this->exactly(2))->method('escapeHtml')->willReturn('<div>Some random html</div>');

/** @var Context|MockObject $contextMock */
$contextMock = $this->getMockBuilder(Context::class)->disableOriginalConstructor()->getMock();
$contextMock = $this->createMock(Context::class);
$contextMock->expects($this->once())->method('getEscaper')->willReturn($escaperMock);

$this->sut = new Notice($contextMock);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
use Magento\Backend\Block\Context;
use Magento\Backend\Block\Widget\Grid\Column;
use Magento\Framework\DataObject;
use Magento\Framework\Escaper;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;

Expand All @@ -34,10 +33,10 @@ protected function setUp(): void
parent::setUp();

/** @var Inbox|MockObject $inboxMock */
$inboxMock = $this->getMockBuilder(Inbox::class)->disableOriginalConstructor()->getMock();
$inboxMock = $this->createMock(Inbox::class);

/** @var Context|MockObject $contextMock */
$contextMock = $this->getMockBuilder(Context::class)->disableOriginalConstructor()->getMock();
$contextMock = $this->createMock(Context::class);

$this->sut = new Severity($contextMock, $inboxMock);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

/**
* Test class for \Magento\AdminNotification\Block\ToolbarEntry
Expand Down Expand Up @@ -30,7 +31,7 @@ protected function _getBlockInstance($unreadNotifications)
Unread::class,
['getSize', 'setCurPage', 'setPageSize']
);
$notificationList->expects($this->any())->method('getSize')->willReturn($unreadNotifications);
$notificationList->method('getSize')->willReturn($unreadNotifications);

$block = $objectManagerHelper->getObject(
ToolbarEntry::class,
Expand All @@ -52,9 +53,7 @@ public function testGetLatestUnreadNotifications()
$helper = new ObjectManager($this);

// 1. Create mocks
$notificationList = $this->getMockBuilder(Unread::class)
->disableOriginalConstructor()
->getMock();
$notificationList = $this->createMock(Unread::class);

/** @var ToolbarEntry $model */
$model = $helper->getObject(
Expand All @@ -65,8 +64,7 @@ public function testGetLatestUnreadNotifications()
// 2. Set expectations
$notificationList->expects($this->atLeastOnce())
->method('setPageSize')
->with(ToolbarEntry::NOTIFICATIONS_NUMBER)
->willReturnSelf();
->with(ToolbarEntry::NOTIFICATIONS_NUMBER)->willReturnSelf();

// 3. Run tested method
$result = $model->getLatestUnreadNotifications();
Expand Down
18 changes: 8 additions & 10 deletions app/code/Magento/AdminNotification/Test/Unit/Model/FeedTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\AdminNotification\Test\Unit\Model;

Expand Down Expand Up @@ -70,13 +71,12 @@ protected function setUp(): void
['create']
);
$this->curlFactory = $this->createPartialMock(CurlFactory::class, ['create']);
$this->curl = $this->getMockBuilder(Curl::class)
->disableOriginalConstructor()->getMock();
$this->curl = $this->createMock(Curl::class);
$this->appState = $this->createPartialMock(State::class, []);
$this->inboxModel = $this->createPartialMock(Inbox::class, [
'__wakeup',
'parse'
]);
'__wakeup',
'parse'
]);
$this->backendConfig = $this->createPartialMock(
ConfigInterface::class,
[
Expand All @@ -96,13 +96,11 @@ protected function setUp(): void
]
);

$this->deploymentConfig = $this->getMockBuilder(DeploymentConfig::class)
->disableOriginalConstructor()->getMock();
$this->deploymentConfig = $this->createMock(DeploymentConfig::class);

$this->objectManagerHelper = new ObjectManagerHelper($this);

$this->productMetadata = $this->getMockBuilder(ProductMetadata::class)
->disableOriginalConstructor()->getMock();
$this->productMetadata = $this->createMock(ProductMetadata::class);

$this->urlBuilder = $this->getMockForAbstractClass(UrlInterface::class);

Expand Down Expand Up @@ -145,7 +143,7 @@ public function testCheckUpdate($callInbox, $curlRequest)
];

$lastUpdate = 0;
$this->cacheManager->expects($this->once())->method('load')->will(($this->returnValue($lastUpdate)));
$this->cacheManager->expects($this->once())->method('load')->willReturn($lastUpdate);
$this->curlFactory->expects($this->at(0))->method('create')->willReturn($this->curl);
$this->curl->expects($this->once())->method('setConfig')->with($configValues)->willReturnSelf();
$this->curl->expects($this->once())->method('read')->willReturn($curlRequest);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

/**
* Test class for \Magento\AdminNotification\Model\NotificationService
Expand All @@ -27,16 +28,17 @@ class NotificationServiceTest extends TestCase
protected function _getServiceInstanceForMarkAsReadTest($notificationId)
{
/**
* @var $notificationFactory MockObject|InboxFactory
* @var MockObject|InboxFactory $notificationFactory
*/
$notificationFactory = $this->createPartialMock(
InboxFactory::class,
['create']
);
$notification = $this->createPartialMock(
Inbox::class,
['load', 'getId', 'save', 'setData', '__sleep', '__wakeup', 'setIsRead']
);
$notification = $this->getMockBuilder(Inbox::class)
->addMethods(['setIsRead'])
->onlyMethods(['load', 'getId', 'save', 'setData', '__sleep', '__wakeup'])
->disableOriginalConstructor()
->getMock();
$notification->expects($this->once())->method('load')->with($notificationId)->willReturnSelf();
$notification->expects($this->once())->method('getId')->willReturn($notificationId);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\AdminNotification\Test\Unit\Model\System\Message;

use Magento\AdminNotification\Model\System\Message\CacheOutdated;
Expand Down Expand Up @@ -37,9 +39,9 @@ class CacheOutdatedTest extends TestCase

protected function setUp(): void
{
$this->_authorizationMock = $this->getMockForAbstractClass(AuthorizationInterface::class);
$this->_urlInterfaceMock = $this->getMockForAbstractClass(UrlInterface::class);
$this->_cacheTypeListMock = $this->getMockForAbstractClass(TypeListInterface::class);
$this->_authorizationMock = $this->createMock(AuthorizationInterface::class);
$this->_urlInterfaceMock = $this->createMock(UrlInterface::class);
$this->_cacheTypeListMock = $this->createMock(TypeListInterface::class);

$objectManagerHelper = new ObjectManager($this);
$arguments = [
Expand All @@ -60,9 +62,7 @@ protected function setUp(): void
*/
public function testGetIdentity($expectedSum, $cacheTypes)
{
$this->_cacheTypeListMock->expects(
$this->any()
)->method(
$this->_cacheTypeListMock->method(
'getInvalidated'
)->willReturn(
$cacheTypes
Expand All @@ -75,11 +75,15 @@ public function testGetIdentity($expectedSum, $cacheTypes)
*/
public function getIdentityDataProvider()
{
$cacheTypeMock1 = $this->createPartialMock(\stdClass::class, ['getCacheType']);
$cacheTypeMock1->expects($this->any())->method('getCacheType')->willReturn('Simple');
$cacheTypeMock1 = $this->getMockBuilder(\stdClass::class)->addMethods(['getCacheType'])
->disableOriginalConstructor()
->getMock();
$cacheTypeMock1->method('getCacheType')->willReturn('Simple');

$cacheTypeMock2 = $this->createPartialMock(\stdClass::class, ['getCacheType']);
$cacheTypeMock2->expects($this->any())->method('getCacheType')->willReturn('Advanced');
$cacheTypeMock2 = $this->getMockBuilder(\stdClass::class)->addMethods(['getCacheType'])
->disableOriginalConstructor()
->getMock();
$cacheTypeMock2->method('getCacheType')->willReturn('Advanced');

return [
['c13cfaddc2c53e8d32f59bfe89719beb', [$cacheTypeMock1]],
Expand All @@ -96,9 +100,7 @@ public function getIdentityDataProvider()
public function testIsDisplayed($expected, $allowed, $cacheTypes)
{
$this->_authorizationMock->expects($this->once())->method('isAllowed')->willReturn($allowed);
$this->_cacheTypeListMock->expects(
$this->any()
)->method(
$this->_cacheTypeListMock->method(
'getInvalidated'
)->willReturn(
$cacheTypes
Expand All @@ -111,8 +113,10 @@ public function testIsDisplayed($expected, $allowed, $cacheTypes)
*/
public function isDisplayedDataProvider()
{
$cacheTypesMock = $this->createPartialMock(\stdClass::class, ['getCacheType']);
$cacheTypesMock->expects($this->any())->method('getCacheType')->willReturn('someVal');
$cacheTypesMock = $this->getMockBuilder(\stdClass::class)->addMethods(['getCacheType'])
->disableOriginalConstructor()
->getMock();
$cacheTypesMock->method('getCacheType')->willReturn('someVal');
$cacheTypes = [$cacheTypesMock, $cacheTypesMock];
return [
[false, false, []],
Expand All @@ -126,7 +130,7 @@ public function testGetText()
{
$messageText = 'One or more of the Cache Types are invalidated';

$this->_cacheTypeListMock->expects($this->any())->method('getInvalidated')->willReturn([]);
$this->_cacheTypeListMock->method('getInvalidated')->willReturn([]);
$this->_urlInterfaceMock->expects($this->once())->method('getUrl')->willReturn('someURL');
$this->assertStringContainsString($messageText, $this->_messageModel->getText());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\AdminNotification\Test\Unit\Model\System\Message\Media\Synchronization;

use Magento\AdminNotification\Model\System\Message\Media\Synchronization\Error;
Expand Down Expand Up @@ -37,7 +39,7 @@ protected function setUp(): void
);

$this->_fileStorage = $this->createMock(Flag::class);
$this->_fileStorage->expects($this->any())->method('loadSelf')->willReturn($this->_syncFlagMock);
$this->_fileStorage->method('loadSelf')->willReturn($this->_syncFlagMock);

$objectManagerHelper = new ObjectManager($this);
$arguments = ['fileStorage' => $this->_fileStorage];
Expand All @@ -63,14 +65,14 @@ public function testIsDisplayed($expectedFirstRun, $data)
$arguments = ['fileStorage' => $this->_fileStorage];
$objectManagerHelper = new ObjectManager($this);
// create new instance to ensure that it hasn't been displayed yet (var $this->_isDisplayed is unset)
/** @var $model Error */
/** @var Error $model */
$model = $objectManagerHelper->getObject(
Error::class,
$arguments
);

$this->_syncFlagMock->expects($this->any())->method('save');
$this->_syncFlagMock->expects($this->any())->method('getFlagData')->willReturn($data);
$this->_syncFlagMock->method('save');
$this->_syncFlagMock->method('getFlagData')->willReturn($data);
//check first call
$this->assertEquals($expectedFirstRun, $model->isDisplayed());
//check second call(another branch of if operator)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\AdminNotification\Test\Unit\Model\System\Message;

use Magento\AdminNotification\Model\System\Message\Security;
Expand Down Expand Up @@ -39,8 +41,8 @@ class SecurityTest extends TestCase
protected function setUp(): void
{
//Prepare objects for constructor
$this->cacheMock = $this->getMockForAbstractClass(CacheInterface::class);
$this->scopeConfigMock = $this->getMockForAbstractClass(ScopeConfigInterface::class);
$this->cacheMock = $this->createMock(CacheInterface::class);
$this->scopeConfigMock = $this->createMock(ScopeConfigInterface::class);
$this->curlFactoryMock = $this->createPartialMock(
CurlFactory::class,
['create']
Expand Down Expand Up @@ -68,14 +70,14 @@ protected function setUp(): void
*/
public function testIsDisplayed($expectedResult, $cached, $response)
{
$this->cacheMock->expects($this->any())->method('load')->willReturn($cached);
$this->cacheMock->expects($this->any())->method('save')->willReturn(null);
$this->cacheMock->method('load')->willReturn($cached);
$this->cacheMock->method('save')->willReturn(null);

$httpAdapterMock = $this->createMock(Curl::class);
$httpAdapterMock->expects($this->any())->method('read')->willReturn($response);
$this->curlFactoryMock->expects($this->any())->method('create')->willReturn($httpAdapterMock);
$httpAdapterMock->method('read')->willReturn($response);
$this->curlFactoryMock->method('create')->willReturn($httpAdapterMock);

$this->scopeConfigMock->expects($this->any())->method('getValue')->willReturn(null);
$this->scopeConfigMock->method('getValue')->willReturn(null);

$this->assertEquals($expectedResult, $this->messageModel->isDisplayed());
}
Expand Down
Loading

0 comments on commit a71f832

Please sign in to comment.