Skip to content

Commit 9df8b98

Browse files
Merge branch 'improvement/ce-33707-update-unit-tests-codebase-to-phpunit-9-3-0' of github.com:anzin/magento2 into update-phpunit-to-9-3
2 parents 7c91ae3 + 6002121 commit 9df8b98

File tree

183 files changed

+8045
-6501
lines changed

Some content is hidden

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

183 files changed

+8045
-6501
lines changed

app/code/Magento/Cms/Test/Unit/Controller/Adminhtml/Wysiwyg/DirectiveTest.php

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
namespace Magento\Cms\Test\Unit\Controller\Adminhtml\Wysiwyg;
99

10+
use Exception;
1011
use Magento\Backend\App\Action\Context;
1112
use Magento\Cms\Controller\Adminhtml\Wysiwyg\Directive;
1213
use Magento\Cms\Model\Template\Filter;
@@ -17,7 +18,6 @@
1718
use Magento\Framework\Controller\Result\RawFactory;
1819
use Magento\Framework\Filesystem;
1920
use Magento\Framework\Filesystem\Directory\WriteInterface;
20-
use Magento\Framework\Filesystem\Driver\File;
2121
use Magento\Framework\Filesystem\DriverInterface;
2222
use Magento\Framework\Image\Adapter\AdapterInterface;
2323
use Magento\Framework\Image\AdapterFactory;
@@ -106,6 +106,9 @@ class DirectiveTest extends TestCase
106106
*/
107107
private $driverMock;
108108

109+
/**
110+
* @inheritdoc
111+
*/
109112
protected function setUp(): void
110113
{
111114
$this->actionContextMock = $this->getMockBuilder(Context::class)
@@ -128,9 +131,8 @@ protected function setUp(): void
128131
->getMock();
129132
$this->imageAdapterMock = $this->getMockBuilder(AdapterInterface::class)
130133
->disableOriginalConstructor()
131-
->setMethods(
134+
->onlyMethods(
132135
[
133-
'getMimeType',
134136
'getColorAt',
135137
'getImage',
136138
'watermark',
@@ -144,10 +146,12 @@ protected function setUp(): void
144146
'rotate'
145147
]
146148
)
149+
->addMethods(['getMimeType'])
147150
->getMockForAbstractClass();
148151
$this->responseMock = $this->getMockBuilder(ResponseInterface::class)
149152
->disableOriginalConstructor()
150-
->setMethods(['setHeader', 'setBody', 'sendResponse'])
153+
->onlyMethods(['sendResponse'])
154+
->addMethods(['setHeader', 'setBody'])
151155
->getMockForAbstractClass();
152156
$this->wysiwygConfigMock = $this->getMockBuilder(Config::class)
153157
->disableOriginalConstructor()
@@ -156,7 +160,7 @@ protected function setUp(): void
156160
->disableOriginalConstructor()
157161
->getMockForAbstractClass();
158162
$this->rawFactoryMock = $this->getMockBuilder(RawFactory::class)
159-
->setMethods(['create'])
163+
->onlyMethods(['create'])
160164
->disableOriginalConstructor()
161165
->getMock();
162166
$this->rawMock = $this->getMockBuilder(Raw::class)
@@ -201,9 +205,10 @@ protected function setUp(): void
201205
}
202206

203207
/**
208+
* @return void
204209
* @covers \Magento\Cms\Controller\Adminhtml\Wysiwyg\Directive::execute
205210
*/
206-
public function testExecute()
211+
public function testExecute(): void
207212
{
208213
$mimeType = 'image/jpeg';
209214
$imageBody = 'abcdefghijklmnopqrstuvwxyz0123456789';
@@ -243,26 +248,24 @@ public function testExecute()
243248
}
244249

245250
/**
251+
* @return void
246252
* @covers \Magento\Cms\Controller\Adminhtml\Wysiwyg\Directive::execute
247253
*/
248-
public function testExecuteException()
254+
public function testExecuteException(): void
249255
{
250-
$exception = new \Exception('epic fail');
256+
$exception = new Exception('epic fail');
251257
$placeholderPath = 'pub/static/adminhtml/Magento/backend/en_US/Magento_Cms/images/wysiwyg_skin_image.png';
252258
$mimeType = 'image/png';
253259
$imageBody = '0123456789abcdefghijklmnopqrstuvwxyz';
254260
$this->prepareExecuteTest();
255261

256-
$this->imageAdapterMock->expects($this->at(0))
257-
->method('open')
258-
->with(self::IMAGE_PATH)
259-
->willThrowException($exception);
260262
$this->wysiwygConfigMock->expects($this->once())
261263
->method('getSkinImagePlaceholderPath')
262264
->willReturn($placeholderPath);
263-
$this->imageAdapterMock->expects($this->at(1))
265+
$this->imageAdapterMock
264266
->method('open')
265-
->with($placeholderPath);
267+
->withConsecutive([self::IMAGE_PATH])
268+
->willThrowException($exception);
266269
$this->imageAdapterMock->expects($this->atLeastOnce())
267270
->method('getMimeType')
268271
->willReturn($mimeType);
@@ -297,7 +300,10 @@ public function testExecuteException()
297300
);
298301
}
299302

