Skip to content

Commit 9ea686d

Browse files
committed
Fixed static and unit test failures
1 parent 324da66 commit 9ea686d

File tree

2 files changed

+14
-11
lines changed

2 files changed

+14
-11
lines changed

setup/src/Magento/Setup/Model/AdminAccount.php

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@ class AdminAccount
1717
/**#@+
1818
* Data keys
1919
*/
20-
const KEY_USER = 'admin-user';
21-
const KEY_PASSWORD = 'admin-password';
22-
const KEY_EMAIL = 'admin-email';
23-
const KEY_FIRST_NAME = 'admin-firstname';
24-
const KEY_LAST_NAME = 'admin-lastname';
25-
const KEY_PREFIX = 'db-prefix';
20+
public const KEY_USER = 'admin-user';
21+
public const KEY_PASSWORD = 'admin-password';
22+
public const KEY_EMAIL = 'admin-email';
23+
public const KEY_FIRST_NAME = 'admin-firstname';
24+
public const KEY_LAST_NAME = 'admin-lastname';
25+
public const KEY_PREFIX = 'db-prefix';
2626
/**#@- */
2727

2828
/**
@@ -154,8 +154,7 @@ private function trackPassword($adminId, $passwordHash)
154154
}
155155

156156
/**
157-
* Validates that the username and email both match the user,
158-
* and that password exists and is different from user name.
157+
* Validate that the username and email both match the user,and that password exists and is different from username.
159158
*
160159
* @return void
161160
* @throws \Exception If the username and email do not both match data provided to install
@@ -164,12 +163,14 @@ private function trackPassword($adminId, $passwordHash)
164163
public function validateUserMatches()
165164
{
166165
if (empty($this->data[self::KEY_PASSWORD])) {
166+
// phpcs:ignore Magento2.Exceptions.DirectThrow
167167
throw new \Exception(
168168
'"Password" is required. Enter and try again.'
169169
);
170170
}
171171

172172
if (strcasecmp($this->data[self::KEY_PASSWORD], $this->data[self::KEY_USER]) == 0) {
173+
// phpcs:ignore Magento2.Exceptions.DirectThrow
173174
throw new \Exception(
174175
'Password cannot be the same as the user name.'
175176
);
@@ -191,6 +192,7 @@ public function validateUserMatches()
191192
if ((strcasecmp($email, $this->data[self::KEY_EMAIL]) == 0) &&
192193
(strcasecmp($username, $this->data[self::KEY_USER]) != 0)) {
193194
// email matched but username did not
195+
// phpcs:ignore Magento2.Exceptions.DirectThrow
194196
throw new \Exception(
195197
'An existing user has the given email but different username. '
196198
. 'Username and email both need to match an existing user or both be new.'
@@ -199,6 +201,7 @@ public function validateUserMatches()
199201
if ((strcasecmp($username, $this->data[self::KEY_USER]) == 0) &&
200202
(strcasecmp($email, $this->data[self::KEY_EMAIL]) != 0)) {
201203
// username matched but email did not
204+
// phpcs:ignore Magento2.Exceptions.DirectThrow
202205
throw new \Exception(
203206
'An existing user has the given username but different email. '
204207
. 'Username and email both need to match an existing user or both be new.'
@@ -258,6 +261,7 @@ private function retrieveAdministratorsRoleId()
258261
$administratorsRoleData
259262
);
260263
if (empty($result)) {
264+
// phpcs:ignore Magento2.Exceptions.DirectThrow
261265
throw new \Exception('No administrators role was found, data fixture needs to be run');
262266
} else {
263267
// Found at least one, use first

setup/src/Magento/Setup/Test/Unit/Model/AdminAccountTest.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -180,14 +180,13 @@ public function testSaveUserExistsNewAdminRole(): void
180180
'SELECT * FROM ' . $this->prefix .
181181
'authorization_role WHERE parent_id = :parent_id AND tree_level = :tree_level ' .
182182
'AND role_type = :role_type AND user_id = :user_id ' .
183-
'AND user_type = :user_type AND role_name = :role_name',
183+
'AND user_type = :user_type ORDER BY sort_order DESC',
184184
[
185185
'parent_id' => 0,
186186
'tree_level' => 1,
187187
'role_type' => 'G',
188188
'user_id' => 0,
189189
'user_type' => 2,
190-
'role_name' => 'Administrators',
191190
],
192191
null,
193192
$administratorRoleData
@@ -375,7 +374,7 @@ public function testSaveExceptionEmailNotMatch(): void
375374
public function testSaveExceptionSpecialAdminRoleNotFound(): void
376375
{
377376
$this->expectException('Exception');
378-
$this->expectExceptionMessage('No Administrators role was found, data fixture needs to be run');
377+
$this->expectExceptionMessage('No administrators role was found, data fixture needs to be run');
379378
$this->dbAdapter->expects($this->exactly(3))->method('fetchRow')->willReturn([]);
380379
$this->dbAdapter->expects($this->once())->method('lastInsertId')->willReturn(1);
381380

0 commit comments

Comments
 (0)