Skip to content

Commit

Permalink
Merge pull request #403 from laminas/3.0.x-merge-up-into-3.1.x_zGMcvevu
Browse files Browse the repository at this point in the history
Merge release 3.0.1 into 3.1.x
  • Loading branch information
gsteel authored Nov 29, 2024
2 parents 01c59cf + ab6f456 commit 22980ee
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/Digits.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
14 changes: 10 additions & 4 deletions test/DigitsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, array{0: string, 1: bool}>
* @psalm-return array<string, array{0: mixed, 1: bool}>
*/
public static function basicDataProvider(): array
{
Expand All @@ -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
];
Expand Down

0 comments on commit 22980ee

Please sign in to comment.