@@ -190,67 +190,119 @@ public function testIsIdentifierFromFieldMapping(): void
190190
191191 public function testGetValue (): void
192192 {
193- $ mockedObject = $ this ->getMockBuilder (\stdClass::class)->addMethods (['getFoo ' ])->getMock ();
194- $ mockedObject ->expects (static ::once ())->method ('getFoo ' )->willReturn ('myMethodValue ' );
193+ $ object = new class {
194+ public function getFoo ()
195+ {
196+ return 'myMethodValue ' ;
197+ }
198+ };
195199
196200 $ field = new FieldDescription ('name ' , ['accessor ' => 'foo ' ]);
197201
198- static ::assertSame ('myMethodValue ' , $ field ->getValue ($ mockedObject ));
202+ static ::assertSame ('myMethodValue ' , $ field ->getValue ($ object ));
199203 }
200204
201205 public function testGetValueWithParentAssociationMappings (): void
202206 {
203- $ mockedSubObject = $ this ->getMockBuilder (\stdClass::class)->addMethods (['getFieldName ' ])->getMock ();
204- $ mockedSubObject ->expects (static ::once ())->method ('getFieldName ' )->willReturn ('value ' );
205-
206- $ mockedObject = $ this ->getMockBuilder (\stdClass::class)->addMethods (['getSubObject ' ])->getMock ();
207- $ mockedObject ->expects (static ::once ())->method ('getSubObject ' )->willReturn ($ mockedSubObject );
207+ $ subObject = new class {
208+ public function getFieldName ()
209+ {
210+ return 'value ' ;
211+ }
212+ };
213+
214+ $ parentObject = new class ($ subObject ) {
215+ public function __construct (private $ subObject )
216+ {
217+ }
218+
219+ public function getSubObject ()
220+ {
221+ return $ this ->subObject ;
222+ }
223+ };
208224
209225 $ field = new FieldDescription ('name ' , [], [], [], [['fieldName ' => 'subObject ' ]], 'fieldName ' );
210226
211- static ::assertSame ('value ' , $ field ->getValue ($ mockedObject ));
227+ static ::assertSame ('value ' , $ field ->getValue ($ parentObject ));
212228 }
213229
214230 public function testGetValueWhenCannotRetrieve (): void
215231 {
216- $ mockedObject = $ this ->getMockBuilder (\stdClass::class)->addMethods (['myMethod ' ])->getMock ();
217- $ mockedObject ->expects (static ::never ())->method ('myMethod ' )->willReturn ('myMethodValue ' );
232+ $ object = new class {
233+ public function myMethod ()
234+ {
235+ return 'myMethodValue ' ;
236+ }
237+ };
218238
219239 $ admin = static ::createStub (AdminInterface::class);
220240 $ field = new FieldDescription ('name ' );
221241 $ field ->setAdmin ($ admin );
222242
223243 $ this ->expectException (NoValueException::class);
224- static ::assertSame ('myMethodValue ' , $ field ->getValue ($ mockedObject ));
244+ static ::assertSame ('myMethodValue ' , $ field ->getValue ($ object ));
225245 }
226246
227247 public function testGetValueForEmbeddedObject (): void
228248 {
229- $ mockedEmbeddedObject = $ this ->getMockBuilder (\stdClass::class)->addMethods (['getMyMethod ' ])->getMock ();
230- $ mockedEmbeddedObject ->expects (static ::once ())->method ('getMyMethod ' )->willReturn ('myMethodValue ' );
231-
232- $ mockedObject = $ this ->getMockBuilder (\stdClass::class)->addMethods (['getMyEmbeddedObject ' ])->getMock ();
233- $ mockedObject ->expects (static ::once ())->method ('getMyEmbeddedObject ' )->willReturn ($ mockedEmbeddedObject );
249+ $ subObject = new class {
250+ public function getMyMethod ()
251+ {
252+ return 'myMethodValue ' ;
253+ }
254+ };
255+
256+ $ parentObject = new class ($ subObject ) {
257+ public function __construct (private $ subObject )
258+ {
259+ }
260+
261+ public function getMyEmbeddedObject ()
262+ {
263+ return $ this ->subObject ;
264+ }
265+ };
234266
235267 $ field = new FieldDescription ('myMethod ' , [], [], [], [], 'myEmbeddedObject.myMethod ' );
236268
237- static ::assertSame ('myMethodValue ' , $ field ->getValue ($ mockedObject ));
269+ static ::assertSame ('myMethodValue ' , $ field ->getValue ($ parentObject ));
238270 }
239271
240272 public function testGetValueForMultiLevelEmbeddedObject (): void
241273 {
242- $ mockedChildEmbeddedObject = $ this ->getMockBuilder (\stdClass::class)->addMethods (['getMyMethod ' ])->getMock ();
243- $ mockedChildEmbeddedObject ->expects (static ::once ())->method ('getMyMethod ' )->willReturn ('myMethodValue ' );
244-
245- $ mockedEmbeddedObject = $ this ->getMockBuilder (\stdClass::class)->addMethods (['getChild ' ])->getMock ();
246- $ mockedEmbeddedObject ->expects (static ::once ())->method ('getChild ' )->willReturn ($ mockedChildEmbeddedObject );
247-
248- $ mockedObject = $ this ->getMockBuilder (\stdClass::class)->addMethods (['getMyEmbeddedObject ' ])->getMock ();
249- $ mockedObject ->expects (static ::once ())->method ('getMyEmbeddedObject ' )->willReturn ($ mockedEmbeddedObject );
274+ $ subSubObject = new class {
275+ public function getMyMethod ()
276+ {
277+ return 'myMethodValue ' ;
278+ }
279+ };
280+
281+ $ subObject = new class ($ subSubObject ) {
282+ public function __construct (private $ subObject )
283+ {
284+ }
285+
286+ public function getChild ()
287+ {
288+ return $ this ->subObject ;
289+ }
290+ };
291+
292+ $ parentObject = new class ($ subObject ) {
293+ public function __construct (private $ subObject )
294+ {
295+ }
296+
297+ public function getMyEmbeddedObject ()
298+ {
299+ return $ this ->subObject ;
300+ }
301+ };
250302
251303 $ field = new FieldDescription ('myMethod ' , [], [], [], [], 'myEmbeddedObject.child.myMethod ' );
252304
253- static ::assertSame ('myMethodValue ' , $ field ->getValue ($ mockedObject ));
305+ static ::assertSame ('myMethodValue ' , $ field ->getValue ($ parentObject ));
254306 }
255307
256308 public function testEnum (): void
0 commit comments