fix: validation errors in model are not cleared when running validation again

This commit is contained in:
kenjis 2022-04-05 11:10:01 +09:00
parent 5e65c4c23c
commit e4f1d8817a
No known key found for this signature in database
GPG Key ID: BD254878922AF198
3 changed files with 26 additions and 6 deletions

View File

@ -25,11 +25,6 @@ parameters:
count: 1
path: system/Autoloader/Autoloader.php
-
message: "#^Method CodeIgniter\\\\Validation\\\\ValidationInterface\\:\\:run\\(\\) invoked with 3 parameters, 0\\-2 required\\.$#"
count: 1
path: system/BaseModel.php
-
message: "#^Property Config\\\\Cache\\:\\:\\$backupHandler \\(string\\) in isset\\(\\) is not nullable\\.$#"
count: 1

View File

@ -1344,7 +1344,9 @@ abstract class BaseModel
return true;
}
return $this->validation->setRules($rules, $this->validationMessages)->run($data, null, $this->DBGroup);
$this->validation->reset()->setRules($rules, $this->validationMessages);
return $this->validation->run($data, null, $this->DBGroup);
}
/**

View File

@ -55,6 +55,29 @@ final class ValidationModelTest extends LiveModelTestCase
$this->assertSame('You forgot to name the baby.', $errors['name']);
}
/**
* @see https://github.com/codeigniter4/CodeIgniter4/issues/5859
*/
public function testValidationTwice(): void
{
$data = [
'name' => null,
'description' => 'some great marketing stuff',
];
$this->assertFalse($this->model->insert($data));
$errors = $this->model->errors();
$this->assertSame('You forgot to name the baby.', $errors['name']);
$data = [
'name' => 'some name',
'description' => 'some great marketing stuff',
];
$this->assertIsInt($this->model->insert($data));
}
public function testValidationWithSetValidationRule(): void
{
$data = [