Merge branch '1.0' into 1.1

This commit is contained in:
Henrique Moody 2016-05-05 13:03:25 +02:00
commit 3e1988f9c1
2 changed files with 25 additions and 0 deletions

View file

@ -87,6 +87,10 @@ class KeySet extends AllOf
*/
private function hasValidStructure($input)
{
if (!is_array($input)) {
return false;
}
foreach ($this->getRules() as $keyRule) {
if (!array_key_exists($keyRule->reference, $input) && $keyRule->mandatory) {
return false;

View file

@ -172,4 +172,25 @@ class KeySetTest extends PHPUnit_Framework_TestCase
$keySet = new KeySet($key1, $key2);
$keySet->assert($input);
}
/**
* @expectedException Respect\Validation\Exceptions\KeySetException
* @expectedExceptionMessage Must have keys { "name" }
* @dataProvider providerForInvalidArguments
*/
public function testShouldThrowExceptionInCaseArgumentIsAnythingOtherThanArray($input)
{
$keySet = new KeySet(new Key('name'));
$keySet->assert($input);
}
public function providerForInvalidArguments()
{
return [
[''],
[null],
[0],
[new \stdClass()]
];
}
}