Skip to content

Commit 2e200ab

Browse files
committed
PHPUnit 10 fixes
1 parent 344ae9f commit 2e200ab

File tree

8 files changed

+90
-20
lines changed

8 files changed

+90
-20
lines changed

app/code/Magento/CatalogInventory/Test/Unit/Model/Stock/StockItemRepositoryTest.php

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@
3838
*/
3939
class StockItemRepositoryTest extends TestCase
4040
{
41+
/**
42+
* @var string
43+
*/
44+
private static $date = '2023-01-01 00:00:00';
45+
4146
/**
4247
* @var StockItemRepository
4348
*/
@@ -304,7 +309,6 @@ public function testSave(
304309
array $existingStockItemMockConfig
305310
) {
306311
$productId = 1;
307-
$date = '2023-01-01 00:00:00';
308312
$stockStateProviderMockConfig += [
309313
'verifyStock' => ['expects' => $this->once(), 'with' => [$this->stockItemMock], 'willReturn' => true,],
310314
'verifyNotification' => [
@@ -331,7 +335,7 @@ public function testSave(
331335
'setStockId' => ['expects' => $this->once(), 'with' => [1], 'willReturnSelf' => true,],
332336
'setLowStockDate' => [
333337
'expects' => $this->exactly(2),
334-
'willReturnCallback' => [[null], [$date],],
338+
'willReturnCallback' => [[null], [self::$date]],
335339
'willReturnSelf' => true,
336340
],
337341
'hasStockStatusChangedAutomaticallyFlag' => ['expects' => $this->once(), 'willReturn' => false,],
@@ -355,7 +359,7 @@ public function testSave(
355359
->willReturn(true);
356360
$this->dateTime->expects($this->once())
357361
->method('gmtDate')
358-
->willReturn($date);
362+
->willReturn(self::$date);
359363
$this->stockItemResourceMock->expects($this->once())
360364
->method('save')
361365
->with($this->stockItemMock)
@@ -507,7 +511,11 @@ private function configMock(MockObject $mockObject, array $configs): void
507511
$mockMethod->with(...$config['with']);
508512
}
509513
if (isset($config['willReturnCallback'])) {
510-
$mockMethod->willReturnCallback(...$config['willReturnCallback']);
514+
$mockMethod->willReturnCallback(function ($config) {
515+
return match ($config) {
516+
[null], [self::$date] => true
517+
};
518+
});
511519
}
512520
if (isset($config['willReturnSelf'])) {
513521
$mockMethod->willReturnSelf();

app/code/Magento/CatalogRule/Model/ResourceModel/Rule.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,13 @@ class Rule extends \Magento\Rule\Model\ResourceModel\AbstractResource
7979
*/
8080
protected $entityManager;
8181

82+
/**
83+
* Store associated with rule entities information map
84+
*
85+
* @var array
86+
*/
87+
protected $_associatedEntitiesMap = [];
88+
8289
/**
8390
* Rule constructor.
8491
* @param \Magento\Framework\Model\ResourceModel\Db\Context $context
@@ -93,6 +100,7 @@ class Rule extends \Magento\Rule\Model\ResourceModel\AbstractResource
93100
* @param PriceCurrencyInterface $priceCurrency
94101
* @param string|null $connectionName
95102
* @param EntityManager|null $entityManager
103+
* @param \Magento\Framework\DataObject|null $associatedEntityMap
96104
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
97105
*/
98106
public function __construct(
@@ -107,7 +115,8 @@ public function __construct(
107115
\Magento\Framework\Stdlib\DateTime $dateTime,
108116
PriceCurrencyInterface $priceCurrency,
109117
$connectionName = null,
110-
?EntityManager $entityManager = null
118+
?EntityManager $entityManager = null,
119+
\Magento\Framework\DataObject $associatedEntityMap = null
111120
) {
112121
$this->_storeManager = $storeManager;
113122
$this->_conditionFactory = $conditionFactory;
@@ -119,7 +128,7 @@ public function __construct(
119128
$this->dateTime = $dateTime;
120129
$this->priceCurrency = $priceCurrency;
121130
$this->entityManager = $entityManager ?? ObjectManager::getInstance()->get(EntityManager::class);
122-
$this->_associatedEntitiesMap = ObjectManager::getInstance()
131+
$this->_associatedEntitiesMap = $associatedEntityMap ?? ObjectManager::getInstance()
123132
// phpstan:ignore this is a virtual class
124133
->get(\Magento\CatalogRule\Model\ResourceModel\Rule\AssociatedEntityMap::class)
125134
->getData();

app/code/Magento/CatalogRule/Test/Unit/Model/ResourceModel/RuleTest.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,24 @@ protected function setUp(): void
6464
$context = $this->createMock(Context::class);
6565
$context->expects($this->once())->method('getResources')->willReturn($this->resource);
6666

67+
$associatedEntitiesMap = $this->createPartialMock(DataObject::class, ['getData']);
68+
$associatedEntitiesMap->expects($this->any())
69+
->method('getData')
70+
->willReturn(
71+
[
72+
'website' => [
73+
'associations_table' => 'catalogrule_website',
74+
'rule_id_field' => 'rule_id',
75+
'entity_id_field' => 'website_id'
76+
],
77+
'customer_group' => [
78+
'associations_table' => 'catalogrule_customer_group',
79+
'rule_id_field' => 'rule_id',
80+
'entity_id_field' => 'customer_group_id'
81+
],
82+
]
83+
);
84+
6785
$this->model = new Rule(
6886
$context,
6987
$this->createMock(StoreManagerInterface::class),
@@ -77,6 +95,7 @@ protected function setUp(): void
7795
$this->createMock(PriceCurrencyInterface::class),
7896
null,
7997
$this->createMock(EntityManager::class),
98+
$associatedEntitiesMap
8099
);
81100
}
82101

app/code/Magento/Fedex/Test/Unit/Model/CarrierTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -945,7 +945,7 @@ public function testGetTracking($tracking, $shipTimeStamp, $expectedDate, $expec
945945
*
946946
* @return array
947947
*/
948-
public function shipDateDataProvider(): array
948+
public static function shipDateDataProvider(): array
949949
{
950950
return [
951951
'tracking1' => [
@@ -1111,6 +1111,7 @@ private function getRateMethodFactory()
11111111
$priceCurrency = $this->getMockForAbstractClass(PriceCurrencyInterface::class);
11121112
$rateMethod = $this->getMockBuilder(Method::class)
11131113
->setConstructorArgs(['priceCurrency' => $priceCurrency])
1114+
->onlyMethods([])
11141115
->getMock();
11151116
$rateMethodFactory = $this->getMockBuilder(MethodFactory::class)
11161117
->disableOriginalConstructor()

app/code/Magento/ImportExport/Test/Unit/Helper/ReportTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,7 @@ public function testGetSummaryStats()
221221
$localeEmulator = $this->getMockForAbstractClass(LocaleEmulatorInterface::class);
222222
$localeEmulator->method('emulate')
223223
->willReturnCallback(fn (callable $callback) => $callback());
224+
$this->objectManagerHelper->prepareObjectManager();
224225
$import = new Import(
225226
$logger,
226227
$filesystem,

app/code/Magento/Theme/Test/Unit/Helper/StorageTest.php

Lines changed: 38 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
use Magento\Framework\Url\EncoderInterface;
1818
use Magento\Framework\View\Design\Theme\Customization;
1919
use Magento\Framework\View\Design\Theme\FlyweightFactory;
20+
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
21+
use Magento\Framework\Filesystem\Io\File;
2022
use Magento\Theme\Helper\Storage;
2123
use Magento\Theme\Model\Theme;
2224
use PHPUnit\Framework\MockObject\MockObject;
@@ -93,6 +95,11 @@ class StorageTest extends TestCase
9395
*/
9496
private $filesystemDriver;
9597

98+
/**
99+
* @var File|MockObject
100+
*/
101+
private $file;
102+
96103
/**
97104
* @inheritDoc
98105
*/
@@ -125,17 +132,29 @@ protected function setUp(): void
125132
$this->contextHelper->expects($this->any())->method('getUrlDecoder')->willReturn($this->urlDecoder);
126133
$this->themeFactory->expects($this->any())->method('create')->willReturn($this->theme);
127134
$this->filesystemDriver = $this->createMock(DriverInterface::class);
135+
$this->file = $this->createMock(File::class);
136+
137+
$this->file->expects($this->any())
138+
->method('getPathInfo')
139+
->willReturnCallback(
140+
function ($path) {
141+
return pathinfo($path);
142+
}
143+
);
128144

129145
$this->theme->expects($this->any())
130146
->method('getCustomization')
131147
->willReturn($this->customization);
132148

149+
// $objectManager = new ObjectManager($this);
150+
// $objectManager->prepareObjectManager();
151+
133152
$this->helper = new Storage(
134153
$this->contextHelper,
135154
$this->filesystem,
136155
$this->session,
137156
$this->themeFactory,
138-
null,
157+
$this->file,
139158
$this->filesystemDriver
140159
);
141160
}
@@ -190,6 +209,8 @@ public function testGetThumbnailDirectory(): void
190209
['root', 'image', \Magento\Theme\Model\Wysiwyg\Storage::THUMBNAIL_DIRECTORY]
191210
);
192211

212+
213+
193214
$this->assertEquals($thumbnailDir, $this->helper->getThumbnailDirectory($imagePath));
194215
}
195216

@@ -443,7 +464,8 @@ public function testGetThemeNotFound(): void
443464
$this->contextHelper,
444465
$this->filesystem,
445466
$this->session,
446-
$this->themeFactory
467+
$this->themeFactory,
468+
$this->file
447469
);
448470
$helper->getStorageRoot();
449471
}
@@ -519,14 +541,13 @@ private function initializeDefaultRequestMock(): void
519541
{
520542
$this->request
521543
->method('getParam')
522-
->withConsecutive(
523-
[Storage::PARAM_THEME_ID],
524-
[Storage::PARAM_CONTENT_TYPE]
525-
)
526-
->willReturnOnConsecutiveCalls(
527-
6,
528-
\Magento\Theme\Model\Wysiwyg\Storage::TYPE_IMAGE
529-
);
544+
->willReturnCallback(function ($param) {
545+
return match ($param) {
546+
Storage::PARAM_THEME_ID => 6,
547+
Storage::PARAM_CONTENT_TYPE => \Magento\Theme\Model\Wysiwyg\Storage::TYPE_IMAGE,
548+
default => '',
549+
};
550+
});
530551
}
531552

532553
/**
@@ -546,15 +567,19 @@ private function resetRequestMock(array $withArgs, array $willReturnArgs): void
546567
$this->contextHelper->expects($this->any())->method('getRequest')->willReturn($this->request);
547568
$this->request
548569
->method('getParam')
549-
->withConsecutive(...$withArgs)
550-
->willReturnOnConsecutiveCalls(...$willReturnArgs);
570+
->willReturnCallback(function ($withArgs) use ($willReturnArgs) {
571+
static $callCount = 0;
572+
$returnValue = $willReturnArgs[$callCount] ?? null;
573+
$callCount++;
574+
return $returnValue;
575+
});
551576

552577
$this->helper = new Storage(
553578
$this->contextHelper,
554579
$this->filesystem,
555580
$this->session,
556581
$this->themeFactory,
557-
null,
582+
$this->file,
558583
$this->filesystemDriver
559584
);
560585
}

vendor/.htaccess

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<IfVersion < 2.4>
2+
order allow,deny
3+
deny from all
4+
</IfVersion>
5+
<IfVersion >= 2.4>
6+
Require all denied
7+
</IfVersion>

xdebug-3.3.1.tgz

-253 KB
Binary file not shown.

0 commit comments

Comments
 (0)