300-
protected function prepareExecuteTest()
303+
/**
304+
* @return void
305+
*/
306+
protected function prepareExecuteTest(): void
301307
{
302308
$directiveParam = 'e3ttZWRpYSB1cmw9Ind5c2l3eWcvYnVubnkuanBnIn19';
303309
$directive = '{{media url="wysiwyg/image.jpg"}}';
@@ -324,11 +330,12 @@ protected function prepareExecuteTest()
324330
/**
325331
* Test Execute With Deleted Image
326332
*
333+
* @return void
327334
* @covers \Magento\Cms\Controller\Adminhtml\Wysiwyg\Directive::execute
328335
*/
329-
public function testExecuteWithDeletedImage()
336+
public function testExecuteWithDeletedImage(): void
330337
{
331-
$exception = new \Exception('epic fail');
338+
$exception = new Exception('epic fail');
332339
$placeholderPath = 'pub/static/adminhtml/Magento/backend/en_US/Magento_Cms/images/wysiwyg_skin_image.png';
333340
$this->prepareExecuteTest();
334341

app/code/Magento/Cms/Test/Unit/Controller/Block/InlineEditTest.php

Lines changed: 54 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -20,27 +20,44 @@
2020

2121
class InlineEditTest extends TestCase
2222
{
23-
/** @var RequestInterface|MockObject */
23+
/**
24+
* @var RequestInterface|MockObject
25+
*/
2426
protected $request;
2527

26-
/** @var Block|MockObject */
28+
/**
29+
* @var Block|MockObject
30+
*/
2731
protected $cmsBlock;
2832

29-
/** @var Context|MockObject */
33+
/**
34+
* @var Context|MockObject
35+
*/
3036
protected $context;
3137

32-
/** @var BlockRepositoryInterface|MockObject */
38+
/**
39+
* @var BlockRepositoryInterface|MockObject
40+
*/
3341
protected $blockRepository;
3442

35-
/** @var JsonFactory|MockObject */
43+
/**
44+
* @var JsonFactory|MockObject
45+
*/
3646
protected $jsonFactory;
3747

38-
/** @var Json|MockObject */
48+
/**
49+
* @var Json|MockObject
50+
*/
3951
protected $resultJson;
4052

41-
/** @var InlineEdit */
53+
/**
54+
* @var InlineEdit
55+
*/
4256
protected $controller;
4357

58+
/**
59+
* @inheritdoc
60+
*/
4461
protected function setUp(): void
4562
{
4663
$helper = new ObjectManager($this);
@@ -76,7 +93,10 @@ protected function setUp(): void
7693
);
7794
}
7895

79-
public function prepareMocksForTestExecute()
96+
/**
97+
* @return void
98+
*/
99+
public function prepareMocksForTestExecute(): void
80100
{
81101
$postData = [
82102
1 => [
@@ -85,14 +105,10 @@ public function prepareMocksForTestExecute()
85105
]
86106
];
87107

88-
$this->request->expects($this->at(0))
108+
$this->request
89109
->method('getParam')
90-
->with('isAjax')
91-
->willReturn(true);
92-
$this->request->expects($this->at(1))
93-
->method('getParam')
94-
->with('items', [])
95-
->willReturn($postData);
110+
->withConsecutive(['isAjax'], ['items', []])
111+
->willReturnOnConsecutiveCalls(true, $postData);
96112
$this->blockRepository->expects($this->once())
97113
->method('getById')
98114
->with(1)
@@ -116,7 +132,10 @@ public function prepareMocksForTestExecute()
116132
->willReturn($this->resultJson);
117133
}
118134

119-
public function testExecuteWithException()
135+
/**
136+
* @return void
137+
*/
138+
public function testExecuteWithException(): void
120139
{
121140
$this->prepareMocksForTestExecute();
122141
$this->blockRepository->expects($this->once())
@@ -125,38 +144,37 @@ public function testExecuteWithException()
125144
->willThrowException(new \Exception('Exception'));
126145
$this->resultJson->expects($this->once())
127146
->method('setData')
128-
->with([
129-
'messages' => [
130-
'[Block ID: 1] Exception'
131-
],
132-
'error' => true
133-
])
147+
->with(
148+
[
149+
'messages' => ['[Block ID: 1] Exception'],
150+
'error' => true
151+
]
152+
)
134153
->willReturnSelf();
135154

136155
$this->controller->execute();
137156
}
138157

139-
public function testExecuteWithoutData()
158+
/**
159+
* @return void
160+
*/
161+
public function testExecuteWithoutData(): void
140162
{
141-
$this->request->expects($this->at(0))
163+
$this->request
142164
->method('getParam')
143-
->with('isAjax')
144-
->willReturn(true);
145-
$this->request->expects($this->at(1))
146-
->method('getParam')
147-
->with('items', [])
148-
->willReturn([]);
165+
->withConsecutive(['isAjax'], ['items', []])
166+
->willReturnOnConsecutiveCalls(true, []);
149167
$this->jsonFactory->expects($this->once())
150168
->method('create')
151169
->willReturn($this->resultJson);
152170
$this->resultJson->expects($this->once())
153171
->method('setData')
154-
->with([
155-
'messages' => [
156-
'Please correct the data sent.'
157-
],
158-
'error' => true
159-
])
172+
->with(
173+
[
174+
'messages' => ['Please correct the data sent.'],
175+
'error' => true
176+
]
177+
)
160178
->willReturnSelf();
161179

162180
$this->controller->execute();

app/code/Magento/Cms/Test/Unit/Controller/Noroute/IndexTest.php

Lines changed: 32 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88
namespace Magento\Cms\Test\Unit\Controller\Noroute;
99

1010
use Magento\Cms\Controller\Noroute\Index;
11+
use Magento\Cms\Helper\Page as CmsPage;
1112
use Magento\Framework\App\Config\ScopeConfigInterface;
13+
use Magento\Framework\App\Request\Http as RequestHttp;
1214
use Magento\Framework\App\Response\Http;
1315
use Magento\Framework\Controller\Result\Forward;
1416
use Magento\Framework\Controller\Result\ForwardFactory;
@@ -54,6 +56,9 @@ class IndexTest extends TestCase
5456
*/
5557
protected $resultPageMock;
5658

59+
/**
60+
* @inheritdoc
61+
*/
5762
protected function setUp(): void
5863
{
5964
$helper = new ObjectManager($this);
@@ -63,7 +68,7 @@ protected function setUp(): void
6368
->disableOriginalConstructor()
6469
->getMock();
6570
$this->forwardFactoryMock = $this->getMockBuilder(ForwardFactory::class)
66-
->setMethods(['create'])
71+
->onlyMethods(['create'])
6772
->disableOriginalConstructor()
6873
->getMock();
6974
$this->forwardMock = $this->getMockBuilder(Forward::class)
@@ -74,48 +79,50 @@ protected function setUp(): void
7479
->willReturn($this->forwardMock);
7580

7681
$scopeConfigMock = $this->getMockForAbstractClass(ScopeConfigInterface::class);
77-
$this->_requestMock = $this->createMock(\Magento\Framework\App\Request\Http::class);
78-
$this->_cmsHelperMock = $this->createMock(\Magento\Cms\Helper\Page::class);
82+
$this->_requestMock = $this->createMock(RequestHttp::class);
83+
$this->_cmsHelperMock = $this->createMock(CmsPage::class);
7984
$valueMap = [
80-
[ScopeConfigInterface::class,
85+
[
86+
ScopeConfigInterface::class,
8187
ScopeInterface::SCOPE_STORE,
8288
$scopeConfigMock,
8389
],
84-
[\Magento\Cms\Helper\Page::class, $this->_cmsHelperMock],
90+
[CmsPage::class, $this->_cmsHelperMock]
8591
];
8692
$objectManagerMock->expects($this->any())->method('get')->willReturnMap($valueMap);
8793
$scopeConfigMock->expects(
8894
$this->once()
8995
)->method(
9096
'getValue'
9197
)->with(
92-
\Magento\Cms\Helper\Page::XML_PATH_NO_ROUTE_PAGE
98+
CmsPage::XML_PATH_NO_ROUTE_PAGE
9399
)->willReturn(
94100
'pageId'
95101
);
96102
$this->_controller = $helper->getObject(
97103
Index::class,
98-
['response' => $responseMock, 'objectManager' => $objectManagerMock, 'request' => $this->_requestMock,
104+
[
105+
'response' => $responseMock,
106+
'objectManager' => $objectManagerMock,
107+
'request' => $this->_requestMock,
99108
'resultForwardFactory' => $this->forwardFactoryMock
100109
]
101110
);
102111
}
103112

104-
public function testExecuteResultPage()
113+
/**
114+
* @return void
115+
*/
116+
public function testExecuteResultPage(): void
105117
{
106-
$this->resultPageMock->expects(
107-
$this->at(0)
108-
)->method(
109-
'setStatusHeader'
110-
)->with(404, '1.1', 'Not Found')->willReturnSelf();
111-
$this->resultPageMock->expects(
112-
$this->at(1)
113-
)->method(
114-
'setHeader'
115-
)->with(
116-
'Status',
117-
'404 File not found'
118-
)->willReturnSelf();
118+
$this->resultPageMock
119+
->method('setStatusHeader')
120+
->with(404, '1.1', 'Not Found')
121+
->willReturn($this->resultPageMock);
122+
$this->resultPageMock
123+
->method('setHeader')
124+
->with('Status', '404 File not found')
125+
->willReturn($this->resultPageMock);
119126
$this->_cmsHelperMock->expects(
120127
$this->once()
121128
)->method(
@@ -129,7 +136,10 @@ public function testExecuteResultPage()
129136
);
130137
}
131138

132-
public function testExecuteResultForward()
139+
/**
140+
* @return void
141+
*/
142+
public function testExecuteResultForward(): void
133143
{
134144
$this->forwardMock->expects(
135145
$this->once()

0 commit comments

Comments
 (0)