Skip to content

Commit 0762bcb

Browse files
Raj MohanRaj Mohan
authored andcommitted
AC-12092_PHPUnit10: PHPUnit10.5 Deprecation Fixes Framework App, Cache, Code, Validator Modules
1 parent 6c54ac2 commit 0762bcb

File tree

6 files changed

+94
-26
lines changed

6 files changed

+94
-26
lines changed

lib/internal/Magento/Framework/App/Test/Unit/Cache/Type/ConfigTest.php

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,17 +64,27 @@ public function testProxyMethod($method, $params, $expectedResult): void
6464
/**
6565
* @return array
6666
*/
67-
public function proxyMethodDataProvider(): array
67+
public static function proxyMethodDataProvider(): array
6868
{
6969
return [
7070
['test', ['record_id'], 111],
7171
['load', ['record_id'], '111'],
7272
['remove', ['record_id'], true],
73-
['getBackend', [], $this->createMock(\Zend_Cache_Backend::class)],
74-
['getLowLevelFrontend', [], $this->createMock(\Zend_Cache_Core::class)]
73+
['getBackend', [], static fn (self $testCase) => $testCase->createZendCacheBackendMock()],
74+
['getLowLevelFrontend', [], static fn (self $testCase) => $testCase->createZendCacheCoreMock()]
7575
];
7676
}
7777

