Skip to content
This repository was archived by the owner on Jan 30, 2020. It is now read-only.

Make symmetric the scenarios when required is true/false #55

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions src/ArrayInput.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,6 @@ public function isValid($context = null)
$result = true;
foreach ($values as $value) {
$empty = ($value === null || $value === '' || $value === []);
if ($empty && !$this->isRequired() && !$this->continueIfEmpty()) {
$result = true;
continue;
}
if ($empty && $this->allowEmpty() && !$this->continueIfEmpty()) {
$result = true;
continue;
Expand Down
4 changes: 0 additions & 4 deletions src/FileInput.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,6 @@ public function isValid($context = null)
return false;
}

if ($empty && ! $required && ! $continueIfEmpty) {
return true;
}

if ($empty && $allowEmpty && ! $continueIfEmpty) {
return true;
}
Expand Down
4 changes: 0 additions & 4 deletions src/Input.php
Original file line number Diff line number Diff line change
Expand Up @@ -409,10 +409,6 @@ public function isValid($context = null)
return false;
}

if ($empty && ! $required && ! $continueIfEmpty) {
return true;
}

if ($empty && $allowEmpty && ! $continueIfEmpty) {
return true;
}
Expand Down
13 changes: 1 addition & 12 deletions test/CollectionInputFilterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,21 +101,17 @@ public function getValidCollectionData()
[
'foo' => ' bazbat ',
'bar' => '12345',
'baz' => '',
'nest' => [
'foo' => ' bazbat ',
'bar' => '12345',
'baz' => '',
],
],
[
'foo' => ' batbaz ',
'bar' => '54321',
'baz' => '',
'nest' => [
'foo' => ' batbaz ',
'bar' => '54321',
'baz' => '',
],
]
];
Expand Down Expand Up @@ -307,7 +303,7 @@ public function testGetValues()

$this->assertCount(2, $this->filter->getValidInput());
foreach ($this->filter->getValidInput() as $validInputs) {
$this->assertCount(4, $validInputs);
$this->assertCount(3, $validInputs);
}
}

Expand Down Expand Up @@ -360,31 +356,25 @@ public function testGetMessagesForInvalidInputs()
[
'foo' => ' bazbattoolong ',
'bar' => '12345',
'baz' => '',
'nest' => [
'foo' => ' bazbat ',
'bar' => '12345',
'baz' => '',
],
],
[
'foo' => ' bazbat ',
'bar' => 'notstring',
'baz' => '',
'nest' => [
'foo' => ' bazbat ',
'bar' => '12345',
'baz' => '',
],
],
[
'foo' => ' bazbat ',
'bar' => '12345',
'baz' => '',
'nest' => [
// missing 'foo' here
'bar' => '12345',
'baz' => '',
],
],
];
Expand Down Expand Up @@ -506,7 +496,6 @@ public function testNonRequiredFieldsAreValidated()
'nest' => [
'foo' => ' bazbat ',
'bar' => '12345',
'baz' => '',
],
]
];
Expand Down
3 changes: 3 additions & 0 deletions test/FileInputTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,9 @@ public function isRequiredVsAllowEmptyVsContinueIfEmptyVsIsValidProvider()
unset($dataSets['Required: T; AEmpty: F; CIEmpty: F; Validator: X, Value: Empty / tmp_name']);
unset($dataSets['Required: T; AEmpty: F; CIEmpty: F; Validator: X, Value: Empty / single']);
unset($dataSets['Required: T; AEmpty: F; CIEmpty: F; Validator: X, Value: Empty / multi']);
unset($dataSets['Required: F; AEmpty: F; CIEmpty: F; Validator: X, Value: Empty / tmp_name']);
unset($dataSets['Required: F; AEmpty: F; CIEmpty: F; Validator: X, Value: Empty / single']);
unset($dataSets['Required: F; AEmpty: F; CIEmpty: F; Validator: X, Value: Empty / multi']);

return $dataSets;
}
Expand Down
2 changes: 1 addition & 1 deletion test/InputTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -655,7 +655,7 @@ public function isRequiredVsAllowEmptyVsContinueIfEmptyVsIsValidProvider()
'Required: F; AEmpty: F; CIEmpty: T; Validator: T' => [!$isRequired, !$aEmpty, $cIEmpty, $validatorValid , $allValues , $isValid, []],
'Required: F; AEmpty: F; CIEmpty: T; Validator: F' => [!$isRequired, !$aEmpty, $cIEmpty, $validatorInvalid, $allValues , !$isValid, $validatorMsg],

'Required: F; AEmpty: F; CIEmpty: F; Validator: X, Value: Empty' => [!$isRequired, !$aEmpty, !$cIEmpty, $validatorNotCall, $emptyValues , $isValid, []],
'Required: F; AEmpty: F; CIEmpty: F; Validator: X, Value: Empty' => [!$isRequired, !$aEmpty, !$cIEmpty, $validatorNotCall, $emptyValues , !$isValid, $notEmptyMsg],
'Required: F; AEmpty: F; CIEmpty: F; Validator: T, Value: Not Empty' => [!$isRequired, !$aEmpty, !$cIEmpty, $validatorValid , $nonEmptyValues, $isValid, []],
'Required: F; AEmpty: F; CIEmpty: F; Validator: F, Value: Not Empty' => [!$isRequired, !$aEmpty, !$cIEmpty, $validatorInvalid, $nonEmptyValues, !$isValid, $validatorMsg],
];
Expand Down