Skip to content

Commit

Permalink
Fix validator 3.4 compatibility problems
Browse files Browse the repository at this point in the history
  • Loading branch information
Sebastian Wróblewski committed Feb 26, 2020
1 parent 4dd8214 commit 6eac233
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 5 deletions.
3 changes: 1 addition & 2 deletions src/Validator/Constraints/NipValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
use Symfony\Component\Validator\Constraint;
use Symfony\Component\Validator\ConstraintValidator;
use Symfony\Component\Validator\Exception\UnexpectedTypeException;
use Symfony\Component\Validator\Exception\UnexpectedValueException;

/**
* @author Sebastian Wróblewski <kontakt@swroblewski.pl>
Expand All @@ -37,7 +36,7 @@ public function validate($value, Constraint $constraint)
}

if (!is_scalar($value) && !(\is_object($value) && method_exists($value, '__toString'))) {
throw new UnexpectedValueException($value, 'string');
throw new UnexpectedTypeException($value, 'string');
}

$value = (string) $value;
Expand Down
5 changes: 2 additions & 3 deletions tests/Validator/Constraints/NipValidatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
use Kreyu\Bundle\NipValidatorBundle\Validator\Constraints\NipValidator;
use Symfony\Component\Validator\Constraint;
use Symfony\Component\Validator\Exception\UnexpectedTypeException;
use Symfony\Component\Validator\Exception\UnexpectedValueException;
use Symfony\Component\Validator\Test\ConstraintValidatorTestCase;

/**
Expand Down Expand Up @@ -371,13 +370,13 @@ public function testInvalidConstraintThrowsException()

public function testInvalidValueTypeThrowsException()
{
$this->expectException(UnexpectedValueException::class);
$this->expectException(UnexpectedTypeException::class);
$this->validator->validate([], new Nip());
}

public function testObjectValueWithoutToStringMethodThrowsException()
{
$this->expectException(UnexpectedValueException::class);
$this->expectException(UnexpectedTypeException::class);
$this->validator->validate(new class {}, new Nip());
}

Expand Down

0 comments on commit 6eac233

Please sign in to comment.