Skip to content

Commit 70a4b21

Browse files
committed
Fix phpunit tests with special characters pwd
1 parent 2b32695 commit 70a4b21

1 file changed

Lines changed: 19 additions & 14 deletions

File tree

tests/Unit/Generator/PasswordTest.php

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -39,26 +39,31 @@ public function testPasswordWithSpecialCharacters()
3939
$sPassword = Password::generate(Password::DEFAULT_LENGTH, true);
4040

4141
$this->assertSame(Password::DEFAULT_LENGTH, strlen($sPassword));
42-
$this->assertTrue(
43-
in_array(
44-
$sPassword,
45-
['-', '_', '~', '|', '%', '^', '!', '$', '#', '@', '?'],
46-
true
47-
)
48-
);
42+
$this->assertTrue($this->doesContainSpecialChars($sPassword));
4943
}
5044

5145
public function testPasswordWithoutSpecialCharacters()
5246
{
5347
$sPassword = Password::generate(Password::DEFAULT_LENGTH, false);
5448

5549
$this->assertSame(Password::DEFAULT_LENGTH, strlen($sPassword));
56-
$this->assertFalse(
57-
in_array(
58-
$sPassword,
59-
['-', '_', '~', '|', '%', '^', '!', '$', '#', '@', '?'],
60-
true
61-
)
62-
);
50+
$this->assertFalse($this->doesContainSpecialChars($sPassword));
51+
}
52+
53+
/**
54+
* @param string $sPassword
55+
*
56+
* @return bool
57+
*/
58+
private function doesContainSpecialChars($sPassword)
59+
{
60+
$aSpecialChars = ['-', '_', '~', '|', '%', '^', '!', '$', '#', '@', '?'];
61+
62+
foreach (str_split($sPassword) as $sCharacter) {
63+
if (in_array($sCharacter, $aSpecialChars, true)) {
64+
return true;
65+
}
66+
}
67+
return false;
6368
}
6469
}

0 commit comments

Comments
 (0)