Skip to content

Commit a8dbc2d

Browse files
committed
Merge remote-tracking branch 'anzin/fix-deprecation-unit-part-3' into ph-delivery
2 parents feb6494 + 5587ce8 commit a8dbc2d

File tree

5 files changed

+47
-25
lines changed

5 files changed

+47
-25
lines changed

app/code/Magento/Contact/Controller/Index/Post.php

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,10 @@ public function execute()
9191
}
9292

9393
/**
94+
* Method to send email.
95+
*
9496
* @param array $post Post data from contact form
97+
*
9598
* @return void
9699
*/
97100
private function sendEmail($post)
@@ -103,22 +106,26 @@ private function sendEmail($post)
103106
}
104107

105108
/**
109+
* Method to validated params.
110+
*
106111
* @return array
107112
* @throws \Exception
108113
*/
109114
private function validatedParams()
110115
{
111116
$request = $this->getRequest();
112-
if (trim($request->getParam('name')) === '') {
117+
118+
if (trim($request->getParam('name', '')) === '') {
113119
throw new LocalizedException(__('Enter the Name and try again.'));
114120
}
115-
if (trim($request->getParam('comment')) === '') {
121+
if (trim($request->getParam('comment', '')) === '') {
116122
throw new LocalizedException(__('Enter the comment and try again.'));
117123
}
118-
if (false === \strpos($request->getParam('email'), '@')) {
124+
if (\strpos($request->getParam('email', ''), '@') === false) {
119125
throw new LocalizedException(__('The email address is invalid. Verify the email address and try again.'));
120126
}
121-
if (trim($request->getParam('hideit')) !== '') {
127+
if (trim($request->getParam('hideit', '')) !== '') {
128+
// phpcs:ignore Magento2.Exceptions.DirectThrow
122129
throw new \Exception();
123130
}
124131

app/code/Magento/Contact/Test/Unit/Controller/Index/PostTest.php

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -137,21 +137,19 @@ public function testExecuteEmptyPost(): void
137137

138138
/**
139139
* Test exceute post validation
140+
*
140141
* @param array $postData
141-
* @param bool $exceptionExpected
142142
* @dataProvider postDataProvider
143143
*/
144-
public function testExecutePostValidation($postData, $exceptionExpected): void
144+
public function testExecutePostValidation($postData): void
145145
{
146146
$this->stubRequestPostData($postData);
147+
$this->messageManagerMock->expects($this->once())
148+
->method('addErrorMessage');
149+
$this->dataPersistorMock->expects($this->once())
150+
->method('set')
151+
->with('contact_us', $postData);
147152

148-
if ($exceptionExpected) {
149-
$this->messageManagerMock->expects($this->once())
150-
->method('addErrorMessage');
151-
$this->dataPersistorMock->expects($this->once())
152-
->method('set')
153-
->with('contact_us', $postData);
154-
}
155153

156154
$this->controller->execute();
157155
}
@@ -162,12 +160,12 @@ public function testExecutePostValidation($postData, $exceptionExpected): void
162160
public function postDataProvider(): array
163161
{
164162
return [
165-
[['name' => null, 'comment' => null, 'email' => '', 'hideit' => 'no'], true],
166-
[['name' => 'test', 'comment' => '', 'email' => '', 'hideit' => 'no'], true],
167-
[['name' => '', 'comment' => 'test', 'email' => '', 'hideit' => 'no'], true],
168-
[['name' => '', 'comment' => '', 'email' => 'test', 'hideit' => 'no'], true],
169-
[['name' => '', 'comment' => '', 'email' => '', 'hideit' => 'no'], true],
170-
[['name' => 'Name', 'comment' => 'Name', 'email' => 'invalidmail', 'hideit' => 'no'], true],
163+
[['name' => null, 'comment' => null, 'email' => '', 'hideit' => 'no']],
164+
[['name' => 'test', 'comment' => '', 'email' => '', 'hideit' => 'no']],
165+
[['name' => '', 'comment' => 'test', 'email' => '', 'hideit' => 'no']],
166+
[['name' => '', 'comment' => '', 'email' => 'test', 'hideit' => 'no']],
167+
[['name' => '', 'comment' => '', 'email' => '', 'hideit' => 'no']],
168+
[['name' => 'Name', 'comment' => 'Name', 'email' => 'invalidmail', 'hideit' => 'no']],
171169
];
172170
}
173171

@@ -206,8 +204,8 @@ private function stubRequestPostData($post): void
206204
$this->requestStub->method('getPostValue')->willReturn($post);
207205
$this->requestStub->method('getParams')->willReturn($post);
208206
$this->requestStub->method('getParam')->willReturnCallback(
209-
function ($key) use ($post) {
210-
return $post[$key];
207+
function ($key, $defaultValue) use ($post) {
208+
return $post[$key] ?? $defaultValue;
211209
}
212210
);
213211
}

app/code/Magento/MediaStorage/Test/Unit/App/MediaTest.php

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,9 @@ public function testProcessRequestCreatesConfigFileMediaDirectoryIsNotProvided()
134134
$this->responseMock->expects(self::once())
135135
->method('setFilePath')
136136
->with($filePath);
137+
$this->configMock->expects($this->once())
138+
->method('getMediaDirectory')
139+
->willReturn('');
137140

138141
$this->createMediaModel()->launch();
139142
}
@@ -161,6 +164,9 @@ public function testProcessRequestReturnsFileIfItsProperlySynchronized(): void
161164
$this->responseMock->expects(self::once())
162165
->method('setFilePath')
163166
->with($filePath);
167+
$this->configMock->expects($this->once())
168+
->method('getMediaDirectory')
169+
->willReturn('');
164170

165171
self::assertSame($this->responseMock, $this->mediaModel->launch());
166172
}
@@ -180,6 +186,10 @@ public function testProcessRequestReturnsNotFoundIfFileIsNotSynchronized(): void
180186
->method('isReadable')
181187
->with(self::RELATIVE_FILE_PATH)
182188
->willReturn(false);
189+
$this->configMock->expects($this->once())
190+
->method('getMediaDirectory')
191+
->willReturn('');
192+
$this->directoryPubMock->method('getAbsolutePath')->willReturn('');
183193

184194
self::assertSame($this->responseMock, $this->mediaModel->launch());
185195
}
@@ -225,6 +235,9 @@ public function testExceptionWhenIsAllowedReturnsFalse(): void
225235
->willReturn($filePath);
226236
$this->configMock->expects(self::once())
227237
->method('save');
238+
$this->configMock->expects($this->once())
239+
->method('getMediaDirectory')
240+
->willReturn('');
228241

229242
$this->expectException(LogicException::class);
230243
$this->expectExceptionMessage('The path is not allowed: ' . self::RELATIVE_FILE_PATH);
@@ -255,6 +268,8 @@ protected function createMediaModel(bool $isAllowed = true): Media
255268
return $isAllowed;
256269
};
257270

271+
$driverFile = $this->createMock(Filesystem\Driver\File::class);
272+
$driverFile->method('getRealPath')->willReturn('');
258273
$placeholderFactory = $this->createMock(PlaceholderFactory::class);
259274
$placeholderFactory->method('create')
260275
->willReturn($this->createMock(Placeholder::class));
@@ -271,7 +286,7 @@ protected function createMediaModel(bool $isAllowed = true): Media
271286
$placeholderFactory,
272287
$this->createMock(State::class),
273288
$this->createMock(ImageResize::class),
274-
$this->createMock(Filesystem\Driver\File::class),
289+
$driverFile,
275290
$this->createMock(CatalogMediaConfig::class)
276291
);
277292
}

