Skip to content

Commit f5fd14e

Browse files
ShradddhaShradddha
authored andcommitted
AC-12092:: Remove Deprecations- PhpUnit10 Unit Tests
1 parent 1baa893 commit f5fd14e

File tree

11 files changed

+55
-41
lines changed

11 files changed

+55
-41
lines changed

app/code/Magento/AdminNotification/Test/Unit/Model/System/Message/CacheOutdatedTest.php

Lines changed: 28 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -57,62 +57,64 @@ protected function setUp(): void
5757

5858
/**
5959
* @param string $expectedSum
60-
* @param array $types
60+
* @param array $cacheTypes
6161
* @dataProvider getIdentityDataProvider
6262
*/
63-
public function testGetIdentity($expectedSum, $types)
63+
public function testGetIdentity($expectedSum, $cacheTypes)
6464
{
65-
$cacheTypes = [];
66-
foreach ($types as $type)
67-
{
68-
$cacheTypeMock = $this->getMockBuilder(\stdClass::class)->addMethods(['getCacheType'])
69-
->disableOriginalConstructor()
70-
->getMock();
71-
$cacheTypeMock->method('getCacheType')->willReturn($type);
72-
$cacheTypes[] = $cacheTypeMock;
65+
$cacheType1 = [];
66+
foreach($cacheTypes as $cacheType){
67+
$cacheType1[] = $cacheType($this);
7368
}
7469

7570
$this->_cacheTypeListMock->method(
7671
'getInvalidated'
7772
)->willReturn(
78-
$cacheTypes
73+
$cacheType1
7974
);
8075
$this->assertEquals($expectedSum, $this->_messageModel->getIdentity());
8176
}
8277

78+
protected function getMockForStdClass($mockReturn)
79+
{
80+
$cacheTypeMock = $this->getMockBuilder(\stdClass::class)->addMethods(['getCacheType'])
81+
->disableOriginalConstructor()
82+
->getMock();
83+
$cacheTypeMock->method('getCacheType')->willReturn($mockReturn);
84+
return $cacheTypeMock;
85+
}
86+
8387
/**
8488
* @return array
8589
*/
8690
public static function getIdentityDataProvider()
8791
{
92+
$cacheTypeMock1 = static fn (self $testCase) => $testCase->getMockForStdClass('Simple');
93+
$cacheTypeMock2 = static fn (self $testCase) => $testCase->getMockForStdClass('Advanced');
94+
8895
return [
89-
['c13cfaddc2c53e8d32f59bfe89719beb', ['Simple']],
90-
['69aacdf14d1d5fcef7168b9ac308215e', ['Simple', 'Advanced']]
96+
['c13cfaddc2c53e8d32f59bfe89719beb', [$cacheTypeMock1]],
97+
['69aacdf14d1d5fcef7168b9ac308215e', [$cacheTypeMock1, $cacheTypeMock2]]
9198
];
9299
}
93100

94101
/**
95102
* @param bool $expected
96103
* @param bool $allowed
97-
* @param array $types
104+
* @param array $cacheTypes
98105
* @dataProvider isDisplayedDataProvider
99106
*/
100-
public function testIsDisplayed($expected, $allowed, $types)
107+
public function testIsDisplayed($expected, $allowed, $cacheTypes)
101108
{
102-
$cacheTypes = [];
103-
foreach ($types as $type)
104-
{
105-
$cacheTypeMock = $this->getMockBuilder(\stdClass::class)->addMethods(['getCacheType'])
106-
->disableOriginalConstructor()
107-
->getMock();
108-
$cacheTypeMock->method('getCacheType')->willReturn($type);
109-
$cacheTypes[] = $cacheTypeMock;
109+
$cacheType1 = [];
110+
foreach($cacheTypes as $cacheType){
111+
$cacheType1[] = $cacheType($this);
110112
}
111113
$this->_authorizationMock->expects($this->once())->method('isAllowed')->willReturn($allowed);
112114
$this->_cacheTypeListMock->method(
113115
'getInvalidated'
114116
)->willReturn(
115-
$cacheTypes
117+
$cacheType1
116118
);
117119
$this->assertEquals($expected, $this->_messageModel->isDisplayed());
118120
}
@@ -122,7 +124,8 @@ public function testIsDisplayed($expected, $allowed, $types)
122124
*/
123125
public static function isDisplayedDataProvider()
124126
{
125-
$cacheTypes = ['someVal', 'someVal'];
127+
$cacheTypesMock = static fn (self $testCase) => $testCase->getMockForStdClass('someVal');
128+
$cacheTypes = [$cacheTypesMock, $cacheTypesMock];
126129
return [
127130
[false, false, []],
128131
[false, false, $cacheTypes],

app/code/Magento/CustomerImportExport/Test/Unit/Model/Import/CustomerCompositeTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@
2121
use Magento\Framework\Filesystem\Directory\Write;
2222
use Magento\Framework\Filesystem\Driver\File;
2323
use Magento\Framework\Filesystem\File\Read;
24+
use Magento\Framework\Serialize\Serializer\Json;
2425
use Magento\Framework\Stdlib\StringUtils;
26+
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
2527
use Magento\Framework\Translate\InlineInterface;
2628
use Magento\ImportExport\Model\Import;
2729
use Magento\ImportExport\Model\Import\AbstractSource;
@@ -177,6 +179,15 @@ protected function setUp(): void
177179
*/
178180
protected function _createModelMock($data)
179181
{
182+
$objectManager = new ObjectManager($this);
183+
$objects = [
184+
[
185+
Json::class,
186+
$this->createMock(Json::class)
187+
]
188+
];
189+
$objectManager->prepareObjectManager($objects);
190+
180191
return new CustomerComposite(
181192
$this->_string,
182193
$this->_scopeConfigMock,

app/code/Magento/Multishipping/Test/Unit/Model/Checkout/Type/MultishippingTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1191,7 +1191,7 @@ private function getCurrencyMock($shippingPrice): MockObject
11911191
*
11921192
* @return array
11931193
*/
1194-
public function getConfigCreateOrders(): array
1194+
public static function getConfigCreateOrders(): array
11951195
{
11961196
return [
11971197
[

app/code/Magento/Multishipping/Test/Unit/Model/DisableMultishippingTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public function testExecuteWithMultishippingModeEnabled(bool $hasShippingAssignm
8484
*
8585
* @return array
8686
*/
87-
public function executeWithMultishippingModeEnabledDataProvider(): array
87+
public static function executeWithMultishippingModeEnabledDataProvider(): array
8888
{
8989
return [
9090
'check_with_shipping_assignments' => [true],

app/code/Magento/Multishipping/Test/Unit/Model/Payment/Method/Specification/EnabledTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public function testIsSatisfiedBy($methodsInfo, $result)
7575
*
7676
* @return array
7777
*/
78-
public function methodsDataProvider()
78+
public static function methodsDataProvider()
7979
{
8080
return [
8181
[['allow_multiple_address' => 1], true],

app/code/Magento/Multishipping/Test/Unit/Plugin/DisableMultishippingModeTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ public function testPluginWithChangedMultishippingMode(bool $totalsCollectedBefo
9292
*
9393
* @return array
9494
*/
95-
public function pluginWithChangedMultishippingModeDataProvider(): array
95+
public static function pluginWithChangedMultishippingModeDataProvider(): array
9696
{
9797
return [
9898
'check_when_totals_are_collected' => [true],

app/code/Magento/Paypal/Test/Unit/Model/InfoTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ private function _prepareLabelValuesExpectation($expectation)
156156
*
157157
* @return array
158158
*/
159-
public function additionalInfoDataProvider()
159+
public static function additionalInfoDataProvider()
160160
{
161161
return include __DIR__ . '/_files/additional_info_data.php';
162162
}

app/code/Magento/Translation/Test/Unit/Model/Json/PreProcessorTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -144,25 +144,25 @@ public function testProcess(array $data, array $expects)
144144
*
145145
* @return array
146146
*/
147-
public function processDataProvider()
147+
public static function processDataProvider()
148148
{
149149
return [
150150
[
151151
[
152152
'area_code' => FrontNameResolver::AREA_CODE
153153
],
154154
[
155-
'areaList_getArea' => $this->never(),
156-
'area_load' => $this->never(),
155+
'areaList_getArea' => self::never(),
156+
'area_load' => self::never(),
157157
]
158158
],
159159
[
160160
[
161161
'area_code' => 'frontend'
162162
],
163163
[
164-
'areaList_getArea' => $this->once(),
165-
'area_load' => $this->once(),
164+
'areaList_getArea' => self::once(),
165+
'area_load' => self::once(),
166166
]
167167
],
168168
];

app/code/Magento/Vault/Test/Unit/Model/Method/VaultTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ public function testAuthorizeNoTokenMetadata(array $additionalInfo)
9393
* Get list of additional information variations
9494
* @return array
9595
*/
96-
public function additionalInfoDataProvider()
96+
public static function additionalInfoDataProvider()
9797
{
9898
return [
9999
['additionalInfo' => []],
@@ -380,7 +380,7 @@ public function testCanUseInternal($configValue, $paymentValue, $expected)
380380
* Get list of variations for testing canUseInternal method
381381
* @return array
382382
*/
383-
public function internalUsageDataProvider()
383+
public static function internalUsageDataProvider()
384384
{
385385
return [
386386
['configValue' => true, 'paymentValue' => true, 'expected' => true],

lib/internal/Magento/Framework/HTTP/Test/Unit/HeaderTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public function testHttpMethods($method, $clean, $expectedValue)
7373
/**
7474
* @return array
7575
*/
76-
public function methodsDataProvider()
76+
public static function methodsDataProvider()
7777
{
7878
return [
7979
'getHttpHost clean true' => [
@@ -154,7 +154,7 @@ public function testGetRequestUri($clean, $expectedValue)
154154
/**
155155
* @return array
156156
*/
157-
public function getRequestUriDataProvider()
157+
public static function getRequestUriDataProvider()
158158
{
159159
return [
160160
'getRequestUri clean true' => ['clean' => true, 'expectedValue' => 'converted value'],

0 commit comments

Comments
 (0)