Skip to content

Commit 8993320

Browse files
committed
Se agrega a isEmptyValue() la validación de un arreglo vacío.
1 parent fb251bd commit 8993320

3 files changed

Lines changed: 26 additions & 1 deletion

File tree

src/Processor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,6 @@ private function isRequiredRule(string $ruleString): bool
118118
*/
119119
private function isEmptyValue(mixed $value): bool
120120
{
121-
return $value === null || $value === '';
121+
return $value === null || $value === '' || $value === [];
122122
}
123123
}

tests/src/ProcessorTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -450,6 +450,21 @@ public static function notRequiredValidationDataProvider(): array
450450
['validate' => ['email', 'min_length:5', 'max_length:50']],
451451
false,
452452
],
453+
'not_required_file_with_empty_array' => [
454+
[],
455+
['validate' => ['file']],
456+
true,
457+
],
458+
'not_required_image_with_empty_array' => [
459+
[],
460+
['validate' => ['image']],
461+
true,
462+
],
463+
'not_required_mimetype_with_empty_array' => [
464+
[],
465+
['validate' => ['mimetype:image/jpeg']],
466+
true,
467+
],
453468
];
454469
}
455470

tests/src/Rule/Validator/FileValidationTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,16 @@ public function testInvalidFormatBadArray(): void
262262
$rule->validate(['foo' => 'bar']);
263263
}
264264

265+
public function testEmptyArrayThrowsInvalidFormat(): void
266+
{
267+
// The validator itself has no concept of "optional" — an empty array
268+
// is currently an invalid format. Skipping for optional fields is the
269+
// pipeline's responsibility (Processor::isEmptyValue).
270+
$rule = $this->makeConcreteRule();
271+
$this->expectException(ValidationException::class);
272+
$rule->validate([]);
273+
}
274+
265275
// -------------------------------------------------------------------------
266276
// Tests for PSR-7 UploadedFileInterface.
267277
// -------------------------------------------------------------------------

0 commit comments

Comments
 (0)