Skip to content

Commit 13d3e59

Browse files
Raj MohanRaj Mohan
authored andcommitted
AC-12092_PHPUnit10: PHPUnit Deprecation Error Fixes
1 parent 424ad2a commit 13d3e59

File tree

3 files changed

+77
-95
lines changed

3 files changed

+77
-95
lines changed

lib/internal/Magento/Framework/App/Test/Unit/Router/ActionListTest.php

Lines changed: 34 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,12 @@ public function testConstructActionsNoCached()
108108
*/
109109
public function testGet($module, $area, $namespace, $action, $data, $isInstantiable, $expected)
110110
{
111-
if ($expected!=null) {
111+
if (is_callable($expected)) {
112112
$expected = $expected($this);
113113
}
114+
if (is_object($expected)) {
115+
$expected = get_class($expected);
116+
}
114117
$this->reflectionClass->method('isInstantiable')->willReturn($isInstantiable);
115118

116119
$this->cacheMock->expects($this->once())
@@ -130,59 +133,62 @@ public function testGet($module, $area, $namespace, $action, $data, $isInstantia
130133
));
131134
}
132135

133-
protected function getMockForActionInterface()
134-
{
135-
$mockClassName = 'Mock_Action_Class';
136-
$actionClassObject = $this->getMockForAbstractClass(
137-
ActionInterface::class,
138-
[],
139-
$mockClassName,
140-
true,
141-
true,
142-
true,
143-
['execute', 'getResponse']
144-
);
145-
146-
$actionClass = get_class($actionClassObject);
147-
return $actionClass;
148-
}
149-
150136
/**
151137
* @return array
152138
*/
153139
public static function getDataProvider()
154140
{
155-
$mockClassName = 'Mock_Action_Class';
156-
157-
$actionClass = static fn (self $testCase) => $testCase->getMockForActionInterface();
158-
159141
return [
160142
[
161143
'Magento_Module',
162144
'Area',
163145
'Namespace',
164146
'Index',
165-
['magento\module\controller\area\namespace\index' => $mockClassName],
147+
['magento\module\controller\area\namespace\index' => 'Mock_Action_Class_1'],
166148
true,
167-
$actionClass
149+
static fn (self $testCase) => $testCase->getMockForAbstractClass(
150+
ActionInterface::class,
151+
[],
152+
'Mock_Action_Class_1',
153+
true,
154+
true,
155+
true,
156+
['execute', 'getResponse']
157+
)
168158
],
169159
[
170160
'Magento_Module',
171161
'',
172162
'Namespace',
173163
'Index',
174-
['magento\module\controller\namespace\index' => $mockClassName],
164+
['magento\module\controller\namespace\index' => 'Mock_Action_Class_2'],
175165
true,
176-
$actionClass
166+
static fn (self $testCase) => $testCase->getMockForAbstractClass(
167+
ActionInterface::class,
168+
[],
169+
'Mock_Action_Class_2',
170+
true,
171+
true,
172+
true,
173+
['execute', 'getResponse']
174+
)
177175
],
178176
[
179177
'Magento_Module',
180178
'Area',
181179
'Namespace',
182180
'Catch',
183-
['magento\module\controller\area\namespace\catchaction' => $mockClassName],
181+
['magento\module\controller\area\namespace\catchaction' => 'Mock_Action_Class_3'],
184182
true,
185-
$actionClass
183+
static fn (self $testCase) => $testCase->getMockForAbstractClass(
184+
ActionInterface::class,
185+
[],
186+
'Mock_Action_Class_3',
187+
true,
188+
true,
189+
true,
190+
['execute', 'getResponse']
191+
)
186192
],
187193
[
188194
'Magento_Module',

lib/internal/Magento/Framework/Profiler/Test/Unit/Driver/FactoryTest.php

Lines changed: 20 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php declare(strict_types=1);
22
/**
3-
* Copyright © Magento, Inc. All rights reserved.
4-
* See COPYING.txt for license details.
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
55
*
66
* Test class for \Magento\Framework\Profiler\Driver\Factory
77
*/
@@ -79,49 +79,35 @@ public static function createDataProvider()
7979
return [
8080
'Prefix and concrete type' => [
8181
['type' => 'test'],
82-
static fn (self $testCase) => $testCase->getMockForDriverClass()['testDriverClass']
82+
static fn (self $testCase) => $testCase->getTestDriverClassMock()
8383
],
8484
'Prefix and default type' => [
8585
[],
86-
static fn (self $testCase) => $testCase->getMockForDriverClass()['defaultDriverClass']
86+
static fn (self $testCase) => $testCase->getDefaultDriverClassMock()
8787
],
8888
'Concrete class' => [
89-
['type' => static fn (self $testCase) => $testCase->getMockForDriverClass()['testDriverClass']],
90-
static fn (self $testCase) => $testCase->getMockForDriverClass()['testDriverClass']
89+
['type' => 'Magento_Framework_Profiler_Driver_Test_Foo'],
90+
static fn (self $testCase) => $testCase->getTestDriverClassMock(
91+
'Magento_Framework_Profiler_Driver_Test_Foo'
92+
)
9193
]
9294
];
9395
}
9496

95-
public function getMockForDriverClass()
97+
protected function getDefaultDriverClassMock($mockClass = 'Magento_Framework_Profiler_Driver_Test_Default')
9698
{
97-
$defaultDriverClassMock = $this->getMockForAbstractClass(
98-
DriverInterface::class,
99-
[],
100-
'Magento_Framework_Profiler_Driver_Test_Default',
101-
true,
102-
true,
103-
true,
104-
[]
105-
);
106-
107-
$defaultDriverClass = get_class($defaultDriverClassMock);
108-
109-
$testDriverClassMock = $this->getMockForAbstractClass(
110-
DriverInterface::class,
111-
[],
112-
'Magento_Framework_Profiler_Driver_Test_Test',
113-
true,
114-
true,
115-
true,
116-
[]
117-
);
118-
119-
$testDriverClass = get_class($testDriverClassMock);
99+
$defaultDriverClassMock = $this->getMockBuilder(DriverInterface::class)
100+
->setMockClassName($mockClass)
101+
->getMock();
102+
return get_class($defaultDriverClassMock);
103+
}
120104

121-
return [
122-
'defaultDriverClass' => $defaultDriverClass,
123-
'testDriverClass' => $testDriverClass
124-
];
105+
protected function getTestDriverClassMock($mockClass = 'Magento_Framework_Profiler_Driver_Test_Test')
106+
{
107+
$testDriverClassMock = $this->getMockBuilder(DriverInterface::class)
108+
->setMockClassName($mockClass)
109+
->getMock();
110+
return get_class($testDriverClassMock);
125111
}
126112

127113
public function testCreateUndefinedClass()

lib/internal/Magento/Framework/Profiler/Test/Unit/Driver/Standard/Output/FactoryTest.php

Lines changed: 23 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public function testDefaultConstructor()
5555

5656
/**
5757
* @dataProvider createDataProvider
58-
* @param array $configData
58+
* @param array|string $configData
5959
* @param string $expectedClass
6060
*/
6161
public function testCreate($configData, $expectedClass)
@@ -81,15 +81,17 @@ public static function createDataProvider(): array
8181
return [
8282
'Prefix and concrete type' => [
8383
['type' => 'test'],
84-
static fn(self $testCase) => $testCase->getOutputClassMock()['testOutputClass']
84+
static fn(self $testCase) => $testCase->getOutputClassTestMock()
8585
],
8686
'Prefix and default type' => [
8787
[],
88-
static fn(self $testCase) => $testCase->getOutputClassMock()['defaultOutputClass']
88+
static fn(self $testCase) => $testCase->getOutputClassDefaultMock()
8989
],
9090
'Concrete class' => [
91-
['type' => static fn(self $testCase) => $testCase->getOutputClassMock()['testOutputClass']],
92-
static fn(self $testCase) => $testCase->getOutputClassMock()['testOutputClass']
91+
['type' => 'Magento_Framework_Profiler_Driver_Standard_Output_Test_Test_Foo'],
92+
static fn(self $testCase) => $testCase->getOutputClassTestMock(
93+
'Magento_Framework_Profiler_Driver_Standard_Output_Test_Test_Foo'
94+
)
9395
],
9496
];
9597
}
@@ -98,36 +100,24 @@ public static function createDataProvider(): array
98100
* @return array
99101
* @throws \PHPUnit\Framework\MockObject\Exception
100102
*/
101-
public function getOutputClassMock(): array
102-
{
103-
$defaultOutputClassMock = $this->getMockForAbstractClass(
104-
OutputInterface::class,
105-
[],
106-
'Magento_Framework_Profiler_Driver_Standard_Output_Test_Default',
107-
true,
108-
true,
109-
true,
110-
[]
111-
);
112-
113-
$defaultOutputClass = get_class($defaultOutputClassMock);
114-
115-
$testOutputClassMock = $this->getMockForAbstractClass(
116-
OutputInterface::class,
117-
[],
118-
'Magento_Framework_Profiler_Driver_Standard_Output_Test_Test',
119-
true,
120-
true,
121-
true,
122-
[]
123-
);
103+
public function getOutputClassDefaultMock(
104+
$mockClass = 'Magento_Framework_Profiler_Driver_Standard_Output_Test_Default'
105+
): string {
106+
$defaultOutputClassMock = $this->getMockBuilder(OutputInterface::class)
107+
->setMockClassName($mockClass)
108+
->getMock();
109+
110+
return get_class($defaultOutputClassMock);
111+
}
124112

125-
$testOutputClass = get_class($testOutputClassMock);
113+
public function getOutputClassTestMock(
114+
$mockClass = 'Magento_Framework_Profiler_Driver_Standard_Output_Test_Test'
115+
): string {
116+
$testOutputClassMock = $this->getMockBuilder(OutputInterface::class)
117+
->setMockClassName($mockClass)
118+
->getMock();
126119

127-
return [
128-
'defaultOutputClass' => $defaultOutputClass,
129-
'testOutputClass' => $testOutputClass
130-
];
120+
return get_class($testOutputClassMock);
131121
}
132122

133123
public function testCreateUndefinedClass()

0 commit comments

Comments
 (0)