diff --git a/src/Digits.php b/src/Digits.php index 767784bd..c72c5091 100644 --- a/src/Digits.php +++ b/src/Digits.php @@ -45,7 +45,7 @@ public function isValid(mixed $value): bool $digits = preg_replace('/[^0-9]/', '', (string) $value); - if ($value !== $digits) { + if ((string) $value !== $digits) { $this->error(self::NOT_DIGITS); return false; } diff --git a/test/DigitsTest.php b/test/DigitsTest.php index 8e9457ac..2ed0889f 100644 --- a/test/DigitsTest.php +++ b/test/DigitsTest.php @@ -23,13 +23,13 @@ protected function setUp(): void * Ensures that the validator follows expected behavior for basic input values */ #[DataProvider('basicDataProvider')] - public function testExpectedResultsWithBasicInputValues(string $input, bool $expected): void + public function testExpectedResultsWithBasicInputValues(mixed $input, bool $expected): void { self::assertSame($expected, $this->validator->isValid($input)); } /** - * @psalm-return array + * @psalm-return array */ public static function basicDataProvider(): array { @@ -39,11 +39,17 @@ public static function basicDataProvider(): array 'invalid; contains alphabetic chars and one whitespace' => ['abc 123', false], 'invalid; contains only alphabetic chars' => ['abcxyz', false], 'invalid; contains alphabetic and special chars' => ['AZ@#4.3', false], - 'invalid; is a float' => ['1.23', false], - 'invalid; is a hexa notation' => ['0x9f', false], + 'invalid; string float' => ['1.23', false], + 'invalid; float' => [1.23, false], + 'Hex string' => ['0x9f', false], + 'Hex int' => [0x9f, true], 'invalid; is empty' => ['', false], + 'Boolean' => [true, false], + 'Null' => [null, false], + 'Array' => [['123'], false], 'valid; is a normal integer' => ['123', true], + 'any integer' => [123, true], 'valid; starts with a zero' => ['09', true], // phpcs:enable ];