mirror of
https://github.com/Respect/Validation.git
synced 2024-06-29 02:30:06 +02:00
Merge branch '1.0' into 1.1
This commit is contained in:
commit
3e1988f9c1
|
@ -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;
|
||||
|
|
|
@ -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()]
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue