Skip to content

Commit f4db7d4

Browse files
committed
MC-33068: Make Unit, Integration, Web-API tests compatible with PHPUnit9
1 parent c926f89 commit f4db7d4

File tree

6,322 files changed

+43042
-41495
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

6,322 files changed

+43042
-41495
lines changed

app/code/Magento/AdminAnalytics/Test/Unit/Condition/CanViewNotificationTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ protected function setUp(): void
4242
->getMock();
4343
$this->productMetadataMock = $this->getMockBuilder(ProductMetadataInterface::class)
4444
->disableOriginalConstructor()
45-
->getMock();
45+
->getMockForAbstractClass();
4646
$objectManager = new ObjectManager($this);
4747
$this->canViewNotification = $objectManager->getObject(
4848
CanViewNotification::class,

app/code/Magento/AdminNotification/Test/Unit/Block/Grid/Renderer/ActionsTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class ActionsTest extends TestCase
2929
*/
3030
private $sut;
3131

32-
protected function setUp() : void
32+
protected function setUp(): void
3333
{
3434
parent::setUp();
3535

app/code/Magento/AdminNotification/Test/Unit/Block/Grid/Renderer/NoticeTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class NoticeTest extends TestCase
2727
*/
2828
private $sut;
2929

30-
protected function setUp() : void
30+
protected function setUp(): void
3131
{
3232
parent::setUp();
3333

app/code/Magento/AdminNotification/Test/Unit/Block/Grid/Renderer/SeverityTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class SeverityTest extends TestCase
2929
*/
3030
private $sut;
3131

32-
protected function setUp() : void
32+
protected function setUp(): void
3333
{
3434
parent::setUp();
3535

app/code/Magento/AdminNotification/Test/Unit/Block/ToolbarEntryTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ protected function _getBlockInstance($unreadNotifications)
3030
Unread::class,
3131
['getSize', 'setCurPage', 'setPageSize']
3232
);
33-
$notificationList->expects($this->any())->method('getSize')->will($this->returnValue($unreadNotifications));
33+
$notificationList->expects($this->any())->method('getSize')->willReturn($unreadNotifications);
3434

3535
$block = $objectManagerHelper->getObject(
3636
ToolbarEntry::class,
@@ -66,7 +66,7 @@ public function testGetLatestUnreadNotifications()
6666
$notificationList->expects($this->atLeastOnce())
6767
->method('setPageSize')
6868
->with(ToolbarEntry::NOTIFICATIONS_NUMBER)
69-
->will($this->returnSelf());
69+
->willReturnSelf();
7070

7171
// 3. Run tested method
7272
$result = $model->getLatestUnreadNotifications();

app/code/Magento/AdminNotification/Test/Unit/Model/FeedTest.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ protected function setUp(): void
104104
$this->productMetadata = $this->getMockBuilder(ProductMetadata::class)
105105
->disableOriginalConstructor()->getMock();
106106

107-
$this->urlBuilder = $this->createMock(UrlInterface::class);
107+
$this->urlBuilder = $this->getMockForAbstractClass(UrlInterface::class);
108108

109109
$this->feed = $this->objectManagerHelper->getObject(
110110
Feed::class,
@@ -146,19 +146,19 @@ public function testCheckUpdate($callInbox, $curlRequest)
146146

147147
$lastUpdate = 0;
148148
$this->cacheManager->expects($this->once())->method('load')->will(($this->returnValue($lastUpdate)));
149-
$this->curlFactory->expects($this->at(0))->method('create')->will($this->returnValue($this->curl));
149+
$this->curlFactory->expects($this->at(0))->method('create')->willReturn($this->curl);
150150
$this->curl->expects($this->once())->method('setConfig')->with($configValues)->willReturnSelf();
151-
$this->curl->expects($this->once())->method('read')->will($this->returnValue($curlRequest));
152-
$this->backendConfig->expects($this->at(0))->method('getValue')->will($this->returnValue('1'));
153-
$this->backendConfig->expects($this->once())->method('isSetFlag')->will($this->returnValue(false));
151+
$this->curl->expects($this->once())->method('read')->willReturn($curlRequest);
152+
$this->backendConfig->expects($this->at(0))->method('getValue')->willReturn('1');
153+
$this->backendConfig->expects($this->once())->method('isSetFlag')->willReturn(false);
154154
$this->backendConfig->expects($this->at(1))->method('getValue')
155-
->will($this->returnValue('http://feed.magento.com'));
155+
->willReturn('http://feed.magento.com');
156156
$this->deploymentConfig->expects($this->once())->method('get')
157157
->with(ConfigOptionsListConstants::CONFIG_PATH_INSTALL_DATE)
158-
->will($this->returnValue('Sat, 6 Sep 2014 16:46:11 UTC'));
158+
->willReturn('Sat, 6 Sep 2014 16:46:11 UTC');
159159
if ($callInbox) {
160160
$this->inboxFactory->expects($this->once())->method('create')
161-
->will($this->returnValue($this->inboxModel));
161+
->willReturn($this->inboxModel);
162162
$this->inboxModel->expects($this->once())
163163
->method('parse')
164164
->with(
@@ -178,7 +178,7 @@ function ($initialValue, $item) use ($data) {
178178
}
179179
)
180180
)
181-
->will($this->returnSelf());
181+
->willReturnSelf();
182182
} else {
183183
$this->inboxFactory->expects($this->never())->method('create');
184184
$this->inboxModel->expects($this->never())->method('parse');

app/code/Magento/AdminNotification/Test/Unit/Model/NotificationServiceTest.php

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,19 +35,18 @@ protected function _getServiceInstanceForMarkAsReadTest($notificationId)
3535
);
3636
$notification = $this->createPartialMock(
3737
Inbox::class,
38-
['load', 'getId', 'save', 'setData', '__sleep', '__wakeup']
38+
['load', 'getId', 'save', 'setData', '__sleep', '__wakeup', 'setIsRead']
3939
);
40-
$notification->expects($this->once())->method('load')->with($notificationId)->will($this->returnSelf());
41-
$notification->expects($this->once())->method('getId')->will($this->returnValue($notificationId));
40+
$notification->expects($this->once())->method('load')->with($notificationId)->willReturnSelf();
41+
$notification->expects($this->once())->method('getId')->willReturn($notificationId);
4242

4343
// when notification Id is valid, add additional expectations
4444
if ($notificationId) {
45-
$notification->expects($this->once())->method('save')->will($this->returnSelf());
46-
$notification->expects($this->once())->method('setData')
47-
->with('is_read', 1)->will($this->returnSelf());
45+
$notification->expects($this->once())->method('save')->willReturnSelf();
46+
$notification->expects($this->once())->method('setIsRead')->with(1)->willReturnSelf();
4847
}
4948

50-
$notificationFactory->expects($this->once())->method('create')->will($this->returnValue($notification));
49+
$notificationFactory->expects($this->once())->method('create')->willReturn($notification);
5150
return new NotificationService($notificationFactory);
5251
}
5352

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

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ class CacheOutdatedTest extends TestCase
3737

3838
protected function setUp(): void
3939
{
40-
$this->_authorizationMock = $this->createMock(AuthorizationInterface::class);
41-
$this->_urlInterfaceMock = $this->createMock(UrlInterface::class);
42-
$this->_cacheTypeListMock = $this->createMock(TypeListInterface::class);
40+
$this->_authorizationMock = $this->getMockForAbstractClass(AuthorizationInterface::class);
41+
$this->_urlInterfaceMock = $this->getMockForAbstractClass(UrlInterface::class);
42+
$this->_cacheTypeListMock = $this->getMockForAbstractClass(TypeListInterface::class);
4343

4444
$objectManagerHelper = new ObjectManager($this);
4545
$arguments = [
@@ -64,8 +64,8 @@ public function testGetIdentity($expectedSum, $cacheTypes)
6464
$this->any()
6565
)->method(
6666
'getInvalidated'
67-
)->will(
68-
$this->returnValue($cacheTypes)
67+
)->willReturn(
68+
$cacheTypes
6969
);
7070
$this->assertEquals($expectedSum, $this->_messageModel->getIdentity());
7171
}
@@ -76,10 +76,10 @@ public function testGetIdentity($expectedSum, $cacheTypes)
7676
public function getIdentityDataProvider()
7777
{
7878
$cacheTypeMock1 = $this->createPartialMock(\stdClass::class, ['getCacheType']);
79-
$cacheTypeMock1->expects($this->any())->method('getCacheType')->will($this->returnValue('Simple'));
79+
$cacheTypeMock1->expects($this->any())->method('getCacheType')->willReturn('Simple');
8080

8181
$cacheTypeMock2 = $this->createPartialMock(\stdClass::class, ['getCacheType']);
82-
$cacheTypeMock2->expects($this->any())->method('getCacheType')->will($this->returnValue('Advanced'));
82+
$cacheTypeMock2->expects($this->any())->method('getCacheType')->willReturn('Advanced');
8383

8484
return [
8585
['c13cfaddc2c53e8d32f59bfe89719beb', [$cacheTypeMock1]],
@@ -95,13 +95,13 @@ public function getIdentityDataProvider()
9595
*/
9696
public function testIsDisplayed($expected, $allowed, $cacheTypes)
9797
{
98-
$this->_authorizationMock->expects($this->once())->method('isAllowed')->will($this->returnValue($allowed));
98+
$this->_authorizationMock->expects($this->once())->method('isAllowed')->willReturn($allowed);
9999
$this->_cacheTypeListMock->expects(
100100
$this->any()
101101
)->method(
102102
'getInvalidated'
103-
)->will(
104-
$this->returnValue($cacheTypes)
103+
)->willReturn(
104+
$cacheTypes
105105
);
106106
$this->assertEquals($expected, $this->_messageModel->isDisplayed());
107107
}
@@ -112,7 +112,7 @@ public function testIsDisplayed($expected, $allowed, $cacheTypes)
112112
public function isDisplayedDataProvider()
113113
{
114114
$cacheTypesMock = $this->createPartialMock(\stdClass::class, ['getCacheType']);
115-
$cacheTypesMock->expects($this->any())->method('getCacheType')->will($this->returnValue('someVal'));
115+
$cacheTypesMock->expects($this->any())->method('getCacheType')->willReturn('someVal');
116116
$cacheTypes = [$cacheTypesMock, $cacheTypesMock];
117117
return [
118118
[false, false, []],
@@ -126,15 +126,15 @@ public function testGetText()
126126
{
127127
$messageText = 'One or more of the Cache Types are invalidated';
128128

129-
$this->_cacheTypeListMock->expects($this->any())->method('getInvalidated')->will($this->returnValue([]));
130-
$this->_urlInterfaceMock->expects($this->once())->method('getUrl')->will($this->returnValue('someURL'));
131-
$this->assertContains($messageText, $this->_messageModel->getText());
129+
$this->_cacheTypeListMock->expects($this->any())->method('getInvalidated')->willReturn([]);
130+
$this->_urlInterfaceMock->expects($this->once())->method('getUrl')->willReturn('someURL');
131+
$this->assertStringContainsString($messageText, $this->_messageModel->getText());
132132
}
133133

134134
public function testGetLink()
135135
{
136136
$url = 'backend/admin/cache';
137-
$this->_urlInterfaceMock->expects($this->once())->method('getUrl')->will($this->returnValue($url));
137+
$this->_urlInterfaceMock->expects($this->once())->method('getUrl')->willReturn($url);
138138
$this->assertEquals($url, $this->_messageModel->getLink());
139139
}
140140
}

app/code/Magento/AdminNotification/Test/Unit/Model/System/Message/Media/Synchronization/ErrorTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ protected function setUp(): void
3737
);
3838

3939
$this->_fileStorage = $this->createMock(Flag::class);
40-
$this->_fileStorage->expects($this->any())->method('loadSelf')->will($this->returnValue($this->_syncFlagMock));
40+
$this->_fileStorage->expects($this->any())->method('loadSelf')->willReturn($this->_syncFlagMock);
4141

4242
$objectManagerHelper = new ObjectManager($this);
4343
$arguments = ['fileStorage' => $this->_fileStorage];
@@ -50,7 +50,7 @@ protected function setUp(): void
5050
public function testGetText()
5151
{
5252
$messageText = 'We were unable to synchronize one or more media files.';
53-
$this->assertContains($messageText, (string)$this->_model->getText());
53+
$this->assertStringContainsString($messageText, (string)$this->_model->getText());
5454
}
5555

5656
/**
@@ -70,7 +70,7 @@ public function testIsDisplayed($expectedFirstRun, $data)
7070
);
7171

7272
$this->_syncFlagMock->expects($this->any())->method('save');
73-
$this->_syncFlagMock->expects($this->any())->method('getFlagData')->will($this->returnValue($data));
73+
$this->_syncFlagMock->expects($this->any())->method('getFlagData')->willReturn($data);
7474
//check first call
7575
$this->assertEquals($expectedFirstRun, $model->isDisplayed());
7676
//check second call(another branch of if operator)

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ class SecurityTest extends TestCase
3939
protected function setUp(): void
4040
{
4141
//Prepare objects for constructor
42-
$this->cacheMock = $this->createMock(CacheInterface::class);
43-
$this->scopeConfigMock = $this->createMock(ScopeConfigInterface::class);
42+
$this->cacheMock = $this->getMockForAbstractClass(CacheInterface::class);
43+
$this->scopeConfigMock = $this->getMockForAbstractClass(ScopeConfigInterface::class);
4444
$this->curlFactoryMock = $this->createPartialMock(
4545
CurlFactory::class,
4646
['create']
@@ -68,14 +68,14 @@ protected function setUp(): void
6868
*/
6969
public function testIsDisplayed($expectedResult, $cached, $response)
7070
{
71-
$this->cacheMock->expects($this->any())->method('load')->will($this->returnValue($cached));
72-
$this->cacheMock->expects($this->any())->method('save')->will($this->returnValue(null));
71+
$this->cacheMock->expects($this->any())->method('load')->willReturn($cached);
72+
$this->cacheMock->expects($this->any())->method('save')->willReturn(null);
7373

7474
$httpAdapterMock = $this->createMock(Curl::class);
75-
$httpAdapterMock->expects($this->any())->method('read')->will($this->returnValue($response));
76-
$this->curlFactoryMock->expects($this->any())->method('create')->will($this->returnValue($httpAdapterMock));
75+
$httpAdapterMock->expects($this->any())->method('read')->willReturn($response);
76+
$this->curlFactoryMock->expects($this->any())->method('create')->willReturn($httpAdapterMock);
7777

78-
$this->scopeConfigMock->expects($this->any())->method('getValue')->will($this->returnValue(null));
78+
$this->scopeConfigMock->expects($this->any())->method('getValue')->willReturn(null);
7979

8080
$this->assertEquals($expectedResult, $this->messageModel->isDisplayed());
8181
}

0 commit comments

Comments
 (0)