1111
1212namespace Symfony \Component \PropertyAccess \Tests ;
1313
14+ use PHPUnit \Framework \Attributes \DataProvider ;
1415use PHPUnit \Framework \TestCase ;
1516use Symfony \Component \Cache \Adapter \ArrayAdapter ;
1617use Symfony \Component \PropertyAccess \Exception \InvalidArgumentException ;
@@ -82,44 +83,34 @@ public static function getPathsWithMissingIndex()
8283 ];
8384 }
8485
85- /**
86- * @dataProvider getValidReadPropertyPaths
87- */
86+ #[DataProvider('getValidReadPropertyPaths ' )]
8887 public function testGetValue (array |object $ objectOrArray , string $ path , ?string $ value )
8988 {
9089 $ this ->assertSame ($ value , $ this ->propertyAccessor ->getValue ($ objectOrArray , $ path ));
9190 }
9291
93- /**
94- * @dataProvider getPathsWithMissingProperty
95- */
92+ #[DataProvider('getPathsWithMissingProperty ' )]
9693 public function testGetValueThrowsExceptionIfPropertyNotFound (array |object $ objectOrArray , string $ path )
9794 {
9895 $ this ->expectException (NoSuchPropertyException::class);
9996 $ this ->propertyAccessor ->getValue ($ objectOrArray , $ path );
10097 }
10198
102- /**
103- * @dataProvider getPathsWithMissingProperty
104- */
99+ #[DataProvider('getPathsWithMissingProperty ' )]
105100 public function testGetValueReturnsNullIfPropertyNotFoundAndExceptionIsDisabled (array |object $ objectOrArray , string $ path )
106101 {
107102 $ this ->propertyAccessor = new PropertyAccessor (PropertyAccessor::MAGIC_GET | PropertyAccessor::MAGIC_SET , PropertyAccessor::DO_NOT_THROW );
108103
109104 $ this ->assertNull ($ this ->propertyAccessor ->getValue ($ objectOrArray , $ path ), $ path );
110105 }
111106
112- /**
113- * @dataProvider getPathsWithMissingIndex
114- */
107+ #[DataProvider('getPathsWithMissingIndex ' )]
115108 public function testGetValueThrowsNoExceptionIfIndexNotFound (array |object $ objectOrArray , string $ path )
116109 {
117110 $ this ->assertNull ($ this ->propertyAccessor ->getValue ($ objectOrArray , $ path ));
118111 }
119112
120- /**
121- * @dataProvider getPathsWithMissingIndex
122- */
113+ #[DataProvider('getPathsWithMissingIndex ' )]
123114 public function testGetValueThrowsExceptionIfIndexNotFoundAndIndexExceptionsEnabled (array |object $ objectOrArray , string $ path )
124115 {
125116 $ this ->propertyAccessor = new PropertyAccessor (PropertyAccessor::DISALLOW_MAGIC_METHODS , PropertyAccessor::THROW_ON_INVALID_INDEX | PropertyAccessor::THROW_ON_INVALID_PROPERTY_PATH );
@@ -314,38 +305,30 @@ public function testGetValueReadsMagicCallThatReturnsConstant()
314305 $ this ->assertSame ('constant value ' , $ this ->propertyAccessor ->getValue (new TestClassMagicCall ('Bernhard ' ), 'constantMagicCallProperty ' ));
315306 }
316307
317- /**
318- * @dataProvider getValidWritePropertyPaths
319- */
308+ #[DataProvider('getValidWritePropertyPaths ' )]
320309 public function testSetValue (array |object $ objectOrArray , string $ path )
321310 {
322311 $ this ->propertyAccessor ->setValue ($ objectOrArray , $ path , 'Updated ' );
323312
324313 $ this ->assertSame ('Updated ' , $ this ->propertyAccessor ->getValue ($ objectOrArray , $ path ));
325314 }
326315
327- /**
328- * @dataProvider getPathsWithMissingProperty
329- */
316+ #[DataProvider('getPathsWithMissingProperty ' )]
330317 public function testSetValueThrowsExceptionIfPropertyNotFound (array |object $ objectOrArray , string $ path )
331318 {
332319 $ this ->expectException (NoSuchPropertyException::class);
333320 $ this ->propertyAccessor ->setValue ($ objectOrArray , $ path , 'Updated ' );
334321 }
335322
336- /**
337- * @dataProvider getPathsWithMissingIndex
338- */
323+ #[DataProvider('getPathsWithMissingIndex ' )]
339324 public function testSetValueThrowsNoExceptionIfIndexNotFound (array |object $ objectOrArray , string $ path )
340325 {
341326 $ this ->propertyAccessor ->setValue ($ objectOrArray , $ path , 'Updated ' );
342327
343328 $ this ->assertSame ('Updated ' , $ this ->propertyAccessor ->getValue ($ objectOrArray , $ path ));
344329 }
345330
346- /**
347- * @dataProvider getPathsWithMissingIndex
348- */
331+ #[DataProvider('getPathsWithMissingIndex ' )]
349332 public function testSetValueThrowsNoExceptionIfIndexNotFoundAndIndexExceptionsEnabled (array |object $ objectOrArray , string $ path )
350333 {
351334 $ this ->propertyAccessor = new PropertyAccessor (PropertyAccessor::DISALLOW_MAGIC_METHODS , PropertyAccessor::THROW_ON_INVALID_INDEX | PropertyAccessor::THROW_ON_INVALID_PROPERTY_PATH );
@@ -418,34 +401,26 @@ public function testGetValueWhenArrayValueIsNull()
418401 $ this ->assertNull ($ this ->propertyAccessor ->getValue (['index ' => ['nullable ' => null ]], '[index][nullable] ' ));
419402 }
420403
421- /**
422- * @dataProvider getValidReadPropertyPaths
423- */
404+ #[DataProvider('getValidReadPropertyPaths ' )]
424405 public function testIsReadable (array |object $ objectOrArray , string $ path )
425406 {
426407 $ this ->assertTrue ($ this ->propertyAccessor ->isReadable ($ objectOrArray , $ path ));
427408 }
428409
429- /**
430- * @dataProvider getPathsWithMissingProperty
431- */
410+ #[DataProvider('getPathsWithMissingProperty ' )]
432411 public function testIsReadableReturnsFalseIfPropertyNotFound (array |object $ objectOrArray , string $ path )
433412 {
434413 $ this ->assertFalse ($ this ->propertyAccessor ->isReadable ($ objectOrArray , $ path ));
435414 }
436415
437- /**
438- * @dataProvider getPathsWithMissingIndex
439- */
416+ #[DataProvider('getPathsWithMissingIndex ' )]
440417 public function testIsReadableReturnsTrueIfIndexNotFound (array |object $ objectOrArray , string $ path )
441418 {
442419 // Non-existing indices can be read. In this case, null is returned
443420 $ this ->assertTrue ($ this ->propertyAccessor ->isReadable ($ objectOrArray , $ path ));
444421 }
445422
446- /**
447- * @dataProvider getPathsWithMissingIndex
448- */
423+ #[DataProvider('getPathsWithMissingIndex ' )]
449424 public function testIsReadableReturnsFalseIfIndexNotFoundAndIndexExceptionsEnabled (array |object $ objectOrArray , string $ path )
450425 {
451426 $ this ->propertyAccessor = new PropertyAccessor (PropertyAccessor::DISALLOW_MAGIC_METHODS , PropertyAccessor::THROW_ON_INVALID_INDEX | PropertyAccessor::THROW_ON_INVALID_PROPERTY_PATH );
@@ -471,34 +446,26 @@ public function testIsReadableRecognizesMagicCallIfEnabled()
471446 $ this ->assertTrue ($ this ->propertyAccessor ->isReadable (new TestClassMagicCall ('Bernhard ' ), 'magicCallProperty ' ));
472447 }
473448
474- /**
475- * @dataProvider getValidWritePropertyPaths
476- */
449+ #[DataProvider('getValidWritePropertyPaths ' )]
477450 public function testIsWritable (array |object $ objectOrArray , string $ path )
478451 {
479452 $ this ->assertTrue ($ this ->propertyAccessor ->isWritable ($ objectOrArray , $ path ));
480453 }
481454
482- /**
483- * @dataProvider getPathsWithMissingProperty
484- */
455+ #[DataProvider('getPathsWithMissingProperty ' )]
485456 public function testIsWritableReturnsFalseIfPropertyNotFound (array |object $ objectOrArray , string $ path )
486457 {
487458 $ this ->assertFalse ($ this ->propertyAccessor ->isWritable ($ objectOrArray , $ path ));
488459 }
489460
490- /**
491- * @dataProvider getPathsWithMissingIndex
492- */
461+ #[DataProvider('getPathsWithMissingIndex ' )]
493462 public function testIsWritableReturnsTrueIfIndexNotFound (array |object $ objectOrArray , string $ path )
494463 {
495464 // Non-existing indices can be written. Arrays are created on-demand.
496465 $ this ->assertTrue ($ this ->propertyAccessor ->isWritable ($ objectOrArray , $ path ));
497466 }
498467
499- /**
500- * @dataProvider getPathsWithMissingIndex
501- */
468+ #[DataProvider('getPathsWithMissingIndex ' )]
502469 public function testIsWritableReturnsTrueIfIndexNotFoundAndIndexExceptionsEnabled (array |object $ objectOrArray , string $ path )
503470 {
504471 $ this ->propertyAccessor = new PropertyAccessor (PropertyAccessor::DISALLOW_MAGIC_METHODS , PropertyAccessor::THROW_ON_INVALID_INDEX | PropertyAccessor::THROW_ON_INVALID_PROPERTY_PATH );
@@ -595,9 +562,7 @@ public static function getNullSafeIndexPaths(): iterable
595562 yield [['foo ' => ['firstName ' => 'Bernhard ' ]], '[foo][bar?][baz?] ' , null ];
596563 }
597564
598- /**
599- * @dataProvider getNullSafeIndexPaths
600- */
565+ #[DataProvider('getNullSafeIndexPaths ' )]
601566 public function testNullSafeIndexWithThrowOnInvalidIndex (array |object $ objectOrArray , string $ path , ?string $ value )
602567 {
603568 $ this ->propertyAccessor = new PropertyAccessor (PropertyAccessor::DISALLOW_MAGIC_METHODS , PropertyAccessor::THROW_ON_INVALID_INDEX | PropertyAccessor::THROW_ON_INVALID_PROPERTY_PATH );
@@ -633,9 +598,7 @@ public static function getReferenceChainObjectsForSetValue()
633598 ];
634599 }
635600
636- /**
637- * @dataProvider getReferenceChainObjectsForSetValue
638- */
601+ #[DataProvider('getReferenceChainObjectsForSetValue ' )]
639602 public function testSetValueForReferenceChainIssue ($ object , $ path , $ value )
640603 {
641604 $ this ->propertyAccessor ->setValue ($ object , $ path , $ value );
@@ -652,9 +615,7 @@ public static function getReferenceChainObjectsForIsWritable()
652615 ];
653616 }
654617
655- /**
656- * @dataProvider getReferenceChainObjectsForIsWritable
657- */
618+ #[DataProvider('getReferenceChainObjectsForIsWritable ' )]
658619 public function testIsWritableForReferenceChainIssue ($ object , $ path , $ value )
659620 {
660621 $ this ->assertEquals ($ value , $ this ->propertyAccessor ->isWritable ($ object , $ path ));
@@ -1056,9 +1017,7 @@ public function testIsReadableWithAsymmetricVisibility()
10561017 $ this ->assertTrue ($ this ->propertyAccessor ->isReadable ($ object , 'virtualNoSetHook ' ));
10571018 }
10581019
1059- /**
1060- * @dataProvider setValueWithAsymmetricVisibilityDataProvider
1061- */
1020+ #[DataProvider('setValueWithAsymmetricVisibilityDataProvider ' )]
10621021 public function testSetValueWithAsymmetricVisibility (string $ propertyPath , ?string $ expectedException )
10631022 {
10641023 $ object = new AsymmetricVisibility ();
0 commit comments