Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 28 additions & 26 deletions tests/Unit/NothingPersonalValidatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ protected function setUp(): void
{
parent::setUp();

$config = new Auth();
$this->validator = new NothingPersonalValidator($config);
$this->validator = new NothingPersonalValidator(new Auth());
}

public function testFalseOnPasswordIsEmail(): void
Expand Down Expand Up @@ -86,11 +85,8 @@ public function testTrueWhenPasswordHasNothingPersonal(): void
{
$config = new Auth();
$config->maxSimilarity = 50;
$config->personalFields = [
'firstname',
'lastname',
];
$this->validator = new NothingPersonalValidator($config);
$config->personalFields = ['firstname', 'lastname'];
$this->validator = new NothingPersonalValidator($config);

$user = new User([
'email' => 'jsmith@example.com',
Expand All @@ -110,11 +106,8 @@ public function testTrueWhenNoUsername(): void
{
$config = new Auth();
$config->maxSimilarity = 50;
$config->personalFields = [
'firstname',
'lastname',
];
$this->validator = new NothingPersonalValidator($config);
$config->personalFields = ['firstname', 'lastname'];
$this->validator = new NothingPersonalValidator($config);

$user = new User([
'email' => 'jsmith@example.com',
Expand Down Expand Up @@ -169,9 +162,9 @@ public function testFalseForSensibleMatch(): void
* $config->maxSimilarity = 50; is the highest setting where all tests pass.
*/
#[DataProvider('provideIsNotPersonalFalsePositivesCaughtByIsNotSimilar')]
public function testIsNotPersonalFalsePositivesCaughtByIsNotSimilar(mixed $password): void
public function testIsNotPersonalFalsePositivesCaughtByIsNotSimilar(string $password): void
{
new User([
$user = new User([
'username' => 'CaptainJoe',
'email' => 'JosephSmith@example.com',
]);
Expand All @@ -180,16 +173,19 @@ public function testIsNotPersonalFalsePositivesCaughtByIsNotSimilar(mixed $passw
$config->maxSimilarity = 50;
$this->validator = new NothingPersonalValidator($config);

$isNotPersonal = $this->getPrivateMethodInvoker($this->validator, 'isNotPersonal');
$isNotPersonal = self::getPrivateMethodInvoker($this->validator, 'isNotPersonal');

$isNotSimilar = $this->getPrivateMethodInvoker($this->validator, 'isNotSimilar');
$isNotSimilar = self::getPrivateMethodInvoker($this->validator, 'isNotSimilar');

$this->assertNotSame($isNotPersonal, $isNotSimilar);
$this->assertNotSame($isNotPersonal($password, $user), $isNotSimilar($password, $user));
}

/**
* @return iterable<int, array{0: string}>
*/
public static function provideIsNotPersonalFalsePositivesCaughtByIsNotSimilar(): iterable
{
return [
yield from [
['JoeTheCaptain'],
['JoeCaptain'],
['CaptainJ'],
Expand All @@ -202,15 +198,12 @@ public static function provideIsNotPersonalFalsePositivesCaughtByIsNotSimilar():
}

#[DataProvider('provideConfigPersonalFieldsValues')]
public function testConfigPersonalFieldsValues(mixed $firstName, mixed $lastName, mixed $expected): void
public function testConfigPersonalFieldsValues(string $firstName, string $lastName, bool $expected): void
{
$config = new Auth();
$config->maxSimilarity = 66;
$config->personalFields = [
'firstname',
'lastname',
];
$this->validator = new NothingPersonalValidator($config);
$config->personalFields = ['firstname', 'lastname'];
$this->validator = new NothingPersonalValidator($config);

$user = new User([
'username' => 'Vlad the Impaler',
Expand All @@ -226,9 +219,12 @@ public function testConfigPersonalFieldsValues(mixed $firstName, mixed $lastName
$this->assertSame($expected, $result->isOK());
}

/**
* @return iterable<int, array{0: string, 1: string, 2: bool}>
*/
public static function provideConfigPersonalFieldsValues(): iterable
{
return [
yield from [
[
'Count',
'',
Expand All @@ -248,7 +244,7 @@ public static function provideConfigPersonalFieldsValues(): iterable
}

#[DataProvider('provideMaxSimilarityZeroTurnsOffSimilarityCalculation')]
public function testMaxSimilarityZeroTurnsOffSimilarityCalculation(mixed $maxSimilarity, mixed $expected): void
public function testMaxSimilarityZeroTurnsOffSimilarityCalculation(int $maxSimilarity, bool $expected): void
{
$config = new Auth();
$config->maxSimilarity = $maxSimilarity;
Expand All @@ -266,6 +262,9 @@ public function testMaxSimilarityZeroTurnsOffSimilarityCalculation(mixed $maxSim
$this->assertSame($expected, $result->isOK());
}

/**
* @return iterable<int, array{0: int, 1: bool}>
*/
public static function provideMaxSimilarityZeroTurnsOffSimilarityCalculation(): iterable
{
return [
Expand Down Expand Up @@ -298,6 +297,9 @@ public function testCheckPasswordWithBadEmail(string $email, bool $expected): vo
$this->assertSame($expected, $result->isOK());
}

/**
* @return iterable<int, array{0: string, 1: bool}>
*/
public static function provideCheckPasswordWithBadEmail(): iterable
{
return [
Expand Down
Loading