@@ -56,6 +56,58 @@ public function testHydrate(): void
5656 $ this ->assertSame ($ testData , $ this ->testValueStorage );
5757 }
5858
59+ public function testHydrateIsStrictByDefault ()
60+ {
61+
62+ $ testPropertySetter = function (
63+ $ value ,
64+ string $ name
65+ ): void {
66+ $ this ->testValueStorage [$ name ] = $ value ;
67+ };
68+
69+ $ hydratorConfig = new GenericHydratorConfig ([
70+ 'prop1 ' => $ testPropertySetter ,
71+ ]);
72+
73+
74+ $ testData = [
75+ 'unexpected ' => true ,
76+ 'prop1 ' => 'fu ' ,
77+ 'another_unexpected ' => true ,
78+ ];
79+
80+ $ expectedResult = [
81+ 'prop1 ' => 'fu ' ,
82+ ];
83+
84+ $ this ->expectException (\InvalidArgumentException::class);
85+ $ this ->expectExceptionMessage ('Unexpected data: unexpected, another_unexpected ' );
86+
87+ $ this ->subject ->hydrate ($ hydratorConfig , $ this , $ testData , 0 );
88+
89+ $ this ->assertSame ($ expectedResult , $ this ->testValueStorage );
90+ }
91+
92+ public function testHydrateOnNonStrict ()
93+ {
94+ $ hydratorConfig = new GenericHydratorConfig ([
95+ 'prop1 ' => 'strval ' ,
96+ ]);
97+
98+
99+ $ testData = [
100+ 'unexpected ' => true ,
101+ 'prop1 ' => 'fu ' ,
102+ 'another_unexpected ' => true ,
103+ ];
104+
105+ $ this ->expectException (\InvalidArgumentException::class);
106+ $ this ->expectExceptionMessage ('Unexpected data: unexpected, another_unexpected ' );
107+
108+ $ this ->subject ->hydrate ($ hydratorConfig , $ this , $ testData , 0 );
109+ }
110+
59111 public function testExtract (): void
60112 {
61113 $ testPropertyGetter = function (
@@ -73,13 +125,6 @@ public function testExtract(): void
73125
74126 $ randomInt = random_int (0 , PHP_INT_MAX );
75127
76-
77- $ testData = [
78- 'prop1 ' => 'fu ' ,
79- 'prop2 ' => $ randomInt ,
80- 'prop3 ' => null ,
81- ];
82-
83128 $ this ->testValueStorage = [
84129 'prop1 ' => ['fu ' , $ this ],
85130 'prop2 ' => [$ randomInt , $ this ],
0 commit comments