Skip to content

Commit 281615f

Browse files
committed
test: add tests for required_with with zero value
1 parent ef732e0 commit 281615f

1 file changed

Lines changed: 27 additions & 3 deletions

File tree

tests/system/Validation/RulesTest.php

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -617,9 +617,9 @@ public function requiredWithProvider(): Generator
617617
/**
618618
* @see https://github.com/codeigniter4/CodeIgniter4/issues/7557
619619
*
620-
* @dataProvider RequiredWithAndOtherRuleProvider
620+
* @dataProvider RequiredWithAndOtherRulesProvider
621621
*/
622-
public function testRequiredWithAndOtherRule(bool $expected, array $data): void
622+
public function testRequiredWithAndOtherRules(bool $expected, array $data): void
623623
{
624624
$this->validation->setRules([
625625
'mustBeADate' => 'required_with[otherField]|permit_empty|valid_date',
@@ -630,7 +630,7 @@ public function testRequiredWithAndOtherRule(bool $expected, array $data): void
630630
$this->assertSame($expected, $result);
631631
}
632632

633-
public function RequiredWithAndOtherRuleProvider(): Generator
633+
public function RequiredWithAndOtherRulesProvider(): Generator
634634
{
635635
yield from [
636636
// `otherField` and `mustBeADate` do not exist
@@ -652,6 +652,30 @@ public function RequiredWithAndOtherRuleProvider(): Generator
652652
];
653653
}
654654

655+
/**
656+
* @dataProvider RequiredWithAndOtherRuleWithValueZeroProvider
657+
*/
658+
public function testRequiredWithAndOtherRuleWithValueZero(bool $expected, array $data): void
659+
{
660+
$this->validation->setRules([
661+
'married' => ['rules' => ['in_list[0,1]']],
662+
'partner_name' => ['rules' => ['permit_empty', 'required_with[married]', 'alpha_space']],
663+
]);
664+
665+
$result = $this->validation->run($data);
666+
667+
$this->assertSame($expected, $result);
668+
}
669+
670+
public function RequiredWithAndOtherRuleWithValueZeroProvider(): Generator
671+
{
672+
yield from [
673+
[true, ['married' => '0', 'partner_name' => '']],
674+
[true, ['married' => '1', 'partner_name' => 'Foo']],
675+
[false, ['married' => '1', 'partner_name' => '']],
676+
];
677+
}
678+
655679
/**
656680
* @dataProvider requiredWithoutProvider
657681
*/

0 commit comments

Comments
 (0)