Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
147 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,6 @@ | |
/** | ||
* DummyDto. | ||
*/ | ||
class DummyDto implements DtoInterface | ||
final class DummyDto implements DtoInterface | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
<?php | ||
/* | ||
* This file is part of the StfalconApiBundle. | ||
* | ||
* (c) Stfalcon LLC <stfalcon.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace StfalconStudio\ApiBundle\Tests\Util; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use StfalconStudio\ApiBundle\Util\PasswordRequirementsValidator; | ||
|
||
/** | ||
* PasswordRequirementsValidatorTest. | ||
*/ | ||
final class PasswordRequirementsValidatorTest extends TestCase | ||
{ | ||
/** @var PasswordRequirementsValidator */ | ||
private $validator; | ||
|
||
protected function setUp(): void | ||
{ | ||
$this->validator = new PasswordRequirementsValidator(); | ||
} | ||
|
||
protected function tearDown(): void | ||
{ | ||
unset( | ||
$this->validator, | ||
); | ||
} | ||
|
||
/** | ||
* @param string $password | ||
* | ||
* @dataProvider dataProviderForTestPasswordIsValid | ||
*/ | ||
public function testPasswordIsValid(string $password): void | ||
{ | ||
self::assertTrue($this->validator->isValid($password)); | ||
} | ||
|
||
public static function dataProviderForTestPasswordIsValid(): iterable | ||
{ | ||
yield ['qwertY1']; | ||
yield ['QWERTy1']; | ||
yield ['QWERTy1']; | ||
yield ['Пароль1']; | ||
yield ['ПАРОЛь1']; | ||
} | ||
|
||
/** | ||
* @param string $password | ||
* | ||
* @dataProvider dataProviderForTestPasswordIsNotValid | ||
*/ | ||
public function testPasswordIsNotValid(string $password): void | ||
{ | ||
self::assertFalse($this->validator->isValid($password)); | ||
} | ||
|
||
public static function dataProviderForTestPasswordIsNotValid(): iterable | ||
{ | ||
yield ['PASSWORD']; | ||
yield ['password']; | ||
yield ['passWORD']; | ||
yield ['password1']; | ||
yield ['PASSWORD1']; | ||
yield ['парольчик']; | ||
yield ['ПАРОЛЬЧИК']; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
<?php | ||
/* | ||
* This file is part of the StfalconApiBundle. | ||
* | ||
* (c) Stfalcon LLC <stfalcon.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace StfalconStudio\ApiBundle\Util; | ||
|
||
/** | ||
* PasswordRequirementsValidator. | ||
*/ | ||
class PasswordRequirementsValidator | ||
{ | ||
private const NUMBER_REGEXP = '/[\d]{1,}/'; | ||
private const LOWERCASE_LETTER_REGEXP = '/\p{Ll}{1,}/u'; | ||
private const UPPERCASE_LETTER_REGEXP = '/\p{Lu}{1,}/u'; | ||
|
||
/** | ||
* @param string $password | ||
* | ||
* @return bool | ||
*/ | ||
public function isValid(string $password): bool | ||
{ | ||
return $this->hasAtLeastOneNumber($password) | ||
&& $this->hasAtLeastOneUnicodeUpperCaseLetter($password) | ||
&& $this->hasAtLeastOneUnicodeLowerCaseLetter($password) | ||
; | ||
} | ||
|
||
/** | ||
* @param string $password | ||
* | ||
* @return bool | ||
*/ | ||
private function hasAtLeastOneNumber(string $password): bool | ||
{ | ||
return (bool) \preg_match(self::NUMBER_REGEXP, $password); | ||
} | ||
|
||
/** | ||
* @param string $password | ||
* | ||
* @return bool | ||
*/ | ||
private function hasAtLeastOneUnicodeUpperCaseLetter(string $password): bool | ||
{ | ||
return (bool) \preg_match(self::UPPERCASE_LETTER_REGEXP, $password); | ||
} | ||
|
||
/** | ||
* @param string $password | ||
* | ||
* @return bool | ||
*/ | ||
private function hasAtLeastOneUnicodeLowerCaseLetter(string $password): bool | ||
{ | ||
return (bool) \preg_match(self::LOWERCASE_LETTER_REGEXP, $password); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters