2222use Sunrise \Hydrator \Dictionary \BuiltinType ;
2323use Sunrise \Hydrator \Dictionary \ContextKey ;
2424use Sunrise \Hydrator \Dictionary \ErrorCode ;
25+ use Sunrise \Hydrator \Dictionary \TranslationDomain ;
2526use Sunrise \Hydrator \Exception \InvalidDataException ;
2627use Sunrise \Hydrator \Exception \InvalidObjectException ;
2728use Sunrise \Hydrator \Hydrator ;
@@ -46,6 +47,7 @@ class HydratorTest extends TestCase
4647 private array $ invalidValueExceptionMessage = [];
4748 private array $ invalidValueExceptionPropertyPath = [];
4849 private array $ invalidValueExceptionErrorCode = [];
50+ private array $ invalidValueExceptionTranslationDomain = [];
4951
5052 public function testIssue25 (): void
5153 {
@@ -180,6 +182,7 @@ public function testHydrateBooleanPropertyWithEmptyValue(array $data): void
180182 $ this ->assertInvalidValueExceptionMessage (0 , 'This value must not be empty. ' );
181183 $ this ->assertInvalidValueExceptionErrorCode (0 , ErrorCode::MUST_NOT_BE_EMPTY );
182184 $ this ->assertInvalidValueExceptionPropertyPath (0 , 'value ' );
185+ $ this ->assertInvalidValueExceptionTranslationDomain (0 , TranslationDomain::HYDRATOR );
183186 $ this ->createHydrator ()->hydrate ($ object , $ data );
184187 }
185188
@@ -197,6 +200,7 @@ public function testHydrateBooleanPropertyWithInvalidValue(array $data): void
197200 $ this ->assertInvalidValueExceptionMessage (0 , 'This value must be of type boolean. ' );
198201 $ this ->assertInvalidValueExceptionErrorCode (0 , ErrorCode::MUST_BE_BOOLEAN );
199202 $ this ->assertInvalidValueExceptionPropertyPath (0 , 'value ' );
203+ $ this ->assertInvalidValueExceptionTranslationDomain (0 , TranslationDomain::HYDRATOR );
200204 $ this ->createHydrator ()->hydrate ($ object , $ data );
201205 }
202206
@@ -213,6 +217,7 @@ public function testHydrateBooleanPropertyWithoutValue(): void
213217 $ this ->assertInvalidValueExceptionMessage (0 , 'This value must be provided. ' );
214218 $ this ->assertInvalidValueExceptionErrorCode (0 , ErrorCode::MUST_BE_PROVIDED );
215219 $ this ->assertInvalidValueExceptionPropertyPath (0 , 'value ' );
220+ $ this ->assertInvalidValueExceptionTranslationDomain (0 , TranslationDomain::HYDRATOR );
216221 $ this ->createHydrator ()->hydrate ($ object , []);
217222 }
218223
@@ -282,6 +287,7 @@ public function testHydrateIntegerPropertyWithEmptyValue(array $data): void
282287 $ this ->assertInvalidValueExceptionMessage (0 , 'This value must not be empty. ' );
283288 $ this ->assertInvalidValueExceptionErrorCode (0 , ErrorCode::MUST_NOT_BE_EMPTY );
284289 $ this ->assertInvalidValueExceptionPropertyPath (0 , 'value ' );
290+ $ this ->assertInvalidValueExceptionTranslationDomain (0 , TranslationDomain::HYDRATOR );
285291 $ this ->createHydrator ()->hydrate ($ object , $ data );
286292 }
287293
@@ -299,6 +305,7 @@ public function testHydrateIntegerPropertyWithInvalidValue(array $data): void
299305 $ this ->assertInvalidValueExceptionMessage (0 , 'This value must be of type integer. ' );
300306 $ this ->assertInvalidValueExceptionErrorCode (0 , ErrorCode::MUST_BE_INTEGER );
301307 $ this ->assertInvalidValueExceptionPropertyPath (0 , 'value ' );
308+ $ this ->assertInvalidValueExceptionTranslationDomain (0 , TranslationDomain::HYDRATOR );
302309 $ this ->createHydrator ()->hydrate ($ object , $ data );
303310 }
304311
@@ -315,6 +322,7 @@ public function testHydrateIntegerPropertyWithoutValue(): void
315322 $ this ->assertInvalidValueExceptionMessage (0 , 'This value must be provided. ' );
316323 $ this ->assertInvalidValueExceptionErrorCode (0 , ErrorCode::MUST_BE_PROVIDED );
317324 $ this ->assertInvalidValueExceptionPropertyPath (0 , 'value ' );
325+ $ this ->assertInvalidValueExceptionTranslationDomain (0 , TranslationDomain::HYDRATOR );
318326 $ this ->createHydrator ()->hydrate ($ object , []);
319327 }
320328
@@ -384,6 +392,7 @@ public function testHydrateNumericPropertyWithEmptyValue(array $data): void
384392 $ this ->assertInvalidValueExceptionMessage (0 , 'This value must not be empty. ' );
385393 $ this ->assertInvalidValueExceptionErrorCode (0 , ErrorCode::MUST_NOT_BE_EMPTY );
386394 $ this ->assertInvalidValueExceptionPropertyPath (0 , 'value ' );
395+ $ this ->assertInvalidValueExceptionTranslationDomain (0 , TranslationDomain::HYDRATOR );
387396 $ this ->createHydrator ()->hydrate ($ object , $ data );
388397 }
389398
@@ -401,6 +410,7 @@ public function testHydrateNumericPropertyWithInvalidValue(array $data): void
401410 $ this ->assertInvalidValueExceptionMessage (0 , 'This value must be of type number. ' );
402411 $ this ->assertInvalidValueExceptionErrorCode (0 , ErrorCode::MUST_BE_NUMBER );
403412 $ this ->assertInvalidValueExceptionPropertyPath (0 , 'value ' );
413+ $ this ->assertInvalidValueExceptionTranslationDomain (0 , TranslationDomain::HYDRATOR );
404414 $ this ->createHydrator ()->hydrate ($ object , $ data );
405415 }
406416
@@ -417,6 +427,7 @@ public function testHydrateNumericPropertyWithoutValue(): void
417427 $ this ->assertInvalidValueExceptionMessage (0 , 'This value must be provided. ' );
418428 $ this ->assertInvalidValueExceptionErrorCode (0 , ErrorCode::MUST_BE_PROVIDED );
419429 $ this ->assertInvalidValueExceptionPropertyPath (0 , 'value ' );
430+ $ this ->assertInvalidValueExceptionTranslationDomain (0 , TranslationDomain::HYDRATOR );
420431 $ this ->createHydrator ()->hydrate ($ object , []);
421432 }
422433
@@ -484,6 +495,7 @@ public function testHydrateStringPropertyWithNull(array $data): void
484495 $ this ->assertInvalidValueExceptionMessage (0 , 'This value must not be empty. ' );
485496 $ this ->assertInvalidValueExceptionErrorCode (0 , ErrorCode::MUST_NOT_BE_EMPTY );
486497 $ this ->assertInvalidValueExceptionPropertyPath (0 , 'value ' );
498+ $ this ->assertInvalidValueExceptionTranslationDomain (0 , TranslationDomain::HYDRATOR );
487499 $ this ->createHydrator ()->hydrate ($ object , $ data );
488500 }
489501
@@ -501,6 +513,7 @@ public function testHydrateStringPropertyWithInvalidValue(array $data): void
501513 $ this ->assertInvalidValueExceptionMessage (0 , 'This value must be of type string. ' );
502514 $ this ->assertInvalidValueExceptionErrorCode (0 , ErrorCode::MUST_BE_STRING );
503515 $ this ->assertInvalidValueExceptionPropertyPath (0 , 'value ' );
516+ $ this ->assertInvalidValueExceptionTranslationDomain (0 , TranslationDomain::HYDRATOR );
504517 $ this ->createHydrator ()->hydrate ($ object , $ data );
505518 }
506519
@@ -517,6 +530,7 @@ public function testHydrateStringPropertyWithoutValue(): void
517530 $ this ->assertInvalidValueExceptionMessage (0 , 'This value must be provided. ' );
518531 $ this ->assertInvalidValueExceptionErrorCode (0 , ErrorCode::MUST_BE_PROVIDED );
519532 $ this ->assertInvalidValueExceptionPropertyPath (0 , 'value ' );
533+ $ this ->assertInvalidValueExceptionTranslationDomain (0 , TranslationDomain::HYDRATOR );
520534 $ this ->createHydrator ()->hydrate ($ object , []);
521535 }
522536
@@ -3180,6 +3194,13 @@ private function assertInvalidValueExceptionErrorCode(int $exceptionIndex, strin
31803194 $ this ->invalidValueExceptionErrorCode [] = [$ exceptionIndex , $ expectedErrorCode ];
31813195 }
31823196
3197+ private function assertInvalidValueExceptionTranslationDomain (
3198+ int $ exceptionIndex ,
3199+ string $ expectedTranslationDomain
3200+ ): void {
3201+ $ this ->invalidValueExceptionTranslationDomain [] = [$ exceptionIndex , $ expectedTranslationDomain ];
3202+ }
3203+
31833204 protected function runTest (): void
31843205 {
31853206 $ invalidDataExceptionHandled = false ;
@@ -3232,6 +3253,18 @@ protected function runTest(): void
32323253 );
32333254 }
32343255
3256+ foreach ($ this ->invalidValueExceptionTranslationDomain as [
3257+ $ index ,
3258+ $ invalidValueExceptionTranslationDomain ,
3259+ ]) {
3260+ $ invalidDataExceptionHandled = true ;
3261+ $ this ->assertArrayHasKey ($ index , $ invalidDataException ->getExceptions ());
3262+ $ this ->assertSame (
3263+ $ invalidValueExceptionTranslationDomain ,
3264+ $ invalidDataException ->getExceptions ()[$ index ]->getTranslationDomain (),
3265+ );
3266+ }
3267+
32353268 if (!$ invalidDataExceptionHandled ) {
32363269 throw $ invalidDataException ;
32373270 }
@@ -3240,6 +3273,7 @@ protected function runTest(): void
32403273 $ this ->invalidValueExceptionMessage = [];
32413274 $ this ->invalidValueExceptionPropertyPath = [];
32423275 $ this ->invalidValueExceptionErrorCode = [];
3276+ $ this ->invalidValueExceptionTranslationDomain = [];
32433277
32443278 if ($ invalidDataExceptionHandled ) {
32453279 $ this ->assertTrue (true );
0 commit comments