Skip to content

Commit 6c54ac2

Browse files
Raj MohanRaj Mohan
authored andcommitted
AC-12092_PHPUnit10: PHPUnit10 Fixes for Magento Framework Modules
1 parent ca90622 commit 6c54ac2

File tree

11 files changed

+77
-42
lines changed

11 files changed

+77
-42
lines changed

lib/internal/Magento/Framework/Code/Test/Unit/GeneratedFilesTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ public function itDoesNotCleanGeneratedFilesWhenCheckingProcessLockDueToExceptio
297297
*
298298
* @return array
299299
*/
300-
public function itDoesNotCleanGeneratedFilesDueToExceptionsDataProvider()
300+
public static function itDoesNotCleanGeneratedFilesDueToExceptionsDataProvider()
301301
{
302302
return [
303303
RuntimeException::class => [RuntimeException::class],

lib/internal/Magento/Framework/DB/Test/Unit/FieldDataConverterTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ public function testConvertBatchSizeFromEnv($envBatchSize, $usedBatchSize)
201201
/**
202202
* @return array
203203
*/
204-
public function convertBatchSizeFromEnvDataProvider()
204+
public static function convertBatchSizeFromEnvDataProvider()
205205
{
206206
return [
207207
[null, FieldDataConverter::DEFAULT_BATCH_SIZE],
@@ -261,7 +261,7 @@ public function testConvertBatchSizeFromEnvInvalid($batchSize)
261261
/**
262262
* @return array
263263
*/
264-
public function convertBatchSizeFromEnvInvalidDataProvider()
264+
public static function convertBatchSizeFromEnvInvalidDataProvider()
265265
{
266266
return [
267267
['value'],

lib/internal/Magento/Framework/DB/Test/Unit/Platform/QuoteTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ public function testQuoteTableAs($identifier, $alias, $expectedResult)
162162
/**
163163
* @return array
164164
*/
165-
public function getExpressionToQuoteDataProvider()
165+
public static function getExpressionToQuoteDataProvider()
166166
{
167167
return [
168168
['string', null, 'string'],
@@ -175,7 +175,7 @@ public function getExpressionToQuoteDataProvider()
175175
/**
176176
* @return array
177177
*/
178-
public function getSelectToQuoteDataProvider()
178+
public static function getSelectToQuoteDataProvider()
179179
{
180180
return [
181181
['string', null, '(string)'],
@@ -188,7 +188,7 @@ public function getSelectToQuoteDataProvider()
188188
/**
189189
* @return array
190190
*/
191-
public function getStringArrayToQuoteDataProvider()
191+
public static function getStringArrayToQuoteDataProvider()
192192
{
193193
return [
194194
['some string', null, '`some string`'],
@@ -202,9 +202,9 @@ public function getStringArrayToQuoteDataProvider()
202202
/**
203203
* @return array
204204
*/
205-
public function getStringArrayToQuoteWithAliasDataProvider()
205+
public static function getStringArrayToQuoteWithAliasDataProvider()
206206
{
207-
$variations = $this->getStringArrayToQuoteDataProvider();
207+
$variations = self::getStringArrayToQuoteDataProvider();
208208
return array_merge($variations, [
209209
['string', 'alias', '`string` ' . Select::SQL_AS . ' `alias`'],
210210
['alias.string', 'alias', '`alias`.`string` ' . Select::SQL_AS . ' `alias`'],

lib/internal/Magento/Framework/Data/Test/Unit/Form/Element/DateTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ public function testGetElementHtmlDateFormat($fieldName)
9292
/**
9393
* @return array
9494
*/
95-
public function providerGetElementHtmlDateFormat()
95+
public static function providerGetElementHtmlDateFormat()
9696
{
9797
return [
9898
['date_format'],

lib/internal/Magento/Framework/Data/Test/Unit/Form/Element/MultilineTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public function testGetEscapedValue($value, $index, $resultValue)
8484
/**
8585
* @return array
8686
*/
87-
public function dataProviderValues()
87+
public static function dataProviderValues()
8888
{
8989
return [
9090
["", 0, ""],

lib/internal/Magento/Framework/Encryption/Test/Unit/EncryptorTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ public function testValidateHash($password, $hash, $expected, int $requiresVersi
175175
*
176176
* @return array
177177
*/
178-
public function validateHashDataProvider(): array
178+
public static function validateHashDataProvider(): array
179179
{
180180
return [
181181
['password', 'hash:salt:1', false, 1],
@@ -235,7 +235,7 @@ public function testDecryptWithEmptyKey($key): void
235235
*
236236
* @return array
237237
*/
238-
public function emptyKeyDataProvider(): array
238+
public static function emptyKeyDataProvider(): array
239239
{
240240
return [[null], [0], [''], ['0']];
241241
}
@@ -356,7 +356,7 @@ public function testValidateKeyInvalid(): void
356356
*
357357
* @return array
358358
*/
359-
public function useSpecifiedHashingAlgoDataProvider(): array
359+
public static function useSpecifiedHashingAlgoDataProvider(): array
360360
{
361361
return [
362362
[

lib/internal/Magento/Framework/File/Test/Unit/UploaderTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public function testGetCorrectFileName($fileName, $expectedCorrectedFileName)
8181
/**
8282
* @return array
8383
*/
84-
public function getCorrectFileNameProvider()
84+
public static function getCorrectFileNameProvider()
8585
{
8686
return [
8787
[
@@ -128,7 +128,7 @@ public function testCheckAllowedExtension(bool $isValid, string $extension)
128128
/**
129129
* @return array
130130
*/
131-
public function checkAllowedExtensionProvider(): array
131+
public static function checkAllowedExtensionProvider(): array
132132
{
133133
return [
134134
[

lib/internal/Magento/Framework/Filesystem/Test/Unit/Directory/WriteTest.php

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -167,14 +167,15 @@ private function getAbsolutePath($path)
167167
*/
168168
public function testRenameFile($sourcePath, $targetPath, $targetDir)
169169
{
170-
if ($targetDir !== null) {
170+
if ($targetDir !== null && is_callable($targetDir)) {
171+
$targetDir = $targetDir($this);
171172
/** @noinspection PhpUndefinedFieldInspection */
172173
$targetDirPath = 'TARGET_PATH/';
173174
$targetDir->expects($this->once())
174175
->method('getAbsolutePath')
175176
->with($targetPath)
176177
->willReturn($targetDirPath . $targetPath);
177-
$targetDir->expects($this->once())
178+
$targetDir->expects($this->any())
178179
->method('isExists')
179180
->with(dirname($targetPath))
180181
->willReturn(false);
@@ -205,7 +206,7 @@ public function testRenameFile($sourcePath, $targetPath, $targetDir)
205206
/**
206207
* @return array
207208
*/
208-
public function getFilePathsDataProvider()
209+
public static function getFilePathsDataProvider()
209210
{
210211
return [
211212
[
@@ -216,11 +217,16 @@ public function getFilePathsDataProvider()
216217
[
217218
'path/to/source.file',
218219
'path/to/target.file',
219-
$this->getMockBuilder(WriteInterface::class)
220-
->onlyMethods(['getAbsolutePath', 'create'])
221-
->addMethods(['isExists'])
222-
->getMockForAbstractClass(),
220+
static fn (self $testCase) => $testCase->getWriterMock(),
223221
],
224222
];
225223
}
224+
225+
public function getWriterMock()
226+
{
227+
return $this->getMockBuilder(WriteInterface::class)
228+
->onlyMethods(['getAbsolutePath', 'create'])
229+
->addMethods(['isExists'])
230+
->getMockForAbstractClass();
231+
}
226232
}

lib/internal/Magento/Framework/Filesystem/Test/Unit/Driver/HttpTest.php

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public function testIsExists(string $status, bool $result): void
6060
*
6161
* @return array
6262
*/
63-
public function dataProviderForTestIsExists(): array
63+
public static function dataProviderForTestIsExists(): array
6464
{
6565
return [['200 OK', true], ['404 Not Found', false]];
6666
}
@@ -69,12 +69,15 @@ public function dataProviderForTestIsExists(): array
6969
* Verify Stat.
7070
*
7171
* @param array $headers
72-
* @param array $result
72+
* @param \Closure $result
7373
* @dataProvider dataProviderForTestStat
7474
* @return void
7575
*/
76-
public function testStat(array $headers, array $result): void
76+
public function testStat(array $headers, \Closure $result): void
7777
{
78+
if (is_callable($result)) {
79+
$result = $result($this);
80+
}
7881
self::$headers = $headers;
7982
$this->assertEquals($result, (new Http())->stat(''));
8083
}
@@ -84,7 +87,7 @@ public function testStat(array $headers, array $result): void
8487
*
8588
* @return array
8689
*/
87-
public function dataProviderForTestStat(): array
90+
public static function dataProviderForTestStat(): array
8891
{
8992
$headers1 = [
9093
'Content-Length' => 128,
@@ -93,11 +96,11 @@ public function dataProviderForTestStat(): array
9396
'Content-Disposition' => 1024,
9497
];
9598

96-
$result1 = $this->_resultForStat(
99+
$result1 = static fn (self $testCase) => $testCase->_resultForStat(
97100
['size' => 128, 'type' => 'type', 'mtime' => '2013-12-19T17:41:45+00:00', 'disposition' => 1024]
98101
);
99102

100-
return [[[], $this->_resultForStat()], [$headers1, $result1]];
103+
return [[[], static fn (self $testCase) => $testCase->_resultForStat()], [$headers1, $result1]];
101104
}
102105

103106
/**

lib/internal/Magento/Framework/MessageQueue/Test/Unit/MessageProcessorLoaderTest.php

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,10 @@ protected function setUp(): void
6969
*/
7070
public function testLoad($message)
7171
{
72+
if (is_callable($message)) {
73+
$message = $message($this);
74+
}
75+
7276
$messageTopic = 'topic';
7377
$messages = [
7478
$messageTopic => [$message]
@@ -85,18 +89,26 @@ public function testLoad($message)
8589
*
8690
* @return array
8791
*/
88-
public function loadDataProvider()
92+
public static function loadDataProvider()
8993
{
90-
$mergedMessage = $this->getMockBuilder(MergedMessageInterface::class)
91-
->disableOriginalConstructor()
92-
->getMockForAbstractClass();
93-
$message = $this->getMockBuilder(EnvelopeInterface::class)
94-
->disableOriginalConstructor()
95-
->getMockForAbstractClass();
94+
$mergedMessage = static fn (self $testCase) => $testCase->getMergedMessageInterfaceMock();
95+
$message = static fn (self $testCase) => $testCase->getEnvelopeInterfaceMock();
9696

9797
return [
9898
[$mergedMessage],
9999
[$message]
100100
];
101101
}
102+
103+
public function getMergedMessageInterfaceMock() {
104+
return $this->getMockBuilder(MergedMessageInterface::class)
105+
->disableOriginalConstructor()
106+
->getMockForAbstractClass();
107+
}
108+
109+
public function getEnvelopeInterfaceMock() {
110+
return $this->getMockBuilder(EnvelopeInterface::class)
111+
->disableOriginalConstructor()
112+
->getMockForAbstractClass();
113+
}
102114
}

0 commit comments

Comments
 (0)