Skip to content

Commit

Permalink
Merge pull request #298 from henriquemoody/related
Browse files Browse the repository at this point in the history
AbstractRelated is accepts '' as valid by default
  • Loading branch information
henriquemoody committed Feb 13, 2015
2 parents d1af494 + 1b1689b commit 11be936
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
3 changes: 2 additions & 1 deletion library/Rules/AbstractRelated.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,11 @@ public function check($input)
public function validate($input)
{
$hasReference = $this->hasReference($input);

if ($this->mandatory && !$hasReference) {
return false;
}

return $this->decision('validate', $hasReference, $input);
return $this->decision('validate', $hasReference, $input) || $this->getReferenceValue($input) === '';
}
}
10 changes: 10 additions & 0 deletions tests/library/Respect/Validation/Rules/KeyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,16 @@ public function testArrayWithPresentKeyShouldReturnTrue()
$this->assertTrue($validator->validate($obj));
}

public function testArrayWithEmptyKeyShouldReturnTrue()
{
$validator = new Key('someEmptyKey');
$obj = array();
$obj['someEmptyKey'] = '';
$this->assertTrue($validator->assert($obj));
$this->assertTrue($validator->check($obj));
$this->assertTrue($validator->validate($obj));
}

/**
* @expectedException Respect\Validation\Exceptions\KeyException
*/
Expand Down

0 comments on commit 11be936

Please sign in to comment.