Small fix

This commit is contained in:
Alexandre Gomes Gaigalas 2010-11-09 00:32:36 -02:00
parent f9b98679b2
commit b403f67739
3 changed files with 27 additions and 2 deletions

View file

@ -33,7 +33,7 @@ class HasAttribute extends All
{
if (!$this->validate($input))
throw new AttributeNotPresentException($input, $this->attribute);
return parent::validate($input->{$this->attribute});
return parent::validate(@$input->{$this->attribute});
}
public function check($input)

View file

@ -34,7 +34,7 @@ class HasKey extends All
{
if (!$this->validate($input))
throw new KeyNotPresentException($input, $this->key);
return parent::validate($input[$this->key]);
return parent::validate(@$input[$this->key]);
}
public function check($input)

View file

@ -60,4 +60,29 @@ class ValidatorTest extends \PHPUnit_Framework_TestCase
$this->assertTrue($v);
}
public function testSample()
{
$target = new \stdClass;
$target->id = 13;
$target->created_at = '2009-10-10';
$target->name = 'Alexandre';
$validator = Validator::object()
->one(
Validator::hasAttribute('screen_name',
Validator::alnum('_')->noWhitespace()),
Validator::hasAttribute('id', Validator::numeric())
)
->hasAttribute('created_at', Validator::date())
->hasAttribute('name', $v160 = Validator::stringLength(1, 160))
->hasOptionalAttribute('description', $v160)
->hasOptionalAttribute('location', $v160);
try {
$validator->assert($target);
} catch (InvalidException $e) {
echo $e->message();
}
}
}