Skip to content

Commit 5587ce8

Browse files
committed
Fixed code by recommendation.
1 parent 3d73ef1 commit 5587ce8

File tree

2 files changed

+16
-17
lines changed

2 files changed

+16
-17
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ private function validatedParams()
125125
throw new LocalizedException(__('The email address is invalid. Verify the email address and try again.'));
126126
}
127127
if (trim($request->getParam('hideit', '')) !== '') {
128+
// phpcs:ignore Magento2.Exceptions.DirectThrow
128129
throw new \Exception();
129130
}
130131

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
}

0 commit comments

Comments
 (0)