1111
1212namespace Symfony \Component \PropertyAccess \Tests ;
1313
14+ use PHPUnit \Framework \Attributes \DataProvider ;
15+ use PHPUnit \Framework \Attributes \RequiresPhp ;
1416use PHPUnit \Framework \TestCase ;
1517use Symfony \Component \Cache \Adapter \ArrayAdapter ;
1618use Symfony \Component \PropertyAccess \Exception \InvalidArgumentException ;
@@ -83,44 +85,34 @@ public static function getPathsWithMissingIndex()
8385 ];
8486 }
8587
86- /**
87- * @dataProvider getValidReadPropertyPaths
88- */
88+ #[DataProvider('getValidReadPropertyPaths ' )]
8989 public function testGetValue (array |object $ objectOrArray , string $ path , ?string $ value )
9090 {
9191 $ this ->assertSame ($ value , $ this ->propertyAccessor ->getValue ($ objectOrArray , $ path ));
9292 }
9393
94- /**
95- * @dataProvider getPathsWithMissingProperty
96- */
94+ #[DataProvider('getPathsWithMissingProperty ' )]
9795 public function testGetValueThrowsExceptionIfPropertyNotFound (array |object $ objectOrArray , string $ path )
9896 {
9997 $ this ->expectException (NoSuchPropertyException::class);
10098 $ this ->propertyAccessor ->getValue ($ objectOrArray , $ path );
10199 }
102100
103- /**
104- * @dataProvider getPathsWithMissingProperty
105- */
101+ #[DataProvider('getPathsWithMissingProperty ' )]
106102 public function testGetValueReturnsNullIfPropertyNotFoundAndExceptionIsDisabled (array |object $ objectOrArray , string $ path )
107103 {
108104 $ this ->propertyAccessor = new PropertyAccessor (PropertyAccessor::MAGIC_GET | PropertyAccessor::MAGIC_SET , PropertyAccessor::DO_NOT_THROW );
109105
110106 $ this ->assertNull ($ this ->propertyAccessor ->getValue ($ objectOrArray , $ path ), $ path );
111107 }
112108
113- /**
114- * @dataProvider getPathsWithMissingIndex
115- */
109+ #[DataProvider('getPathsWithMissingIndex ' )]
116110 public function testGetValueThrowsNoExceptionIfIndexNotFound (array |object $ objectOrArray , string $ path )
117111 {
118112 $ this ->assertNull ($ this ->propertyAccessor ->getValue ($ objectOrArray , $ path ));
119113 }
120114
121- /**
122- * @dataProvider getPathsWithMissingIndex
123- */
115+ #[DataProvider('getPathsWithMissingIndex ' )]
124116 public function testGetValueThrowsExceptionIfIndexNotFoundAndIndexExceptionsEnabled (array |object $ objectOrArray , string $ path )
125117 {
126118 $ this ->propertyAccessor = new PropertyAccessor (PropertyAccessor::DISALLOW_MAGIC_METHODS , PropertyAccessor::THROW_ON_INVALID_INDEX | PropertyAccessor::THROW_ON_INVALID_PROPERTY_PATH );
@@ -315,38 +307,30 @@ public function testGetValueReadsMagicCallThatReturnsConstant()
315307 $ this ->assertSame ('constant value ' , $ this ->propertyAccessor ->getValue (new TestClassMagicCall ('Bernhard ' ), 'constantMagicCallProperty ' ));
316308 }
317309
318- /**
319- * @dataProvider getValidWritePropertyPaths
320- */
310+ #[DataProvider('getValidWritePropertyPaths ' )]
321311 public function testSetValue (array |object $ objectOrArray , string $ path )
322312 {
323313 $ this ->propertyAccessor ->setValue ($ objectOrArray , $ path , 'Updated ' );
324314
325315 $ this ->assertSame ('Updated ' , $ this ->propertyAccessor ->getValue ($ objectOrArray , $ path ));
326316 }
327317
328- /**
329- * @dataProvider getPathsWithMissingProperty
330- */
318+ #[DataProvider('getPathsWithMissingProperty ' )]
331319 public function testSetValueThrowsExceptionIfPropertyNotFound (array |object $ objectOrArray , string $ path )
332320 {
333321 $ this ->expectException (NoSuchPropertyException::class);
334322 $ this ->propertyAccessor ->setValue ($ objectOrArray , $ path , 'Updated ' );
335323 }
336324
337- /**
338- * @dataProvider getPathsWithMissingIndex
339- */
325+ #[DataProvider('getPathsWithMissingIndex ' )]
340326 public function testSetValueThrowsNoExceptionIfIndexNotFound (array |object $ objectOrArray , string $ path )
341327 {
342328 $ this ->propertyAccessor ->setValue ($ objectOrArray , $ path , 'Updated ' );
343329
344330 $ this ->assertSame ('Updated ' , $ this ->propertyAccessor ->getValue ($ objectOrArray , $ path ));
345331 }
346332
347- /**
348- * @dataProvider getPathsWithMissingIndex
349- */
333+ #[DataProvider('getPathsWithMissingIndex ' )]
350334 public function testSetValueThrowsNoExceptionIfIndexNotFoundAndIndexExceptionsEnabled (array |object $ objectOrArray , string $ path )
351335 {
352336 $ this ->propertyAccessor = new PropertyAccessor (PropertyAccessor::DISALLOW_MAGIC_METHODS , PropertyAccessor::THROW_ON_INVALID_INDEX | PropertyAccessor::THROW_ON_INVALID_PROPERTY_PATH );
@@ -419,34 +403,26 @@ public function testGetValueWhenArrayValueIsNull()
419403 $ this ->assertNull ($ this ->propertyAccessor ->getValue (['index ' => ['nullable ' => null ]], '[index][nullable] ' ));
420404 }
421405
422- /**
423- * @dataProvider getValidReadPropertyPaths
424- */
406+ #[DataProvider('getValidReadPropertyPaths ' )]
425407 public function testIsReadable (array |object $ objectOrArray , string $ path )
426408 {
427409 $ this ->assertTrue ($ this ->propertyAccessor ->isReadable ($ objectOrArray , $ path ));
428410 }
429411
430- /**
431- * @dataProvider getPathsWithMissingProperty
432- */
412+ #[DataProvider('getPathsWithMissingProperty ' )]
433413 public function testIsReadableReturnsFalseIfPropertyNotFound (array |object $ objectOrArray , string $ path )
434414 {
435415 $ this ->assertFalse ($ this ->propertyAccessor ->isReadable ($ objectOrArray , $ path ));
436416 }
437417
438- /**
439- * @dataProvider getPathsWithMissingIndex
440- */
418+ #[DataProvider('getPathsWithMissingIndex ' )]
441419 public function testIsReadableReturnsTrueIfIndexNotFound (array |object $ objectOrArray , string $ path )
442420 {
443421 // Non-existing indices can be read. In this case, null is returned
444422 $ this ->assertTrue ($ this ->propertyAccessor ->isReadable ($ objectOrArray , $ path ));
445423 }
446424
447- /**
448- * @dataProvider getPathsWithMissingIndex
449- */
425+ #[DataProvider('getPathsWithMissingIndex ' )]
450426 public function testIsReadableReturnsFalseIfIndexNotFoundAndIndexExceptionsEnabled (array |object $ objectOrArray , string $ path )
451427 {
452428 $ this ->propertyAccessor = new PropertyAccessor (PropertyAccessor::DISALLOW_MAGIC_METHODS , PropertyAccessor::THROW_ON_INVALID_INDEX | PropertyAccessor::THROW_ON_INVALID_PROPERTY_PATH );
@@ -472,34 +448,26 @@ public function testIsReadableRecognizesMagicCallIfEnabled()
472448 $ this ->assertTrue ($ this ->propertyAccessor ->isReadable (new TestClassMagicCall ('Bernhard ' ), 'magicCallProperty ' ));
473449 }
474450
475- /**
476- * @dataProvider getValidWritePropertyPaths
477- */
451+ #[DataProvider('getValidWritePropertyPaths ' )]
478452 public function testIsWritable (array |object $ objectOrArray , string $ path )
479453 {
480454 $ this ->assertTrue ($ this ->propertyAccessor ->isWritable ($ objectOrArray , $ path ));
481455 }
482456
483- /**
484- * @dataProvider getPathsWithMissingProperty
485- */
457+ #[DataProvider('getPathsWithMissingProperty ' )]
486458 public function testIsWritableReturnsFalseIfPropertyNotFound (array |object $ objectOrArray , string $ path )
487459 {
488460 $ this ->assertFalse ($ this ->propertyAccessor ->isWritable ($ objectOrArray , $ path ));
489461 }
490462
491- /**
492- * @dataProvider getPathsWithMissingIndex
493- */
463+ #[DataProvider('getPathsWithMissingIndex ' )]
494464 public function testIsWritableReturnsTrueIfIndexNotFound (array |object $ objectOrArray , string $ path )
495465 {
496466 // Non-existing indices can be written. Arrays are created on-demand.
497467 $ this ->assertTrue ($ this ->propertyAccessor ->isWritable ($ objectOrArray , $ path ));
498468 }
499469
500- /**
501- * @dataProvider getPathsWithMissingIndex
502- */
470+ #[DataProvider('getPathsWithMissingIndex ' )]
503471 public function testIsWritableReturnsTrueIfIndexNotFoundAndIndexExceptionsEnabled (array |object $ objectOrArray , string $ path )
504472 {
505473 $ this ->propertyAccessor = new PropertyAccessor (PropertyAccessor::DISALLOW_MAGIC_METHODS , PropertyAccessor::THROW_ON_INVALID_INDEX | PropertyAccessor::THROW_ON_INVALID_PROPERTY_PATH );
@@ -596,9 +564,7 @@ public static function getNullSafeIndexPaths(): iterable
596564 yield [['foo ' => ['firstName ' => 'Bernhard ' ]], '[foo][bar?][baz?] ' , null ];
597565 }
598566
599- /**
600- * @dataProvider getNullSafeIndexPaths
601- */
567+ #[DataProvider('getNullSafeIndexPaths ' )]
602568 public function testNullSafeIndexWithThrowOnInvalidIndex (array |object $ objectOrArray , string $ path , ?string $ value )
603569 {
604570 $ this ->propertyAccessor = new PropertyAccessor (PropertyAccessor::DISALLOW_MAGIC_METHODS , PropertyAccessor::THROW_ON_INVALID_INDEX | PropertyAccessor::THROW_ON_INVALID_PROPERTY_PATH );
@@ -634,9 +600,7 @@ public static function getReferenceChainObjectsForSetValue()
634600 ];
635601 }
636602
637- /**
638- * @dataProvider getReferenceChainObjectsForSetValue
639- */
603+ #[DataProvider('getReferenceChainObjectsForSetValue ' )]
640604 public function testSetValueForReferenceChainIssue ($ object , $ path , $ value )
641605 {
642606 $ this ->propertyAccessor ->setValue ($ object , $ path , $ value );
@@ -653,9 +617,7 @@ public static function getReferenceChainObjectsForIsWritable()
653617 ];
654618 }
655619
656- /**
657- * @dataProvider getReferenceChainObjectsForIsWritable
658- */
620+ #[DataProvider('getReferenceChainObjectsForIsWritable ' )]
659621 public function testIsWritableForReferenceChainIssue ($ object , $ path , $ value )
660622 {
661623 $ this ->assertEquals ($ value , $ this ->propertyAccessor ->isWritable ($ object , $ path ));
@@ -1052,9 +1014,7 @@ private function createUninitializedObjectPropertyGhost(): UninitializedObjectPr
10521014 return (new \ReflectionClass (UninitializedObjectProperty::class))->newLazyGhost (fn () => null );
10531015 }
10541016
1055- /**
1056- * @requires PHP 8.4
1057- */
1017+ #[RequiresPhp('8.4 ' )]
10581018 public function testIsWritableWithAsymmetricVisibility ()
10591019 {
10601020 $ object = new AsymmetricVisibility ();
@@ -1066,9 +1026,7 @@ public function testIsWritableWithAsymmetricVisibility()
10661026 $ this ->assertFalse ($ this ->propertyAccessor ->isWritable ($ object , 'virtualNoSetHook ' ));
10671027 }
10681028
1069- /**
1070- * @requires PHP 8.4
1071- */
1029+ #[RequiresPhp('8.4 ' )]
10721030 public function testIsReadableWithAsymmetricVisibility ()
10731031 {
10741032 $ object = new AsymmetricVisibility ();
@@ -1080,11 +1038,8 @@ public function testIsReadableWithAsymmetricVisibility()
10801038 $ this ->assertTrue ($ this ->propertyAccessor ->isReadable ($ object , 'virtualNoSetHook ' ));
10811039 }
10821040
1083- /**
1084- * @requires PHP 8.4
1085- *
1086- * @dataProvider setValueWithAsymmetricVisibilityDataProvider
1087- */
1041+ #[RequiresPhp('8.4 ' )]
1042+ #[DataProvider('setValueWithAsymmetricVisibilityDataProvider ' )]
10881043 public function testSetValueWithAsymmetricVisibility (string $ propertyPath , ?string $ expectedException )
10891044 {
10901045 $ object = new AsymmetricVisibility ();
0 commit comments