78+
public function createZendCacheBackendMock()
79+
{
80+
return $this->createMock(\Zend_Cache_Backend::class);
81+
}
82+
83+
public function createZendCacheCoreMock()
84+
{
85+
return $this->createMock(\Zend_Cache_Core::class);
86+
}
87+
7888
public function testSave(): void
7989
{
8090
$expectedResult = new \stdClass();

lib/internal/Magento/Framework/Cache/Test/Unit/Backend/RemoteSynchronizedCacheTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ protected function getMockForMysqlClass()
111111
/**
112112
* @return array
113113
*/
114-
public function initializeWithOutExceptionDataProvider(): array
114+
public static function initializeWithOutExceptionDataProvider(): array
115115
{
116116
$connectionMock = static fn (self $testCase) => $testCase->getMockForMysqlClass();
117117
return [

lib/internal/Magento/Framework/Cache/Test/Unit/Frontend/Adapter/ZendTest.php

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ class ZendTest extends TestCase
2222
*/
2323
public function testProxyMethod($method, $params, $expectedParams, $expectedResult)
2424
{
25+
if (is_callable($expectedResult)) {
26+
$expectedResult = $expectedResult($this);
27+
}
2528
$frontendMock = $this->createMock(\Zend_Cache_Core::class);
2629
$frontendFactory = function () use ($frontendMock) {
2730
return $frontendMock;
@@ -43,7 +46,7 @@ public function testProxyMethod($method, $params, $expectedParams, $expectedResu
4346
/**
4447
* @return array
4548
*/
46-
public function proxyMethodDataProvider()
49+
public static function proxyMethodDataProvider()
4750
{
4851
return [
4952
'test' => ['test', ['record_id'], ['RECORD_ID'], 111],
@@ -77,11 +80,16 @@ public function proxyMethodDataProvider()
7780
'getBackend',
7881
[],
7982
[],
80-
$this->createMock(\Zend_Cache_Backend::class),
83+
static fn (self $testCase) => $testCase->createZendCacheBackendMock(),
8184
]
8285
];
8386
}
8487

88+
public function createZendCacheBackendMock()
89+
{
90+
return $this->createMock(\Zend_Cache_Backend::class);
91+
}
92+
8593
/**
8694
* @param string $cleaningMode
8795
* @param string $expectedErrorMessage
@@ -102,7 +110,7 @@ public function testCleanException($cleaningMode, $expectedErrorMessage)
102110
/**
103111
* @return array
104112
*/
105-
public function cleanExceptionDataProvider()
113+
public static function cleanExceptionDataProvider()
106114
{
107115
return [
108116
'cleaning mode "expired"' => [

lib/internal/Magento/Framework/Cache/Test/Unit/Frontend/Decorator/BareTest.php

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ class BareTest extends TestCase
2222
*/
2323
public function testProxyMethod($method, $params, $expectedResult)
2424
{
25+
if (is_callable($expectedResult)) {
26+
$expectedResult = $expectedResult($this);
27+
}
2528
$frontendMock = $this->getMockForAbstractClass(FrontendInterface::class);
2629

2730
$object = new Bare($frontendMock);
@@ -33,16 +36,26 @@ public function testProxyMethod($method, $params, $expectedResult)
3336
/**
3437
* @return array
3538
*/
36-
public function proxyMethodDataProvider()
39+
public static function proxyMethodDataProvider()
3740
{
3841
return [
3942
['test', ['record_id'], 111],
4043
['load', ['record_id'], '111'],
4144
['save', ['record_value', 'record_id', ['tag'], 555], true],
4245
['remove', ['record_id'], true],
4346
['clean', [\Zend_Cache::CLEANING_MODE_MATCHING_ANY_TAG, ['tag']], true],
44-
['getBackend', [], $this->createMock(\Zend_Cache_Backend::class)],
45-
['getLowLevelFrontend', [], $this->createMock(\Zend_Cache_Core::class)],
47+
['getBackend', [], static fn (self $testCase) => $testCase->createZendCacheBackendMock()],
48+
['getLowLevelFrontend', [], static fn (self $testCase) => $testCase->createZendCacheCoreMock()],
4649
];
4750
}
51+
52+
public function createZendCacheBackendMock()
53+
{
54+
return $this->createMock(\Zend_Cache_Backend::class);
55+
}
56+
57+
public function createZendCacheCoreMock()
58+
{
59+
return $this->createMock(\Zend_Cache_Core::class);
60+
}
4861
}

lib/internal/Magento/Framework/Code/Test/Unit/Generator/ClassGeneratorTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ public function testNamespaceName($actualNamespace, $expectedNamespace)
334334
* DataProvider for testNamespaceName
335335
* @return array
336336
*/
337-
public function providerNamespaces()
337+
public static function providerNamespaces()
338338
{
339339
return [
340340
['Laminas', 'Laminas'],

lib/internal/Magento/Framework/Validator/Test/Unit/Constraint/Option/CallbackTest.php

Lines changed: 52 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -33,52 +33,72 @@ class CallbackTest extends TestCase
3333
*/
3434
public function testGetValue($callback, $expectedResult, $arguments = null, $createInstance = false)
3535
{
36+
if (is_array($callback) && is_callable($callback[0])) {
37+
$callback[0] = $callback[0]($this);
38+
}
3639
$option = new Callback($callback, $arguments, $createInstance);
3740
$this->assertEquals($expectedResult, $option->getValue());
3841
}
3942

4043
/**
4144
* Data provider for testGetValue
4245
*/
43-
public function getConfigDataProvider()
46+
public static function getConfigDataProvider()
4447
{
4548
$closure = function () {
4649
return 'Value from closure';
4750
};
4851

49-
$mock = $this->getMockBuilder(\stdClass::class)
50-
->addMethods(['getValue'])
51-
->getMock();
52-
$mock->method('getValue')
53-
->with('arg1', 'arg2')
54-
->willReturn('Value from mock');
55-
5652
return [
5753
[
5854
$closure,
5955
'Value from closure'
6056
],
6157
[
62-
[$this, 'getTestValue'],
58+
[
59+
static fn (self $testCase) => $testCase->getClassObjectMock()['classObject'],
60+
'getTestValue'
61+
],
6362
self::TEST_VALUE
6463
],
6564
[
6665
[__CLASS__, 'getTestValueStatically'],
6766
self::TEST_VALUE
6867
],
6968
[
70-
[$mock, 'getValue'],
69+
[
70+
static fn (self $testCase) => $testCase->getClassObjectMock()['mock'],
71+
'getValue'
72+
],
7173
'Value from mock', ['arg1', 'arg2']
7274
],
7375
[
74-
[TestCallback::class, 'getId'],
76+
[
77+
TestCallback::class,
78+
'getId'
79+
],
7580
TestCallback::ID,
7681
null,
7782
true
7883
]
7984
];
8085
}
8186

87+
public function getClassObjectMock()
88+
{
89+
$classObject = $this;
90+
$mock = $this->getMockBuilder(\stdClass::class)
91+
->addMethods(['getValue'])
92+
->getMock();
93+
$mock->method('getValue')
94+
->with('arg1', 'arg2')
95+
->willReturn('Value from mock');
96+
return [
97+
'classObject' => $classObject,
98+
'mock' => $mock
99+
];
100+
}
101+
82102
/**
83103
* Get TEST_VALUE from static scope
84104
*/
@@ -137,6 +157,17 @@ public static function setArgumentsDataProvider()
137157
*/
138158
public function testGetValueException($callback, $expectedMessage, $createInstance = false)
139159
{
160+
if (is_array($callback)) {
161+
foreach ($callback as $key => $value) {
162+
if (is_callable($value)) {
163+
$callback[$key] = $value($this);
164+
}
165+
}
166+
} else {
167+
if (is_callable($callback)) {
168+
$callback = $callback($this);
169+
}
170+
}
140171
$this->expectException('InvalidArgumentException');
141172
$option = new Callback($callback, null, $createInstance);
142173
$this->expectException('InvalidArgumentException');
@@ -149,19 +180,20 @@ public function testGetValueException($callback, $expectedMessage, $createInstan
149180
*
150181
* @return array
151182
*/
152-
public function getValueExceptionDataProvider()
183+
public static function getValueExceptionDataProvider()
153184
{
185+
$testObject = static fn (self $testCase) => $testCase->getCallBackTestObject();
154186
return [
155187
[
156188
['Not_Existing_Callback_Class', 'someMethod'],
157189
'Class "Not_Existing_Callback_Class" was not found',
158190
],
159191
[
160-
[$this, 'notExistingMethod'],
192+
[$testObject, 'notExistingMethod'],
161193
'Callback does not callable'
162194
],
163195
[
164-
['object' => $this, 'method' => 'getTestValue'],
196+
['object' => $testObject, 'method' => 'getTestValue'],
165197
'Callback does not callable'
166198
],
167199
[
@@ -173,10 +205,15 @@ public function getValueExceptionDataProvider()
173205
'Callback does not callable'
174206
],
175207
[
176-
[$this, 'getTestValue'],
208+
[$testObject, 'getTestValue'],
177209
'Callable expected to be an array with class name as first element',
178210
true
179211
]
180212
];
181213
}
214+
215+
public function getCallBackTestObject()
216+
{
217+
return $this;
218+
}
182219
}

0 commit comments

Comments
 (0)