Skip to content

Commit

Permalink
Remove "ValidationExceptionInterface"
Browse files Browse the repository at this point in the history
  • Loading branch information
henriquemoody committed Oct 23, 2015
1 parent 67e072e commit 474afaa
Show file tree
Hide file tree
Showing 9 changed files with 25 additions and 35 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ All notable changes of the Respect\Validation releases are documented in this fi
- Remove `addOr()` shortcut (#444)
- Remove `NestedValidationExceptionInterface` interface (#591)
- Remove `not()` shortcut (#444)
- Remove `ValidationExceptionInterface` interface (#591)
- Remove identical checking from "Equals" rule (#442)
- Removed Deprecated Rules (#277)
- Validation rules do not accept an empty string by default (#422)
Expand Down
20 changes: 13 additions & 7 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,17 @@ $usernameValidator->validate('#$%'); //false

* `Repect\Validation\Exceptions\ExceptionInterface`:
* All exceptions implement this interface;
* `Respect\Validation\Exceptions\ValidationExceptionInterface`:
* Extends the `Repect\Validation\Exceptions\ExceptionInterface` interface
* Use when calling `check()`
* All validation exceptions implement this interface
* Interface has one method: `getMainMessage()`
* `Respect\Validation\Exceptions\ValidationException`:
* Implements the `Repect\Validation\Exceptions\ExceptionInterface` interface
* Thrown when the `check()` fails
* All validation exceptions extend this class
* Available methods:
* `getMainMessage()`;
* `setMode($mode)`;
* `setName($name)`;
* `setParam($name, $value)`;
* `setTemplate($template)`;
* more...
* `Respect\Validation\Exceptions\NestedValidationException`:
* Extends the `Respect\Validation\Exceptions\ValidationException` class
* Usually thrown when the `assert()` fails
Expand Down Expand Up @@ -279,11 +285,11 @@ validation report. There is also a `check()` method that returns an Exception
only with the first error found:

```php
use Respect\Validation\Exceptions\ValidationExceptionInterface;
use Respect\Validation\Exceptions\ValidationException;

try {
$usernameValidator->check('really messed up screen#name');
} catch(ValidationExceptionInterface $exception) {
} catch(ValidationException $exception) {
echo $exception->getMainMessage();
}
```
Expand Down
2 changes: 1 addition & 1 deletion library/Exceptions/ValidationException.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
use InvalidArgumentException;
use Traversable;

class ValidationException extends InvalidArgumentException implements ValidationExceptionInterface
class ValidationException extends InvalidArgumentException implements ExceptionInterface
{
const MODE_DEFAULT = 1;
const MODE_NEGATIVE = 2;
Expand Down
17 changes: 0 additions & 17 deletions library/Exceptions/ValidationExceptionInterface.php

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ Do not rely on nested validation exception interface for check
require 'vendor/autoload.php';

use Respect\Validation\Exceptions\NestedValidationException;
use Respect\Validation\Exceptions\ValidationExceptionInterface;
use Respect\Validation\Exceptions\ValidationException;
use Respect\Validation\Validator;

$usernameValidator = Validator::alnum('_')->length(1, 15)->noWhitespace();
try {
$usernameValidator->check('really messed up screen#name');
} catch (NestedValidationException $e) {
echo 'Check used NestedValidationException';
} catch (ValidationExceptionInterface $e) {
} catch (ValidationException $e) {
echo $e->getMessage();
}
?>
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/not_without_recursion.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ not() with recursion should update mode from related rules
<?php
require 'vendor/autoload.php';

use Respect\Validation\Exceptions\ValidationExceptionInterface;
use Respect\Validation\Exceptions\ValidationException;
use Respect\Validation\Validator;

try {
$validator = Validator::not(
Validator::intVal()->positive()
);
$validator->check(2);
} catch (ValidationExceptionInterface $exception) {
} catch (ValidationException $exception) {
echo $exception->getMainMessage().PHP_EOL;
}
?>
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/translator-check.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<?php
require 'vendor/autoload.php';

use Respect\Validation\Exceptions\ValidationExceptionInterface;
use Respect\Validation\Exceptions\ValidationException;
use Respect\Validation\Validator;

function translatorCallback($message)
Expand All @@ -16,7 +16,7 @@ function translatorCallback($message)

try {
Validator::stringType()->length(2, 15)->check(0);
} catch (ValidationExceptionInterface $exception) {
} catch (ValidationException $exception) {
$exception->setParam('translator', 'translatorCallback');

echo $exception->getMainMessage();
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/Exceptions/CheckExceptionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ class_exists($exceptionClass),
'Every exception should extend an Exception class.'
);
$this->assertInstanceOf(
'Respect\Validation\Exceptions\ValidationExceptionInterface',
'Respect\Validation\Exceptions\ValidationException',
$exceptionObject,
'Every Respect/Validation exception must implement out interface.'
'Every Respect/Validation exception must extend ValidationException.'
);
}
}
4 changes: 2 additions & 2 deletions tests/unit/Exceptions/ValidationExceptionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@

class ValidationExceptionTest extends \PHPUnit_Framework_TestCase
{
public function testItImplementsValidationExceptionInterface()
public function testItImplementsExceptionInterface()
{
$validationException = new ValidationException();
$this->assertInstanceOf('Respect\Validation\Exceptions\ValidationExceptionInterface', $validationException);
$this->assertInstanceOf('Respect\Validation\Exceptions\ExceptionInterface', $validationException);
}

/**
Expand Down

0 comments on commit 474afaa

Please sign in to comment.