mirror of
https://github.com/Respect/Validation.git
synced 2026-03-17 23:59:51 +01:00
Refactor ValidationException
Make the ValidationException a little bit less mutable than before. All its dependencies are now passed into the constructor. This commit also make the Factory pass the translator to the exceptions allowing to define the translator before the exception gets created. This change is not the ideal one, later I would like to not need the Singleton from the Factory to do that, but for now it seems like a good approach. One more thing that this commit does is to introduce the "id" for Exceptions. Key can be either the defined "name" or the name of the rule that throwed the exception. This method will be handy to identify exceptions better. Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
This commit is contained in:
parent
d7ebb8c1a7
commit
8c529c433e
35 changed files with 385 additions and 285 deletions
|
|
@ -15,20 +15,12 @@ namespace Respect\Validation\Exceptions;
|
|||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* phpunit has an issue with mocking exceptions when in HHVM:
|
||||
* https://github.com/sebastianbergmann/phpunit-mock-objects/issues/207.
|
||||
*/
|
||||
class PrivateNestedValidationException extends NestedValidationException
|
||||
{
|
||||
}
|
||||
|
||||
class NestedValidationExceptionTest extends TestCase
|
||||
{
|
||||
public function testGetRelatedShouldReturnExceptionAddedByAddRelated(): void
|
||||
{
|
||||
$composite = new AttributeException();
|
||||
$node = new IntValException();
|
||||
$composite = new AttributeException('input', 'id', [], 'trim');
|
||||
$node = new IntValException('input', 'id', [], 'trim');
|
||||
$composite->addRelated($node);
|
||||
self::assertEquals(1, count($composite->getRelated(true)));
|
||||
self::assertContainsOnly($node, $composite->getRelated());
|
||||
|
|
@ -36,8 +28,8 @@ class NestedValidationExceptionTest extends TestCase
|
|||
|
||||
public function testAddingTheSameInstanceShouldAddJustASingleReference(): void
|
||||
{
|
||||
$composite = new AttributeException();
|
||||
$node = new IntValException();
|
||||
$composite = new AttributeException('input', 'id', [], 'trim');
|
||||
$node = new IntValException('input', 'id', [], 'trim');
|
||||
$composite->addRelated($node);
|
||||
$composite->addRelated($node);
|
||||
$composite->addRelated($node);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue