From a1ab6975d5dd969c369e6899f6c19fff1fc4a8f9 Mon Sep 17 00:00:00 2001 From: Jolien Trog Date: Tue, 2 Sep 2025 15:59:18 +0200 Subject: [PATCH] codereview: Improve type hints and return types --- modules/password-policy | 0 .../Application/CommonPasswordPolicyTest.php | 52 ++++++++----------- .../Application/NoPasswordPolicyTest.php | 15 ++---- 3 files changed, 26 insertions(+), 41 deletions(-) create mode 100644 modules/password-policy diff --git a/modules/password-policy b/modules/password-policy new file mode 100644 index 000000000..e69de29bb diff --git a/test/php/library/Icinga/Application/CommonPasswordPolicyTest.php b/test/php/library/Icinga/Application/CommonPasswordPolicyTest.php index 622158896..c3a8e38f0 100644 --- a/test/php/library/Icinga/Application/CommonPasswordPolicyTest.php +++ b/test/php/library/Icinga/Application/CommonPasswordPolicyTest.php @@ -8,79 +8,71 @@ use Icinga\Test\BaseTestCase; class CommonPasswordPolicyTest extends BaseTestCase { - private object $object; + private PasswordPolicyHook $instance; public function setUp(): void { - $this->object = new CommonPasswordPolicy(); - } - - public function testClassIsInstanzOf() - { - $this->assertInstanceOf(PasswordPolicyHook::class, $this->object); + $this->instance = new CommonPasswordPolicy(); } public function testMethodGetName(): void { - $this->assertSame('Common', $this->object->getName()); + $this->assertSame('Common', $this->instance->getName()); } - public function testValidatePasswordTooShort() + public function testValidatePasswordTooShort(): void { - $res = $this->object->validatePassword('Icinga1#'); + $res = $this->instance->validatePassword('Icinga1#'); $this->assertSame('Password must be at least 12 characters long', $res[0]); $this->assertCount(1, $res); } - public function testValidatePasswordNoNumber() + public function testValidatePasswordNoNumber(): void { - $res = $this->object->validatePassword('Icingaadmin#'); + $res = $this->instance->validatePassword('Icingaadmin#'); $this->assertSame('Password must contain at least one number', $res[0]); - var_dump($res); $this->assertCount(1, $res); } - public function testValidatePasswordNoSpecialCharacter() + public function testValidatePasswordNoSpecialCharacter(): void { - $res = $this->object->validatePassword('Icingaadmin1'); + $res = $this->instance->validatePassword('Icingaadmin1'); $this->assertSame('Password must contain at least one special character', $res[0]); $this->assertCount(1, $res); } - public function testValidatePasswordNoUpperCaseLetters() + public function testValidatePasswordNoUpperCaseLetters(): void { - $res = $this->object->validatePassword('icingaadmin1#'); + $res = $this->instance->validatePassword('icingaadmin1#'); $this->assertSame('Password must contain at least one uppercase letter', $res[0]); $this->assertCount(1, $res); } - public function testValidatePasswordNoLowerCaseLetters() + public function testValidatePasswordNoLowerCaseLetters(): void { - $res = $this->object->validatePassword('ICINGAADMIN1#'); + $res = $this->instance->validatePassword('ICINGAADMIN1#'); $this->assertSame('Password must contain at least one lowercase letter', $res[0]); $this->assertCount(1, $res); } - public function testValidatePasswordValid() + public function testValidatePasswordValid(): void { - $res = $this->object->validatePassword('Icingaadmin1#'); + $res = $this->instance->validatePassword('Icingaadmin1#'); $this->assertEmpty($res); } - public function testValidatePasswordOnlyLowerCaseLetters() + public function testValidatePasswordOnlyLowerCaseLetters(): void { - $res = $this->object->validatePassword('icingawebadmin'); - var_dump($res); + $res = $this->instance->validatePassword('icingawebadmin'); $this->assertCount(3, $res); $this->assertSame('Password must contain at least one number', $res[0]); $this->assertSame('Password must contain at least one special character', $res[1]); $this->assertSame('Password must contain at least one uppercase letter', $res[2]); } - public function testValidatePasswordWithLengthAndUpperCaseLetters() + public function testValidatePasswordWithLengthAndUpperCaseLetters(): void { - $res = $this->object->validatePassword('ICINGAADMIN'); - var_dump($res); + $res = $this->instance->validatePassword('ICINGAADMIN'); $this->assertCount(4, $res); $this->assertSame('Password must be at least 12 characters long', $res[0]); $this->assertSame('Password must contain at least one number', $res[1]); @@ -88,12 +80,10 @@ class CommonPasswordPolicyTest extends BaseTestCase $this->assertSame('Password must contain at least one lowercase letter', $res[3]); } - public function testValidatePasswordWithManyCharacters() + public function testValidatePasswordWithManyCharacters(): void { $longPassword = str_repeat('a', 1000); - var_dump($longPassword); - $res = $this->object->validatePassword($longPassword); - var_dump($res); + $res = $this->instance->validatePassword($longPassword); $this->assertCount(3, $res); } } diff --git a/test/php/library/Icinga/Application/NoPasswordPolicyTest.php b/test/php/library/Icinga/Application/NoPasswordPolicyTest.php index fd4d981ac..4eb4b0685 100644 --- a/test/php/library/Icinga/Application/NoPasswordPolicyTest.php +++ b/test/php/library/Icinga/Application/NoPasswordPolicyTest.php @@ -8,26 +8,21 @@ use Icinga\Application\ProvidedHook\NoPasswordPolicy; class NoPasswordPolicyTest extends BaseTestCase { - private object $object; + private PasswordPolicyHook $instance; public function setUp(): void { - $this->object = new NoPasswordPolicy(); - } - - public function testClassIsInstanzOf() - { - $this->assertInstanceOf(PasswordPolicyHook::class, $this->object); + $this->instance = new NoPasswordPolicy(); } public function testMethodGetName(): void { - $this->assertSame('None', $this->object->getName()); + $this->assertSame('None', $this->instance->getName()); } - public function testValidatePasswordValid() + public function testValidatePasswordValid(): void { - $res = $this->object->validatePassword('icingaadmin'); + $res = $this->instance->validatePassword('icingaadmin'); $this->assertEmpty($res); } }