17
17
use PHPUnit \Framework \Constraint \IsNull ;
18
18
use PHPUnit \Framework \Constraint \LogicalOr ;
19
19
use PHPUnit \Framework \ExpectationFailedException ;
20
+ use PHPUnit \Framework \MockObject \MockObject ;
20
21
use PHPUnit \Framework \TestCase ;
21
22
use Symfony \Component \Validator \Constraint ;
22
23
use Symfony \Component \Validator \Constraints \GroupSequence ;
@@ -61,6 +62,8 @@ abstract class ConstraintValidatorTestCase extends TestCase
61
62
protected Constraint $ constraint ;
62
63
protected ?string $ defaultTimezone = null ;
63
64
65
+ private TranslatorInterface &MockObject $ translator ;
66
+
64
67
private string $ defaultLocale ;
65
68
private array $ expectedViolations ;
66
69
private int $ call ;
@@ -122,14 +125,14 @@ protected function restoreDefaultTimezone()
122
125
123
126
protected function createContext ()
124
127
{
125
- $ translator = $ this ->createMock (TranslatorInterface::class);
126
- $ translator ->expects ($ this ->any ())->method ('trans ' )->willReturnArgument (0 );
128
+ $ this -> translator = $ this ->createMock (TranslatorInterface::class);
129
+ $ this -> translator ->expects ($ this ->any ())->method ('trans ' )->willReturnArgument (0 );
127
130
$ validator = $ this ->createMock (ValidatorInterface::class);
128
131
$ validator ->expects ($ this ->any ())
129
132
->method ('validate ' )
130
133
->willReturnCallback (fn () => $ this ->expectedViolations [$ this ->call ++] ?? new ConstraintViolationList ());
131
134
132
- $ context = new ExecutionContext ($ validator , $ this ->root , $ translator );
135
+ $ context = new ExecutionContext ($ validator , $ this ->root , $ this -> translator );
133
136
$ context ->setGroup ($ this ->group );
134
137
$ context ->setNode ($ this ->value , $ this ->object , $ this ->metadata , $ this ->propertyPath );
135
138
$ context ->setConstraint ($ this ->constraint );
@@ -277,6 +280,14 @@ protected function expectViolationsAt(int $i, mixed $value, Constraint $constrai
277
280
return $ context ->getViolations ();
278
281
}
279
282
283
+ protected function expectTranslationDomain (string $ translationDomain )
284
+ {
285
+ $ this ->translator
286
+ ->expects ($ this ->atLeastOnce ())
287
+ ->method ('trans ' )
288
+ ->with ($ this ->anything (), $ this ->anything (), $ translationDomain , $ this ->anything ());
289
+ }
290
+
280
291
protected function assertNoViolation ()
281
292
{
282
293
$ this ->assertSame (0 , $ violationsCount = \count ($ this ->context ->getViolations ()), \sprintf ('0 violation expected. Got %u. ' , $ violationsCount ));
@@ -301,6 +312,7 @@ final class ConstraintViolationAssertion
301
312
private ?int $ plural = null ;
302
313
private ?string $ code = null ;
303
314
private mixed $ cause = null ;
315
+ private ?string $ translationDomain = null ;
304
316
305
317
/**
306
318
* @param ConstraintViolationAssertion[] $assertions
0 commit comments