fix: revert rule alpha

This commit is contained in:
kenjis 2024-06-13 08:04:39 +09:00
parent 1ca24da3d4
commit cdec7d0b39
No known key found for this signature in database
GPG Key ID: BD254878922AF198
3 changed files with 24 additions and 10 deletions

View File

@ -29,10 +29,6 @@ class FormatRules
*/
public function alpha($str = null): bool
{
if (is_array($str)) {
return false;
}
if (! is_string($str)) {
$str = (string) $str;
}

View File

@ -15,6 +15,7 @@ namespace CodeIgniter\Validation;
use CodeIgniter\Test\CIUnitTestCase;
use Config\Services;
use ErrorException;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Group;
use stdClass;
@ -100,12 +101,6 @@ class RulesTest extends CIUnitTestCase
['foo' => ''],
false,
],
// Invalid array input
[
['foo' => 'if_exist|alpha'],
['foo' => ['bar' => '12345']],
false,
],
// Input data does not exist then the other rules will be ignored
[
['foo' => 'if_exist|required'],
@ -132,6 +127,19 @@ class RulesTest extends CIUnitTestCase
];
}
public function testIfExistArray(): void
{
$this->expectException(ErrorException::class);
$this->expectExceptionMessage('Array to string conversion');
$rules = ['foo' => 'if_exist|alpha'];
// Invalid array input
$data = ['foo' => ['bar' => '12345']];
$this->validation->setRules($rules);
$this->validation->run($data);
}
#[DataProvider('providePermitEmpty')]
public function testPermitEmpty(array $rules, array $data, bool $expected): void
{

View File

@ -244,4 +244,14 @@ final class RulesTest extends TraditionalRulesTest
'foo bar bool match' => [['foo' => true, 'bar' => true], false],
];
}
public function testIfExistArray(): void
{
$rules = ['foo' => 'if_exist|alpha'];
// Invalid array input
$data = ['foo' => ['bar' => '12345']];
$this->validation->setRules($rules);
$this->assertFalse($this->validation->run($data));
}
}