app/code/Magento/Reports/Test/Unit/Block/Adminhtml/Grid/Column/Renderer/CurrencyTest.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ protected function setUp(): void
154154
);
155155

156156
$this->gridColumnMock = $this->getMockBuilder(Column::class)
157-
->addMethods(['getIndex'])
157+
->addMethods(['getIndex', 'getRateField', 'getCurrency'])
158158
->disableOriginalConstructor()
159159
->getMock();
160160
$this->model = $objectManager->getObject(
@@ -250,6 +250,8 @@ public function testRender(
250250
->method('getCurrency')
251251
->with($storeCurrencyCode)
252252
->willReturn($currLocaleMock);
253+
$this->gridColumnMock->method('getCurrency')->willReturn('USD');
254+
$this->gridColumnMock->method('getRateField')->willReturn('test_rate_field');
253255
$actualAmount = $this->model->render($this->row);
254256
$this->assertEquals($convertedAmount, $actualAmount);
255257
}

lib/internal/Magento/Framework/DB/Test/Unit/Adapter/Pdo/MysqlTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
*/
2929
class MysqlTest extends TestCase
3030
{
31-
const CUSTOM_ERROR_HANDLER_MESSAGE = 'Custom error handler message';
31+
public const CUSTOM_ERROR_HANDLER_MESSAGE = 'Custom error handler message';
3232

3333
/**
3434
* @var SelectFactory|MockObject
@@ -426,7 +426,7 @@ public function testAddColumn($options, $expectedQuery)
426426
);
427427
$adapter->expects($this->any())->method('getSchemaListener')->willReturn($this->schemaListenerMock);
428428
$adapter->expects($this->any())->method('_getTableName')->willReturnArgument(0);
429-
$adapter->expects($this->any())->method('quote')->willReturnArgument(0);
429+
$adapter->expects($this->any())->method('quote')->willReturnOnConsecutiveCalls('', 'Some field');
430430
$adapter->expects($this->once())->method('rawQuery')->with($expectedQuery);
431431
$adapter->addColumn('tableName', 'columnName', $options);
432432
}

0 commit comments

Comments
 (0)