Skip to content

Commit 5ce29c3

Browse files
Merge pull request #18 from lowerends/master
Add message property to `VatNumber` constraint to override the default validation message.
2 parents 7d409dc + 81ffee2 commit 5ce29c3

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

src/Validator/Constraints/VatNumber.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,12 @@ class VatNumber extends Constraint
1515

1616
public bool $checkExistence = true;
1717
public bool $violateOnException = false;
18+
19+
#[HasNamedArguments]
20+
public function __construct(?string $message = null, ?array $groups = null, mixed $payload = null)
21+
{
22+
parent::__construct(null, $groups, $payload);
23+
24+
$this->message = $message ?? $this->message;
25+
}
1826
}

tests/Validator/Constraints/VatNumberExceptionValidatorTest.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,8 @@ protected function createValidator(): ConstraintValidatorInterface
2323

2424
public function testViesExceptionValid()
2525
{
26-
$constraint = new VatNumber([
27-
'violateOnException' => false,
28-
]);
26+
$constraint = new VatNumber();
27+
$constraint->violateOnException = false;
2928
$this->validator->validate('IE6388047V', $constraint);
3029
$this->assertNoViolation();
3130
}

0 commit comments

Comments
 (0)