mirror of
https://github.com/Respect/Validation.git
synced 2024-06-11 10:12:16 +02:00
Remove "NestedValidationExceptionInterface"
This commit is contained in:
parent
04db93bdad
commit
67e072ebd3
|
@ -70,6 +70,7 @@ All notable changes of the Respect\Validation releases are documented in this fi
|
|||
|
||||
- Drop support for PHP 5.3 (#466)
|
||||
- Remove `addOr()` shortcut (#444)
|
||||
- Remove `NestedValidationExceptionInterface` interface (#591)
|
||||
- Remove `not()` shortcut (#444)
|
||||
- Remove identical checking from "Equals" rule (#442)
|
||||
- Removed Deprecated Rules (#277)
|
||||
|
|
|
@ -103,10 +103,14 @@ $usernameValidator->validate('#$%'); //false
|
|||
* Use when calling `check()`
|
||||
* All validation exceptions implement this interface
|
||||
* Interface has one method: `getMainMessage()`
|
||||
* `Respect\Validation\Exceptions\NestedValidationExceptionInterface`:
|
||||
* Extends the `Respect\Validation\Exceptions\ValidationExceptionInterface` interface
|
||||
* Use when calling `assert()`
|
||||
* Interface has three methods: `getFullMessage()`, `findMessages()`, and `getMainMessage()`.
|
||||
* `Respect\Validation\Exceptions\NestedValidationException`:
|
||||
* Extends the `Respect\Validation\Exceptions\ValidationException` class
|
||||
* Usually thrown when the `assert()` fails
|
||||
* Available methods:
|
||||
* `findMessages()`;
|
||||
* `getFullMessage()`;
|
||||
* `getMessages()`;
|
||||
* more...
|
||||
|
||||
## Informative exceptions
|
||||
|
||||
|
@ -114,11 +118,11 @@ When something goes wrong, Validation can tell you exactly what's going on. For
|
|||
we use the `assert()` method instead of `validate()`:
|
||||
|
||||
```php
|
||||
use Respect\Validation\Exceptions\NestedValidationExceptionInterface;
|
||||
use Respect\Validation\Exceptions\NestedValidationException;
|
||||
|
||||
try {
|
||||
$usernameValidator->assert('really messed up screen#name');
|
||||
} catch(NestedValidationExceptionInterface $exception) {
|
||||
} catch(NestedValidationException $exception) {
|
||||
echo $exception->getFullMessage();
|
||||
}
|
||||
```
|
||||
|
@ -142,7 +146,7 @@ It will return all messages from the rules that did not pass the validation.
|
|||
```php
|
||||
try {
|
||||
$usernameValidator->assert('really messed up screen#name');
|
||||
} catch(NestedValidationExceptionInterface $exception) {
|
||||
} catch(NestedValidationException $exception) {
|
||||
print_r($exception->getMessages());
|
||||
}
|
||||
```
|
||||
|
@ -166,7 +170,7 @@ the names of the rules you want:
|
|||
```php
|
||||
try {
|
||||
$usernameValidator->assert('really messed up screen#name');
|
||||
} catch(NestedValidationExceptionInterface $exception) {
|
||||
} catch(NestedValidationException $exception) {
|
||||
print_r($exception->findMessages(['alnum', 'noWhitespace']));
|
||||
}
|
||||
```
|
||||
|
|
|
@ -11,10 +11,11 @@
|
|||
|
||||
namespace Respect\Validation\Exceptions;
|
||||
|
||||
use IteratorAggregate;
|
||||
use RecursiveIteratorIterator;
|
||||
use SplObjectStorage;
|
||||
|
||||
class NestedValidationException extends ValidationException implements NestedValidationExceptionInterface
|
||||
class NestedValidationException extends ValidationException implements IteratorAggregate
|
||||
{
|
||||
/**
|
||||
* @var SplObjectStorage
|
||||
|
|
|
@ -1,21 +0,0 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Respect/Validation.
|
||||
*
|
||||
* (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
|
||||
*
|
||||
* For the full copyright and license information, please view the "LICENSE.md"
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Respect\Validation\Exceptions;
|
||||
|
||||
use IteratorAggregate;
|
||||
|
||||
interface NestedValidationExceptionInterface extends IteratorAggregate, ValidationExceptionInterface
|
||||
{
|
||||
public function findMessages(array $paths);
|
||||
public function getMessages();
|
||||
public function getFullMessage();
|
||||
}
|
|
@ -1,7 +1,7 @@
|
|||
--FILE--
|
||||
<?php
|
||||
require 'vendor/autoload.php';
|
||||
use Respect\Validation\Exceptions\NestedValidationExceptionInterface;
|
||||
use Respect\Validation\Exceptions\NestedValidationException;
|
||||
use Respect\Validation\Validator as v;
|
||||
|
||||
try {
|
||||
|
@ -35,7 +35,7 @@ try {
|
|||
'password' => 42,
|
||||
],
|
||||
]);
|
||||
} catch (NestedValidationExceptionInterface $exception) {
|
||||
} catch (NestedValidationException $exception) {
|
||||
echo $exception->getFullMessage().PHP_EOL;
|
||||
}
|
||||
?>
|
||||
|
|
|
@ -4,14 +4,14 @@ Do not rely on nested validation exception interface for check
|
|||
<?php
|
||||
require 'vendor/autoload.php';
|
||||
|
||||
use Respect\Validation\Exceptions\NestedValidationExceptionInterface;
|
||||
use Respect\Validation\Exceptions\NestedValidationException;
|
||||
use Respect\Validation\Exceptions\ValidationExceptionInterface;
|
||||
use Respect\Validation\Validator;
|
||||
|
||||
$usernameValidator = Validator::alnum('_')->length(1, 15)->noWhitespace();
|
||||
try {
|
||||
$usernameValidator->check('really messed up screen#name');
|
||||
} catch (NestedValidationExceptionInterface $e) {
|
||||
} catch (NestedValidationException $e) {
|
||||
echo 'Check used NestedValidationException';
|
||||
} catch (ValidationExceptionInterface $e) {
|
||||
echo $e->getMessage();
|
||||
|
|
|
@ -4,7 +4,7 @@ findMessages() should apply templates to flattened messages
|
|||
<?php
|
||||
require 'vendor/autoload.php';
|
||||
|
||||
use Respect\Validation\Exceptions\NestedValidationExceptionInterface;
|
||||
use Respect\Validation\Exceptions\NestedValidationException;
|
||||
use Respect\Validation\Validator as v;
|
||||
|
||||
$stringMax256 = v::stringType()->length(5, 256);
|
||||
|
@ -33,7 +33,7 @@ try {
|
|||
'security_question' => null,
|
||||
]
|
||||
);
|
||||
} catch (NestedValidationExceptionInterface $e) {
|
||||
} catch (NestedValidationException $e) {
|
||||
$messages = $e->findMessages(
|
||||
[
|
||||
'allOf' => 'Invalid {{name}}',
|
||||
|
|
|
@ -4,7 +4,7 @@ findMessages() should return composite validation messages flattened
|
|||
<?php
|
||||
require 'vendor/autoload.php';
|
||||
|
||||
use Respect\Validation\Exceptions\NestedValidationExceptionInterface;
|
||||
use Respect\Validation\Exceptions\NestedValidationException;
|
||||
use Respect\Validation\Validator as v;
|
||||
|
||||
$stringMax256 = v::stringType()->length(5, 256);
|
||||
|
@ -33,7 +33,7 @@ try {
|
|||
'security_question' => null,
|
||||
]
|
||||
);
|
||||
} catch (NestedValidationExceptionInterface $e) {
|
||||
} catch (NestedValidationException $e) {
|
||||
print_r($e->findMessages(['allOf', 'first_name.length']));
|
||||
}
|
||||
?>
|
||||
|
|
|
@ -4,12 +4,12 @@ getFullMessage() should include all validation messages in a chain
|
|||
<?php
|
||||
require 'vendor/autoload.php';
|
||||
|
||||
use Respect\Validation\Exceptions\NestedValidationExceptionInterface;
|
||||
use Respect\Validation\Exceptions\NestedValidationException;
|
||||
use Respect\Validation\Validator;
|
||||
|
||||
try {
|
||||
Validator::stringType()->length(2, 15)->assert(0);
|
||||
} catch (NestedValidationExceptionInterface $e) {
|
||||
} catch (NestedValidationException $e) {
|
||||
echo $e->getFullMessage();
|
||||
}
|
||||
?>
|
||||
|
|
|
@ -7,7 +7,7 @@ date_default_timezone_set('UTC');
|
|||
|
||||
require 'vendor/autoload.php';
|
||||
|
||||
use Respect\Validation\Exceptions\NestedValidationExceptionInterface;
|
||||
use Respect\Validation\Exceptions\NestedValidationException;
|
||||
use Respect\Validation\Validator;
|
||||
|
||||
try {
|
||||
|
@ -22,7 +22,7 @@ try {
|
|||
->key('password', Validator::notEmpty())
|
||||
->key('email', Validator::email())
|
||||
->assert($input);
|
||||
} catch (NestedValidationExceptionInterface $e) {
|
||||
} catch (NestedValidationException $e) {
|
||||
print_r($e->getMessages());
|
||||
}
|
||||
?>
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
require 'vendor/autoload.php';
|
||||
|
||||
use Respect\Validation\Exceptions\NestedValidationExceptionInterface;
|
||||
use Respect\Validation\Exceptions\NestedValidationException;
|
||||
use Respect\Validation\Validator as v;
|
||||
|
||||
$arr = [
|
||||
|
@ -16,7 +16,7 @@ try {
|
|||
->key('name', v::length(2, 32))
|
||||
->key('email', v::email())
|
||||
->assert($arr);
|
||||
} catch (NestedValidationExceptionInterface $e) {
|
||||
} catch (NestedValidationException $e) {
|
||||
print_r($e->getMessages());
|
||||
}
|
||||
?>
|
||||
|
|
|
@ -4,13 +4,13 @@ Issue #85: findMessages() should not trigger catchable fatal error
|
|||
<?php
|
||||
require 'vendor/autoload.php';
|
||||
|
||||
use Respect\Validation\Exceptions\NestedValidationExceptionInterface;
|
||||
use Respect\Validation\Exceptions\NestedValidationException;
|
||||
use Respect\Validation\Validator;
|
||||
|
||||
$usernameValidator = Validator::alnum('_')->length(1, 15)->noWhitespace();
|
||||
try {
|
||||
$usernameValidator->assert('really messed up screen#name');
|
||||
} catch (NestedValidationExceptionInterface $e) {
|
||||
} catch (NestedValidationException $e) {
|
||||
print_r($e->findMessages(['alnum', 'length', 'noWhitespace']));
|
||||
}
|
||||
?>
|
||||
|
|
|
@ -7,7 +7,7 @@ date_default_timezone_set('UTC');
|
|||
|
||||
require 'vendor/autoload.php';
|
||||
|
||||
use Respect\Validation\Exceptions\NestedValidationExceptionInterface;
|
||||
use Respect\Validation\Exceptions\NestedValidationException;
|
||||
use Respect\Validation\Validator;
|
||||
|
||||
try {
|
||||
|
@ -15,7 +15,7 @@ try {
|
|||
->key('birthdate', Validator::date())
|
||||
->setName('User Subscription Form')
|
||||
->assert(['username' => '0', 'birthdate' => 'Whatever']);
|
||||
} catch (NestedValidationExceptionInterface $e) {
|
||||
} catch (NestedValidationException $e) {
|
||||
echo $e->getFullMessage();
|
||||
}
|
||||
?>
|
||||
|
|
|
@ -4,7 +4,7 @@ not() with recursion should update mode from related rules
|
|||
<?php
|
||||
require 'vendor/autoload.php';
|
||||
|
||||
use Respect\Validation\Exceptions\NestedValidationExceptionInterface;
|
||||
use Respect\Validation\Exceptions\NestedValidationException;
|
||||
use Respect\Validation\Validator;
|
||||
|
||||
try {
|
||||
|
@ -20,7 +20,7 @@ try {
|
|||
)
|
||||
);
|
||||
$validator->check(2);
|
||||
} catch (NestedValidationExceptionInterface $exception) {
|
||||
} catch (NestedValidationException $exception) {
|
||||
echo $exception->getFullMessage().PHP_EOL;
|
||||
}
|
||||
?>
|
||||
|
|
|
@ -3,12 +3,12 @@
|
|||
require 'vendor/autoload.php';
|
||||
|
||||
use Respect\Validation\Validator as v;
|
||||
use Respect\Validation\Exceptions\NestedValidationExceptionInterface;
|
||||
use Respect\Validation\Exceptions\NestedValidationException;
|
||||
|
||||
$usernameValidator = v::alnum()->noWhitespace()->length(1, 15);
|
||||
try {
|
||||
$usernameValidator->assert('really messed up screen#name');
|
||||
} catch(NestedValidationExceptionInterface $exception) {
|
||||
} catch(NestedValidationException $exception) {
|
||||
echo $exception->getFullMessage();
|
||||
}
|
||||
?>
|
||||
|
|
|
@ -3,12 +3,12 @@
|
|||
require 'vendor/autoload.php';
|
||||
|
||||
use Respect\Validation\Validator as v;
|
||||
use Respect\Validation\Exceptions\NestedValidationExceptionInterface;
|
||||
use Respect\Validation\Exceptions\NestedValidationException;
|
||||
|
||||
$usernameValidator = v::alnum()->noWhitespace()->length(1, 15);
|
||||
try {
|
||||
$usernameValidator->assert('really messed up screen#name');
|
||||
} catch(NestedValidationExceptionInterface $exception) {
|
||||
} catch(NestedValidationException $exception) {
|
||||
print_r($exception->findMessages(['alnum', 'noWhitespace']));
|
||||
}
|
||||
?>
|
||||
|
|
|
@ -3,12 +3,12 @@
|
|||
require 'vendor/autoload.php';
|
||||
|
||||
use Respect\Validation\Validator as v;
|
||||
use Respect\Validation\Exceptions\NestedValidationExceptionInterface;
|
||||
use Respect\Validation\Exceptions\NestedValidationException;
|
||||
|
||||
$usernameValidator = v::alnum()->noWhitespace()->length(1, 15);
|
||||
try {
|
||||
$usernameValidator->assert('really messed up screen#name');
|
||||
} catch(NestedValidationExceptionInterface $exception) {
|
||||
} catch(NestedValidationException $exception) {
|
||||
print_r($exception->getMessages());
|
||||
}
|
||||
?>
|
||||
|
|
|
@ -4,12 +4,12 @@ setTemplate() with multiple validators should use template as full message
|
|||
<?php
|
||||
require 'vendor/autoload.php';
|
||||
|
||||
use Respect\Validation\Exceptions\NestedValidationExceptionInterface;
|
||||
use Respect\Validation\Exceptions\NestedValidationException;
|
||||
use Respect\Validation\Validator;
|
||||
|
||||
try {
|
||||
Validator::callback('is_string')->between(1, 2)->setTemplate('{{name}} is not tasty')->assert('something');
|
||||
} catch (NestedValidationExceptionInterface $e) {
|
||||
} catch (NestedValidationException $e) {
|
||||
echo $e->getFullMessage();
|
||||
}
|
||||
?>
|
||||
|
|
|
@ -4,12 +4,12 @@ setTemplate() with multiple validators should use template as main message
|
|||
<?php
|
||||
require 'vendor/autoload.php';
|
||||
|
||||
use Respect\Validation\Exceptions\NestedValidationExceptionInterface;
|
||||
use Respect\Validation\Exceptions\NestedValidationException;
|
||||
use Respect\Validation\Validator;
|
||||
|
||||
try {
|
||||
Validator::callback('is_int')->between(1, 2)->setTemplate('{{name}} is not tasty')->assert('something');
|
||||
} catch (NestedValidationExceptionInterface $e) {
|
||||
} catch (NestedValidationException $e) {
|
||||
echo $e->getMainMessage();
|
||||
}
|
||||
?>
|
||||
|
|
|
@ -4,13 +4,13 @@ setTemplate() with single validator should use template as main message
|
|||
<?php
|
||||
require 'vendor/autoload.php';
|
||||
|
||||
use Respect\Validation\Exceptions\NestedValidationExceptionInterface;
|
||||
use Respect\Validation\Exceptions\NestedValidationException;
|
||||
use Respect\Validation\Rules\Callback;
|
||||
use Respect\Validation\Validator;
|
||||
|
||||
try {
|
||||
Validator::callback('is_int')->setTemplate('{{name}} is not tasty')->assert('something');
|
||||
} catch (NestedValidationExceptionInterface $e) {
|
||||
} catch (NestedValidationException $e) {
|
||||
echo $e->getMainMessage();
|
||||
}
|
||||
?>
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
<?php
|
||||
require 'vendor/autoload.php';
|
||||
|
||||
use Respect\Validation\Exceptions\NestedValidationExceptionInterface;
|
||||
use Respect\Validation\Exceptions\NestedValidationException;
|
||||
use Respect\Validation\Validator;
|
||||
|
||||
function translatorCallback($message)
|
||||
|
@ -18,7 +18,7 @@ function translatorCallback($message)
|
|||
|
||||
try {
|
||||
Validator::stringType()->length(2, 15)->assert(0);
|
||||
} catch (NestedValidationExceptionInterface $exception) {
|
||||
} catch (NestedValidationException $exception) {
|
||||
$exception->setParam('translator', 'translatorCallback');
|
||||
|
||||
echo $exception->getFullMessage();
|
||||
|
|
|
@ -21,13 +21,6 @@ class PrivateNestedValidationException extends NestedValidationException
|
|||
|
||||
class NestedValidationExceptionTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testItImplementsNestedValidationExceptionInterface()
|
||||
{
|
||||
$abstractNestedException = new PrivateNestedValidationException();
|
||||
$this->assertInstanceOf('Respect\Validation\Exceptions\NestedValidationExceptionInterface',
|
||||
$abstractNestedException);
|
||||
}
|
||||
|
||||
public function testGetRelatedShouldReturnExceptionAddedByAddRelated()
|
||||
{
|
||||
$composite = new AttributeException();
|
||||
|
|
|
@ -25,13 +25,6 @@ class ValidationExceptionTest extends \PHPUnit_Framework_TestCase
|
|||
$this->assertInstanceOf('Respect\Validation\Exceptions\ValidationExceptionInterface', $validationException);
|
||||
}
|
||||
|
||||
public function testItDoesNotImplementNestedValidationExceptionInterface()
|
||||
{
|
||||
$validationException = new ValidationException();
|
||||
$this->assertNotInstanceOf('Respect\Validation\Exceptions\NestedValidationExceptionInterface',
|
||||
$validationException);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider providerForFormat
|
||||
*/
|
||||
|
|
Loading…
Reference in a new issue