mirror of
https://github.com/Respect/Validation.git
synced 2026-03-15 06:45:44 +01:00
Issue #260: Now using Respect\Validation exceptions only
* `ExceptionInterface`: all Respect\Validation\Exceptions implement through inheritance
* `ValidatorExceptionInterface`: implemented only by AllOfException. This allows the end users to know when there has been a Validator exception rather than just any of our exceptions.
Fixed formatting issues
Created two new exception types
* Created ValidationExceptionInterface
* Created NestedValidationExceptionInterface which extends ValidationExceptionInterface
* Renamed from ValidatorExceptionInterface
* ValidationException implements ValidationExceptionInterface and ValidationExceptionTest checks for the implementation.
* AbstractNestedException implements NestedValidationExceptionInterface and AbstractNestedExceptionTest checks for the implementation.
* CheckExceptionsTest now checks all Rule exceptions to make sure they implement ValidationExceptionInterface
* ValidatorTest now contains test that shows that only ValidationExceptionInterface can be used reliably with `::check()`
* Updated documentation for new exception types
* Reworked examples to show how to catch the exception interfaces
Minor changes in readme.md and ExceptionInterfaces
* Removed `import` statements (hahaha)
* Renamed `$e` to `$exception`
* `ValidationExceptionInterface` now extends `ExceptionInterface`. Changed `ValidationException` to match
This commit is contained in:
parent
116be2bbef
commit
ab65035181
11 changed files with 132 additions and 23 deletions
|
|
@ -5,6 +5,13 @@ use Respect\Validation\Validator as v;
|
|||
|
||||
class AbstractNestedExceptionTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testItImplementsNestedValidationExceptionInterface()
|
||||
{
|
||||
$abstractNestedException = $this->getMock('Respect\Validation\Exceptions\AbstractNestedException');
|
||||
$this->assertInstanceOf('Respect\Validation\Exceptions\NestedValidationExceptionInterface',
|
||||
$abstractNestedException);
|
||||
}
|
||||
|
||||
public function testGetRelatedShouldReturnExceptionAddedByAddRelated()
|
||||
{
|
||||
$composite = new AttributeException;
|
||||
|
|
@ -75,7 +82,7 @@ class AbstractNestedExceptionTest extends \PHPUnit_Framework_TestCase
|
|||
'security_question' => null,
|
||||
)
|
||||
);
|
||||
} catch (ValidationException $e) {
|
||||
} catch (NestedValidationExceptionInterface $e) {
|
||||
$messages = $e->findMessages(
|
||||
array('allOf', 'first_name.length')
|
||||
);
|
||||
|
|
@ -114,7 +121,7 @@ class AbstractNestedExceptionTest extends \PHPUnit_Framework_TestCase
|
|||
'security_question' => null,
|
||||
)
|
||||
);
|
||||
} catch (ValidationException $e) {
|
||||
} catch (NestedValidationExceptionInterface $e) {
|
||||
$messages = $e->findMessages(
|
||||
array(
|
||||
'allOf' => 'Invalid {{name}}',
|
||||
|
|
@ -127,4 +134,3 @@ class AbstractNestedExceptionTest extends \PHPUnit_Framework_TestCase
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue