Skip to content

Commit

Permalink
test: add tests for required_without
Browse files Browse the repository at this point in the history
  • Loading branch information
kenjis committed Sep 21, 2022
1 parent 5a0f1e3 commit 3ac348b
Showing 1 changed file with 93 additions and 0 deletions.
93 changes: 93 additions & 0 deletions tests/system/Validation/RulesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -639,4 +639,97 @@ public function requiredWithoutProvider(): Generator
],
];
}

/**
* @dataProvider requiredWithoutMultipleProvider
*/
public function testRequiredWithoutMultiple(string $foo, string $bar, string $baz, bool $result): void
{
$this->validation->setRules(['foo' => 'required_without[bar,baz]']);

$data = [
'foo' => $foo,
'bar' => $bar,
'baz' => $baz,
];
$this->assertSame($result, $this->validation->run($data));
}

public function requiredWithoutMultipleProvider(): Generator
{
yield from [
'all empty' => [
'',
'',
'',
false,
],
'foo is not empty' => [
'a',
'',
'',
true,
],
'bar is not empty' => [
'',
'b',
'',
false,
],
'baz is not empty' => [
'',
'',
'c',
false,
],
'bar,baz are not empty' => [
'',
'b',
'c',
true,
],
];
}

/**
* @dataProvider requiredWithoutMultipleWithoutFieldsProvider
*/
public function testRequiredWithoutMultipleWithoutFields(array $data, bool $result): void
{
$this->validation->setRules(['foo' => 'required_without[bar,baz]']);

$this->assertSame($result, $this->validation->run($data));
}

public function requiredWithoutMultipleWithoutFieldsProvider(): Generator
{
yield from [
'baz is missing' => [
[
'foo' => '',
'bar' => '',
],
false,
],
'bar,baz are missing' => [
[
'foo' => '',
],
false,
],
'bar is not empty' => [
[
'foo' => '',
'bar' => 'b',
],
false,
],
'foo is not empty' => [
[
'foo' => 'a',
],
true,
],
];
}
}

0 comments on commit 3ac348b

Please sign in to comment.