Skip to content

Commit

Permalink
AbstractRelated is accepts '' as valid by default
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexandre Gaigalas authored and henriquemoody committed Feb 13, 2015
1 parent d1af494 commit 1b1689b
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 1b1689b

Please sign in to comment.