diff --git a/LICENSE b/LICENSE index 0083704..0138f8f 100644 --- a/LICENSE +++ b/LICENSE @@ -1,4 +1,4 @@ -Copyright (c) 2004-2023 Fabien Potencier +Copyright (c) 2004-present Fabien Potencier Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/Tests/PropertyAccessorArrayAccessTest.php b/Tests/PropertyAccessorArrayAccessTestCase.php similarity index 74% rename from Tests/PropertyAccessorArrayAccessTest.php rename to Tests/PropertyAccessorArrayAccessTestCase.php index 98d6eb5..b1b3f63 100644 --- a/Tests/PropertyAccessorArrayAccessTest.php +++ b/Tests/PropertyAccessorArrayAccessTestCase.php @@ -16,7 +16,7 @@ use Symfony\Component\PropertyAccess\PropertyAccess; use Symfony\Component\PropertyAccess\PropertyAccessor; -abstract class PropertyAccessorArrayAccessTest extends TestCase +abstract class PropertyAccessorArrayAccessTestCase extends TestCase { /** * @var PropertyAccessor @@ -28,21 +28,21 @@ protected function setUp(): void $this->propertyAccessor = new PropertyAccessor(); } - abstract protected function getContainer(array $array); + abstract protected static function getContainer(array $array); - public function getValidPropertyPaths() + public static function getValidPropertyPaths(): array { return [ - [$this->getContainer(['firstName' => 'Bernhard']), '[firstName]', 'Bernhard'], - [$this->getContainer(['person' => $this->getContainer(['firstName' => 'Bernhard'])]), '[person][firstName]', 'Bernhard'], + [static::getContainer(['firstName' => 'Bernhard']), '[firstName]', 'Bernhard'], + [static::getContainer(['person' => static::getContainer(['firstName' => 'Bernhard'])]), '[person][firstName]', 'Bernhard'], ]; } - public function getInvalidPropertyPaths() + public static function getInvalidPropertyPaths(): array { return [ - [$this->getContainer(['firstName' => 'Bernhard']), 'firstName', 'Bernhard'], - [$this->getContainer(['person' => $this->getContainer(['firstName' => 'Bernhard'])]), 'person.firstName', 'Bernhard'], + [static::getContainer(['firstName' => 'Bernhard']), 'firstName', 'Bernhard'], + [static::getContainer(['person' => static::getContainer(['firstName' => 'Bernhard'])]), 'person.firstName', 'Bernhard'], ]; } @@ -61,7 +61,7 @@ public function testGetValueFailsIfNoSuchIndex() ->enableExceptionOnInvalidIndex() ->getPropertyAccessor(); - $object = $this->getContainer(['firstName' => 'Bernhard']); + $object = static::getContainer(['firstName' => 'Bernhard']); $this->propertyAccessor->getValue($object, '[lastName]'); } diff --git a/Tests/PropertyAccessorArrayObjectTest.php b/Tests/PropertyAccessorArrayObjectTest.php index fb0b383..9d83656 100644 --- a/Tests/PropertyAccessorArrayObjectTest.php +++ b/Tests/PropertyAccessorArrayObjectTest.php @@ -11,9 +11,9 @@ namespace Symfony\Component\PropertyAccess\Tests; -class PropertyAccessorArrayObjectTest extends PropertyAccessorCollectionTest +class PropertyAccessorArrayObjectTest extends PropertyAccessorCollectionTestCase { - protected function getContainer(array $array) + protected static function getContainer(array $array) { return new \ArrayObject($array); } diff --git a/Tests/PropertyAccessorArrayTest.php b/Tests/PropertyAccessorArrayTest.php index c982826..304b823 100644 --- a/Tests/PropertyAccessorArrayTest.php +++ b/Tests/PropertyAccessorArrayTest.php @@ -11,9 +11,9 @@ namespace Symfony\Component\PropertyAccess\Tests; -class PropertyAccessorArrayTest extends PropertyAccessorCollectionTest +class PropertyAccessorArrayTest extends PropertyAccessorCollectionTestCase { - protected function getContainer(array $array) + protected static function getContainer(array $array) { return $array; } diff --git a/Tests/PropertyAccessorCollectionTest.php b/Tests/PropertyAccessorCollectionTestCase.php similarity index 78% rename from Tests/PropertyAccessorCollectionTest.php rename to Tests/PropertyAccessorCollectionTestCase.php index 2daf260..742889a 100644 --- a/Tests/PropertyAccessorCollectionTest.php +++ b/Tests/PropertyAccessorCollectionTestCase.php @@ -13,7 +13,7 @@ use Symfony\Component\PropertyAccess\Exception\NoSuchPropertyException; -class PropertyAccessorCollectionTest_Car +class PropertyAccessorCollectionTestCase_Car { private $axes; @@ -45,7 +45,7 @@ public function getAxes() } } -class PropertyAccessorCollectionTest_CarOnlyAdder +class PropertyAccessorCollectionTestCase_CarOnlyAdder { public function addAxis($axis) { @@ -56,7 +56,7 @@ public function getAxes() } } -class PropertyAccessorCollectionTest_CarOnlyRemover +class PropertyAccessorCollectionTestCase_CarOnlyRemover { public function removeAxis($axis) { @@ -67,14 +67,14 @@ public function getAxes() } } -class PropertyAccessorCollectionTest_CarNoAdderAndRemover +class PropertyAccessorCollectionTestCase_CarNoAdderAndRemover { public function getAxes() { } } -class PropertyAccessorCollectionTest_CompositeCar +class PropertyAccessorCollectionTestCase_CompositeCar { public function getStructure() { @@ -85,7 +85,7 @@ public function setStructure($structure) } } -class PropertyAccessorCollectionTest_CarStructure +class PropertyAccessorCollectionTestCase_CarStructure { public function addAxis($axis) { @@ -100,7 +100,7 @@ public function getAxes() } } -abstract class PropertyAccessorCollectionTest extends PropertyAccessorArrayAccessTest +abstract class PropertyAccessorCollectionTestCase extends PropertyAccessorArrayAccessTestCase { public function testSetValueCallsAdderAndRemoverForCollections() { @@ -111,7 +111,7 @@ public function testSetValueCallsAdderAndRemoverForCollections() // Don't use a mock in order to test whether the collections are // modified while iterating them - $car = new PropertyAccessorCollectionTest_Car($axesBefore); + $car = new PropertyAccessorCollectionTestCase_Car($axesBefore); $this->propertyAccessor->setValue($car, 'axes', $axesMerged); @@ -138,12 +138,18 @@ public function testSetValueCallsAdderAndRemoverForNestedCollections() $structure->expects($this->once()) ->method('removeAxis') ->with('fourth'); + $structure->expects($this->exactly(2)) ->method('addAxis') - ->withConsecutive( - ['first'], - ['third'] - ); + ->willReturnCallback(function (string $axis) { + static $series = [ + 'first', + 'third', + ]; + + $this->assertSame(array_shift($series), $axis); + }) + ; $this->propertyAccessor->setValue($car, 'structure.axes', $axesAfter); } @@ -151,7 +157,7 @@ public function testSetValueCallsAdderAndRemoverForNestedCollections() public function testSetValueFailsIfNoAdderNorRemoverFound() { $this->expectException(NoSuchPropertyException::class); - $this->expectExceptionMessageMatches('/Could not determine access type for property "axes" in class "Mock_PropertyAccessorCollectionTest_CarNoAdderAndRemover_[^"]*"./'); + $this->expectExceptionMessageMatches('/Could not determine access type for property "axes" in class "Mock_PropertyAccessorCollectionTestCase_CarNoAdderAndRemover_[^"]*"./'); $car = $this->createMock(__CLASS__.'_CarNoAdderAndRemover'); $axesBefore = $this->getContainer([1 => 'second', 3 => 'fourth']); $axesAfter = $this->getContainer([0 => 'first', 1 => 'second', 2 => 'third']); @@ -165,33 +171,33 @@ public function testSetValueFailsIfNoAdderNorRemoverFound() public function testIsWritableReturnsTrueIfAdderAndRemoverExists() { - $car = new PropertyAccessorCollectionTest_Car(); + $car = new PropertyAccessorCollectionTestCase_Car(); $this->assertTrue($this->propertyAccessor->isWritable($car, 'axes')); } public function testIsWritableReturnsFalseIfOnlyAdderExists() { - $car = new PropertyAccessorCollectionTest_CarOnlyAdder(); + $car = new PropertyAccessorCollectionTestCase_CarOnlyAdder(); $this->assertFalse($this->propertyAccessor->isWritable($car, 'axes')); } public function testIsWritableReturnsFalseIfOnlyRemoverExists() { - $car = new PropertyAccessorCollectionTest_CarOnlyRemover(); + $car = new PropertyAccessorCollectionTestCase_CarOnlyRemover(); $this->assertFalse($this->propertyAccessor->isWritable($car, 'axes')); } public function testIsWritableReturnsFalseIfNoAdderNorRemoverExists() { - $car = new PropertyAccessorCollectionTest_CarNoAdderAndRemover(); + $car = new PropertyAccessorCollectionTestCase_CarNoAdderAndRemover(); $this->assertFalse($this->propertyAccessor->isWritable($car, 'axes')); } public function testSetValueFailsIfAdderAndRemoverExistButValueIsNotTraversable() { $this->expectException(NoSuchPropertyException::class); - $this->expectExceptionMessageMatches('/The property "axes" in class "Symfony\\\Component\\\PropertyAccess\\\Tests\\\PropertyAccessorCollectionTest_Car" can be defined with the methods "addAxis\(\)", "removeAxis\(\)" but the new value must be an array or an instance of \\\Traversable\./'); - $car = new PropertyAccessorCollectionTest_Car(); + $this->expectExceptionMessageMatches('/The property "axes" in class "Symfony\\\Component\\\PropertyAccess\\\Tests\\\PropertyAccessorCollectionTestCase_Car" can be defined with the methods "addAxis\(\)", "removeAxis\(\)" but the new value must be an array or an instance of \\\Traversable\./'); + $car = new PropertyAccessorCollectionTestCase_Car(); $this->propertyAccessor->setValue($car, 'axes', 'Not an array or Traversable'); } diff --git a/Tests/PropertyAccessorNonTraversableArrayObjectTest.php b/Tests/PropertyAccessorNonTraversableArrayObjectTest.php index 6910d8b..5c01079 100644 --- a/Tests/PropertyAccessorNonTraversableArrayObjectTest.php +++ b/Tests/PropertyAccessorNonTraversableArrayObjectTest.php @@ -13,9 +13,9 @@ use Symfony\Component\PropertyAccess\Tests\Fixtures\NonTraversableArrayObject; -class PropertyAccessorNonTraversableArrayObjectTest extends PropertyAccessorArrayAccessTest +class PropertyAccessorNonTraversableArrayObjectTest extends PropertyAccessorArrayAccessTestCase { - protected function getContainer(array $array) + protected static function getContainer(array $array) { return new NonTraversableArrayObject($array); } diff --git a/Tests/PropertyAccessorTest.php b/Tests/PropertyAccessorTest.php index bf6a768..c5ecd79 100644 --- a/Tests/PropertyAccessorTest.php +++ b/Tests/PropertyAccessorTest.php @@ -49,7 +49,7 @@ protected function setUp(): void $this->propertyAccessor = new PropertyAccessor(); } - public function getPathsWithMissingProperty() + public static function getPathsWithMissingProperty() { return [ [(object) ['firstName' => 'Bernhard'], 'lastName'], @@ -69,7 +69,7 @@ public function getPathsWithMissingProperty() ]; } - public function getPathsWithMissingIndex() + public static function getPathsWithMissingIndex() { return [ [['firstName' => 'Bernhard'], '[lastName]'], @@ -515,7 +515,7 @@ public function testIsWritableRecognizesMagicCallIfEnabled() $this->assertTrue($this->propertyAccessor->isWritable(new TestClassMagicCall('Bernhard'), 'magicCallProperty')); } - public function getValidWritePropertyPaths() + public static function getValidWritePropertyPaths() { return [ [['Bernhard', 'Schussek'], '[0]', 'Bernhard'], @@ -561,9 +561,9 @@ public function getValidWritePropertyPaths() ]; } - public function getValidReadPropertyPaths(): iterable + public static function getValidReadPropertyPaths(): iterable { - yield from $this->getValidWritePropertyPaths(); + yield from self::getValidWritePropertyPaths(); // Optional paths can only be read and can't be written to. yield [(object) [], 'foo?', null]; @@ -596,7 +596,7 @@ public function testSetValueDeepWithMagicGetter() $this->assertSame('Updated', $obj->publicProperty['foo']['bar']); } - public function getReferenceChainObjectsForSetValue() + public static function getReferenceChainObjectsForSetValue() { return [ [['a' => ['b' => ['c' => 'old-value']]], '[a][b][c]', 'new-value'], @@ -617,7 +617,7 @@ public function testSetValueForReferenceChainIssue($object, $path, $value) $this->assertEquals($value, $this->propertyAccessor->getValue($object, $path)); } - public function getReferenceChainObjectsForIsWritable() + public static function getReferenceChainObjectsForIsWritable() { return [ [new TestClassIsWritable(['a' => ['b' => 'old-value']]), 'value[a][b]', false], diff --git a/Tests/PropertyAccessorTraversableArrayObjectTest.php b/Tests/PropertyAccessorTraversableArrayObjectTest.php index 4e45001..bfd52fa 100644 --- a/Tests/PropertyAccessorTraversableArrayObjectTest.php +++ b/Tests/PropertyAccessorTraversableArrayObjectTest.php @@ -13,9 +13,9 @@ use Symfony\Component\PropertyAccess\Tests\Fixtures\TraversableArrayObject; -class PropertyAccessorTraversableArrayObjectTest extends PropertyAccessorCollectionTest +class PropertyAccessorTraversableArrayObjectTest extends PropertyAccessorCollectionTestCase { - protected function getContainer(array $array) + protected static function getContainer(array $array) { return new TraversableArrayObject($array); } diff --git a/Tests/PropertyPathBuilderTest.php b/Tests/PropertyPathBuilderTest.php index e26ed62..5f46712 100644 --- a/Tests/PropertyPathBuilderTest.php +++ b/Tests/PropertyPathBuilderTest.php @@ -194,7 +194,7 @@ public function testReplaceDoesNotAllowInvalidOffsets($offset) $this->builder->replace($offset, 1, new PropertyPath('new1[new2].new3')); } - public function provideInvalidOffsets() + public static function provideInvalidOffsets() { return [ [6], diff --git a/Tests/PropertyPathTest.php b/Tests/PropertyPathTest.php index c772431..2898624 100644 --- a/Tests/PropertyPathTest.php +++ b/Tests/PropertyPathTest.php @@ -36,7 +36,7 @@ public function testDotCannotBePresentAtTheBeginning() new PropertyPath('.property'); } - public function providePathsContainingUnexpectedCharacters() + public static function providePathsContainingUnexpectedCharacters() { return [ ['property.'], diff --git a/composer.json b/composer.json index a8ba0b1..fd0f1dd 100644 --- a/composer.json +++ b/composer.json @@ -2,7 +2,7 @@ "name": "symfony/property-access", "type": "library", "description": "Provides functions to read and write from/to an object or array using a simple string notation", - "keywords": ["property", "index", "access", "object", "array", "extraction", "injection", "reflection", "property path"], + "keywords": ["property", "index", "access", "object", "array", "extraction", "injection", "reflection", "property-path"], "homepage": "https://symfony.com", "license": "MIT", "authors": [