Skip to content

Commit

Permalink
Merge branch '2.4-develop' of https://github.com/mage-os/mirror-magento2
Browse files Browse the repository at this point in the history
 into 2.4-develop
  • Loading branch information
mage-os-ci committed Mar 6, 2024
2 parents 73c7bfd + ff4439c commit 7b6423f
Show file tree
Hide file tree
Showing 650 changed files with 7,957 additions and 4,227 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public function testShouldRenderSeverity() : void
/** @var Column|MockObject $columnMock */
$columnMock = $this->getMockBuilder(Column::class)
->disableOriginalConstructor()
->setMethods(['getIndex'])
->addMethods(['getIndex'])
->getMock();
$columnMock->expects($this->exactly(5))->method('getIndex')->willReturn('index');
$this->sut->setColumn($columnMock);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

use Magento\AdminNotification\Block\ToolbarEntry;
use Magento\AdminNotification\Model\ResourceModel\Inbox\Collection\Unread;
use Magento\Directory\Helper\Data as DirectoryHelper;
use Magento\Framework\Json\Helper\Data as JsonHelper;
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
use PHPUnit\Framework\TestCase;

Expand All @@ -26,6 +28,17 @@ class ToolbarEntryTest extends TestCase
protected function _getBlockInstance($unreadNotifications)
{
$objectManagerHelper = new ObjectManager($this);
$objects = [
[
JsonHelper::class,
$this->createMock(JsonHelper::class)
],
[
DirectoryHelper::class,
$this->createMock(DirectoryHelper::class)
]
];
$objectManagerHelper->prepareObjectManager($objects);
// mock collection of unread notifications
$notificationList = $this->createPartialMock(
Unread::class,
Expand All @@ -52,6 +65,18 @@ public function testGetLatestUnreadNotifications()
{
$helper = new ObjectManager($this);

$objects = [
[
JsonHelper::class,
$this->createMock(JsonHelper::class)
],
[
DirectoryHelper::class,
$this->createMock(DirectoryHelper::class)
]
];
$helper->prepareObjectManager($objects);

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,13 +225,15 @@ protected function setUp(): void
'initWebsites',
'initCategories'
];
$mockAddMethods = [
'_headerColumns'
];
$mockMethods = array_merge($constructorMethods, [
'_customHeadersMapping',
'_prepareEntityCollection',
'_getEntityCollection',
'getWriter',
'getExportData',
'_headerColumns',
'_customFieldsMapping',
'getItemsPerPage',
'paginateCollection',
Expand All @@ -243,7 +245,8 @@ protected function setUp(): void
$this->advancedPricing = $this->getMockBuilder(
AdvancedPricing::class
)
->setMethods($mockMethods)
->addMethods($mockAddMethods)
->onlyMethods($mockMethods)
->disableOriginalConstructor()
->getMock();
foreach ($constructorMethods as $method) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,13 @@ public function testCreate(): void
$clientOptionsMock = $this->getMockForAbstractClass(ClientOptionsInterface::class);

$this->objectManager->expects($this->exactly(2))->method('create')
->withConsecutive(
[$this->equalTo('engineFactoryClass')],
[$this->equalTo('engineOptionClass')]
)
->willReturnOnConsecutiveCalls(
$factoryMock,
$clientOptionsMock
);
->willReturnCallback(function ($className) use ($factoryMock, $clientOptionsMock) {
if ($className == 'engineFactoryClass') {
return $factoryMock;
} elseif ($className == 'engineOptionClass') {
return $clientOptionsMock;
}
});

$clientOptionsMock->expects($this->once())->method('prepareClientOptions')
->with([])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,11 @@ protected function setUp(): void
$this->objectManager = new ObjectManager($this);
$this->connectionValidatorMock = $this->getMockBuilder(ConnectionValidator::class)
->disableOriginalConstructor()
->setMethods([])
->getMock();

$this->deploymentConfigMock = $this->getMockBuilder(DeploymentConfig::class)
->disableOriginalConstructor()
->setMethods([])
->onlyMethods([])
->getMock();

$this->model = $this->objectManager->getObject(
Expand Down Expand Up @@ -171,7 +170,7 @@ public function testValidateNoOptions()
/**
* @return array
*/
public function getCreateConfigDataProvider()
public static function getCreateConfigDataProvider()
{
return [
[
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ protected function setUp(): void
$this->subscriptionStatusProviderMock = $this->createMock(SubscriptionStatusProvider::class);
$this->contextMock = $this->createMock(Context::class);
$this->abstractElementMock = $this->getMockBuilder(AbstractElement::class)
->setMethods(['getComment', 'getElementHtml'])
->addMethods(['getComment'])
->onlyMethods(['getElementHtml'])
->disableOriginalConstructor()
->getMock();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ class VerticalTest extends TestCase
protected function setUp(): void
{
$this->abstractElementMock = $this->getMockBuilder(AbstractElement::class)
->setMethods(['getComment', 'getLabel', 'getHint', 'getElementHtml'])
->addMethods(['getComment', 'getLabel', 'getHint'])
->onlyMethods(['getElementHtml'])
->disableOriginalConstructor()
->getMock();

Expand Down
12 changes: 6 additions & 6 deletions app/code/Magento/Analytics/Test/Unit/Cron/UpdateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,10 @@ private function addFinalOutputAsserts(bool $isExecuted = true)
$this->flagManagerMock
->expects($this->exactly(2 * $isExecuted))
->method('deleteFlag')
->withConsecutive(
[SubscriptionUpdateHandler::SUBSCRIPTION_UPDATE_REVERSE_COUNTER_FLAG_CODE],
[SubscriptionUpdateHandler::PREVIOUS_BASE_URL_FLAG_CODE]
);
->willReturnCallback(fn($param) => match ([$param]) {
[SubscriptionUpdateHandler::SUBSCRIPTION_UPDATE_REVERSE_COUNTER_FLAG_CODE] => $this->flagManagerMock,
[SubscriptionUpdateHandler::PREVIOUS_BASE_URL_FLAG_CODE] => $this->flagManagerMock
});
$this->configWriterMock
->expects($this->exactly((int)$isExecuted))
->method('delete')
Expand Down Expand Up @@ -143,7 +143,7 @@ public function testExecuteWithEmptyReverseCounter($counterData)
*
* @return array
*/
public function executeWithEmptyReverseCounterDataProvider()
public static function executeWithEmptyReverseCounterDataProvider()
{
return [
[null],
Expand Down Expand Up @@ -189,7 +189,7 @@ public function testExecuteRegularScenario(
/**
* @return array
*/
public function executeRegularScenarioDataProvider()
public static function executeRegularScenarioDataProvider()
{
return [
'The last attempt with command execution result False' => [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,15 @@ public function testTokenAndPreviousBaseUrlExist()
$this->flagManagerMock
->expects($this->once())
->method('saveFlag')
->withConsecutive(
[SubscriptionUpdateHandler::SUBSCRIPTION_UPDATE_REVERSE_COUNTER_FLAG_CODE, $this->attemptsInitValue],
[SubscriptionUpdateHandler::PREVIOUS_BASE_URL_FLAG_CODE, $url]
);
->willReturnCallback(function ($arg1, $arg2) use ($url) {
if ($arg1 == SubscriptionUpdateHandler::SUBSCRIPTION_UPDATE_REVERSE_COUNTER_FLAG_CODE
&& $arg2 == $this->attemptsInitValue) {
return true;
} elseif ($arg1 == SubscriptionUpdateHandler::PREVIOUS_BASE_URL_FLAG_CODE && $arg2 == $url) {
return true;
}
});

$this->configWriterMock
->expects($this->once())
->method('save')
Expand Down Expand Up @@ -160,10 +165,14 @@ public function testTokenExistAndWithoutPreviousBaseUrl()
$this->flagManagerMock
->expects($this->exactly(2))
->method('saveFlag')
->withConsecutive(
[SubscriptionUpdateHandler::PREVIOUS_BASE_URL_FLAG_CODE, $url],
[SubscriptionUpdateHandler::SUBSCRIPTION_UPDATE_REVERSE_COUNTER_FLAG_CODE, $this->attemptsInitValue]
);
->willReturnCallback(function ($arg1, $arg2) use ($url) {
if ($arg1 == SubscriptionUpdateHandler::SUBSCRIPTION_UPDATE_REVERSE_COUNTER_FLAG_CODE
&& $arg2 == $this->attemptsInitValue) {
return true;
} elseif ($arg1 == SubscriptionUpdateHandler::PREVIOUS_BASE_URL_FLAG_CODE && $arg2 == $url) {
return true;
}
});
$this->configWriterMock
->expects($this->once())
->method('save')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,26 +132,18 @@ public function testPrepareExportData($isArchiveSourceDirectory)
$this->directoryMock
->expects($this->exactly(4))
->method('delete')
->withConsecutive(
[$tmpFilesDirectoryPath],
[$archiveRelativePath]
);
->willReturnCallback(fn($param) => match ([$param]) {
[$tmpFilesDirectoryPath] => true,
[$archiveRelativePath] => true
});

$this->directoryMock
->expects($this->exactly(4))
->method('getAbsolutePath')
->withConsecutive(
[$tmpFilesDirectoryPath],
[$tmpFilesDirectoryPath],
[$archiveRelativePath],
[$archiveRelativePath]
)
->willReturnOnConsecutiveCalls(
$archiveSource,
$archiveSource,
$archiveAbsolutePath,
$archiveAbsolutePath
);
->willReturnCallback(fn($param) => match ([$param]) {
[$tmpFilesDirectoryPath] => $archiveSource,
[$archiveRelativePath] => $archiveAbsolutePath
});

$this->reportWriterMock
->expects($this->once())
Expand All @@ -161,14 +153,10 @@ public function testPrepareExportData($isArchiveSourceDirectory)
$this->directoryMock
->expects($this->exactly(2))
->method('isExist')
->withConsecutive(
[$tmpFilesDirectoryPath],
[$archiveRelativePath]
)
->willReturnOnConsecutiveCalls(
true,
true
);
->willReturnCallback(fn($param) => match ([$param]) {
[$tmpFilesDirectoryPath] => true,
[$archiveRelativePath] => true
});

$this->directoryMock
->expects($this->once())
Expand Down Expand Up @@ -208,7 +196,7 @@ public function testPrepareExportData($isArchiveSourceDirectory)
/**
* @return array
*/
public function prepareExportDataDataProvider()
public static function prepareExportDataDataProvider()
{
return [
'Data source for archive is directory' => [true],
Expand Down Expand Up @@ -237,11 +225,10 @@ public function testPrepareExportDataWithLocalizedException()
$this->directoryMock
->expects($this->exactly(3))
->method('delete')
->withConsecutive(
[$tmpFilesDirectoryPath],
[$tmpFilesDirectoryPath],
[$archivePath]
);
->willReturnCallback(fn($param) => match ([$param]) {
[$tmpFilesDirectoryPath] => true,
[$archivePath] => true
});
$this->directoryMock
->expects($this->exactly(2))
->method('getAbsolutePath')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ protected function setUp(): void
$this->subscriptionUpdateHandlerMock = $this->createMock(SubscriptionUpdateHandler::class);
$this->configValueMock = $this->getMockBuilder(Value::class)
->disableOriginalConstructor()
->setMethods(['isValueChanged', 'getPath', 'getScope', 'getOldValue'])
->addMethods(['getPath', 'getScope'])
->onlyMethods(['isValueChanged', 'getOldValue'])
->getMock();
$this->objectManagerHelper = new ObjectManagerHelper($this);
$this->plugin = $this->objectManagerHelper->getObject(
Expand Down Expand Up @@ -88,7 +89,7 @@ public function testAfterSavePluginIsNotApplicable(
/**
* @return array
*/
public function afterSavePluginIsNotApplicableDataProvider()
public static function afterSavePluginIsNotApplicableDataProvider()
{
return [
'Value has not been changed' => [
Expand Down
Loading

0 comments on commit 7b6423f

Please sign in to comment.