From 51fac7bd208651c80ad6921f6a0497036c577b92 Mon Sep 17 00:00:00 2001 From: "John Paul E. Balandan, CPA" Date: Fri, 11 Jul 2025 22:53:20 +0800 Subject: [PATCH 1/2] Fix other test methods --- tests/Unit/NothingPersonalValidatorTest.php | 39 ++++++++++----------- 1 file changed, 19 insertions(+), 20 deletions(-) diff --git a/tests/Unit/NothingPersonalValidatorTest.php b/tests/Unit/NothingPersonalValidatorTest.php index 30652de42..030011db1 100644 --- a/tests/Unit/NothingPersonalValidatorTest.php +++ b/tests/Unit/NothingPersonalValidatorTest.php @@ -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 @@ -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', @@ -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', @@ -202,15 +195,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', @@ -226,9 +216,12 @@ public function testConfigPersonalFieldsValues(mixed $firstName, mixed $lastName $this->assertSame($expected, $result->isOK()); } + /** + * @return iterable + */ public static function provideConfigPersonalFieldsValues(): iterable { - return [ + yield from [ [ 'Count', '', @@ -248,7 +241,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; @@ -266,6 +259,9 @@ public function testMaxSimilarityZeroTurnsOffSimilarityCalculation(mixed $maxSim $this->assertSame($expected, $result->isOK()); } + /** + * @return iterable + */ public static function provideMaxSimilarityZeroTurnsOffSimilarityCalculation(): iterable { return [ @@ -298,6 +294,9 @@ public function testCheckPasswordWithBadEmail(string $email, bool $expected): vo $this->assertSame($expected, $result->isOK()); } + /** + * @return iterable + */ public static function provideCheckPasswordWithBadEmail(): iterable { return [ From fcd15fe134e373352aba75a7c25016babed838ac Mon Sep 17 00:00:00 2001 From: "John Paul E. Balandan, CPA" Date: Fri, 11 Jul 2025 22:54:18 +0800 Subject: [PATCH 2/2] Fix values being compared --- tests/Unit/NothingPersonalValidatorTest.php | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/tests/Unit/NothingPersonalValidatorTest.php b/tests/Unit/NothingPersonalValidatorTest.php index 030011db1..8d4499dcf 100644 --- a/tests/Unit/NothingPersonalValidatorTest.php +++ b/tests/Unit/NothingPersonalValidatorTest.php @@ -162,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', ]); @@ -173,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 + */ public static function provideIsNotPersonalFalsePositivesCaughtByIsNotSimilar(): iterable { - return [ + yield from [ ['JoeTheCaptain'], ['JoeCaptain'], ['CaptainJ'],