Less Reflection on Validator, better tests for AllOf

This commit is contained in:
Alexandre Gomes Gaigalas 2010-12-07 10:11:14 -02:00
parent 71b510cd51
commit b3cc2285fc
5 changed files with 41 additions and 12 deletions

View file

@ -10,6 +10,11 @@ abstract class AbstractRule implements Validatable
protected $exception;
public function __construct()
{
}
public function __invoke($input)
{
return $this->validate($input);

View file

@ -107,13 +107,9 @@ class Validator extends AllOf
throw new ComponentException(
sprintf(static::ERR_INTERFACE, $validatorFqn)
);
if ($validatorClass->hasMethod('__construct')) {
$validatorInstance = $validatorClass->newInstanceArgs(
$arguments
);
} else {
$validatorInstance = new $validatorFqn;
}
$validatorInstance = $validatorClass->newInstanceArgs(
$arguments
);
return $validatorInstance;
}

View file

@ -62,7 +62,7 @@ class AbstractRelatedTest extends \PHPUnit_Framework_TestCase
}
/**
* @expectedException InvalidArgumentException
* @expectedException OutOfBoundsException
*/
public function testAssertHasReference()
{
@ -70,7 +70,7 @@ class AbstractRelatedTest extends \PHPUnit_Framework_TestCase
'', null, true, false
);
//overriding exception cause mocks cant handle createException properly
$mock->setException(new \InvalidArgumentException(''));
$mock->setException(new \OutOfBoundsException(''));
$this->assertFalse($mock->assert('bla'));
}

View file

@ -25,11 +25,11 @@ class AllOfTest extends \PHPUnit_Framework_TestCase
}
/**
* @expectedException Respect\Validation\Exceptions\ValidationException
* @expectedException Respect\Validation\Exceptions\AllOfException
*/
public function testInvalid()
{
$valid1 = new Callback(function() {
$theInvalidOne = new Callback(function() {
return false;
});
$valid2 = new Callback(function() {
@ -38,8 +38,35 @@ class AllOfTest extends \PHPUnit_Framework_TestCase
$valid3 = new Callback(function() {
return true;
});
$o = new AllOf($valid1, $valid2, $valid3);
$o = new AllOf($theInvalidOne, $valid2, $valid3);
$this->assertFalse($o->assert('any'));
$o = new AllOf($valid2, $theInvalidOne, $valid3);
$this->assertFalse($o->assert('any'));
$o = new AllOf($valid2, $valid3, $theInvalidOne);
$this->assertFalse($o->assert('any'));
}
/**
* @expectedException OutOfBoundsException
*/
public function testCheck()
{
$valid1 = new Callback(function() {
return true;
});
$theInvalidOne = new Callback(function() {
return false;
});
$valid3 = new Callback(function() {
return true;
});
$theInvalidOne->setException(new \OutOfBoundsException(''));
$o = new AllOf($valid1, $theInvalidOne, $valid3);
$this->assertFalse($o->check('any'));
$o = new AllOf($theInvalidOne, $valid3, $valid1);
$this->assertFalse($o->check('any'));
$o = new AllOf($valid3, $valid1, $theInvalidOne);
$this->assertFalse($o->check('any'));
}
}

View file

@ -1,3 +1,4 @@
<phpunit backupGlobals="false"
backupStaticAttributes="true"
bootstrap="bootstrap.php"