Skip to content

Commit f02b08d

Browse files
Merge branch '7.4' into 8.0
* 7.4: replace PHPUnit annotations with attributes
2 parents 7b96818 + 34dd355 commit f02b08d

File tree

4 files changed

+32
-84
lines changed

4 files changed

+32
-84
lines changed

Tests/PropertyAccessorArrayAccessTestCase.php

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Symfony\Component\PropertyAccess\Tests;
1313

14+
use PHPUnit\Framework\Attributes\DataProvider;
1415
use PHPUnit\Framework\TestCase;
1516
use Symfony\Component\PropertyAccess\Exception\NoSuchIndexException;
1617
use Symfony\Component\PropertyAccess\PropertyAccess;
@@ -43,9 +44,7 @@ public static function getInvalidPropertyPaths(): array
4344
];
4445
}
4546

46-
/**
47-
* @dataProvider getValidPropertyPaths
48-
*/
47+
#[DataProvider('getValidPropertyPaths')]
4948
public function testGetValue($collection, $path, $value)
5049
{
5150
$this->assertSame($value, $this->propertyAccessor->getValue($collection, $path));
@@ -64,35 +63,27 @@ public function testGetValueFailsIfNoSuchIndex()
6463
$this->propertyAccessor->getValue($object, '[lastName]');
6564
}
6665

67-
/**
68-
* @dataProvider getValidPropertyPaths
69-
*/
66+
#[DataProvider('getValidPropertyPaths')]
7067
public function testSetValue($collection, $path)
7168
{
7269
$this->propertyAccessor->setValue($collection, $path, 'Updated');
7370

7471
$this->assertSame('Updated', $this->propertyAccessor->getValue($collection, $path));
7572
}
7673

77-
/**
78-
* @dataProvider getValidPropertyPaths
79-
*/
74+
#[DataProvider('getValidPropertyPaths')]
8075
public function testIsReadable($collection, $path)
8176
{
8277
$this->assertTrue($this->propertyAccessor->isReadable($collection, $path));
8378
}
8479

85-
/**
86-
* @dataProvider getValidPropertyPaths
87-
*/
80+
#[DataProvider('getValidPropertyPaths')]
8881
public function testIsWritable($collection, $path)
8982
{
9083
$this->assertTrue($this->propertyAccessor->isWritable($collection, $path));
9184
}
9285

93-
/**
94-
* @dataProvider getInvalidPropertyPaths
95-
*/
86+
#[DataProvider('getInvalidPropertyPaths')]
9687
public function testIsNotWritable($collection, $path)
9788
{
9889
$this->assertFalse($this->propertyAccessor->isWritable($collection, $path));

Tests/PropertyAccessorTest.php

Lines changed: 22 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Symfony\Component\PropertyAccess\Tests;
1313

14+
use PHPUnit\Framework\Attributes\DataProvider;
1415
use PHPUnit\Framework\TestCase;
1516
use Symfony\Component\Cache\Adapter\ArrayAdapter;
1617
use 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();

Tests/PropertyPathBuilderTest.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Symfony\Component\PropertyAccess\Tests;
1313

14+
use PHPUnit\Framework\Attributes\DataProvider;
1415
use PHPUnit\Framework\TestCase;
1516
use Symfony\Component\PropertyAccess\PropertyPath;
1617
use Symfony\Component\PropertyAccess\PropertyPathBuilder;
@@ -182,9 +183,7 @@ public function testReplaceNegative()
182183
$this->assertEquals($path, $this->builder->getPropertyPath());
183184
}
184185

185-
/**
186-
* @dataProvider provideInvalidOffsets
187-
*/
186+
#[DataProvider('provideInvalidOffsets')]
188187
public function testReplaceDoesNotAllowInvalidOffsets(int $offset)
189188
{
190189
$this->expectException(\OutOfBoundsException::class);

Tests/PropertyPathTest.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Symfony\Component\PropertyAccess\Tests;
1313

14+
use PHPUnit\Framework\Attributes\DataProvider;
1415
use PHPUnit\Framework\TestCase;
1516
use Symfony\Component\PropertyAccess\Exception\InvalidPropertyPathException;
1617
use Symfony\Component\PropertyAccess\PropertyPath;
@@ -49,9 +50,7 @@ public static function providePathsContainingUnexpectedCharacters()
4950
];
5051
}
5152

52-
/**
53-
* @dataProvider providePathsContainingUnexpectedCharacters
54-
*/
53+
#[DataProvider('providePathsContainingUnexpectedCharacters')]
5554
public function testUnexpectedCharacters(string $path)
5655
{
5756
$this->expectException(InvalidPropertyPathException::class);

0 commit comments

Comments
 (0)