diff --git a/src/Symfony/Component/PropertyAccess/PropertyAccessor.php b/src/Symfony/Component/PropertyAccess/PropertyAccessor.php index 0e400f4380de..e2c06d1b73c1 100644 --- a/src/Symfony/Component/PropertyAccess/PropertyAccessor.php +++ b/src/Symfony/Component/PropertyAccess/PropertyAccessor.php @@ -33,7 +33,7 @@ class PropertyAccessor implements PropertyAccessorInterface /** * @var bool */ - private $throwExceptionOnInvalidIndex; + private $ignoreInvalidIndices; /** * Should not be used by application code. Use @@ -42,7 +42,7 @@ class PropertyAccessor implements PropertyAccessorInterface public function __construct($magicCall = false, $throwExceptionOnInvalidIndex = false) { $this->magicCall = $magicCall; - $this->throwExceptionOnInvalidIndex = $throwExceptionOnInvalidIndex; + $this->ignoreInvalidIndices = $throwExceptionOnInvalidIndex; } /** @@ -56,7 +56,7 @@ public function getValue($objectOrArray, $propertyPath) throw new UnexpectedTypeException($propertyPath, 'string or Symfony\Component\PropertyAccess\PropertyPathInterface'); } - $propertyValues =& $this->readPropertiesUntil($objectOrArray, $propertyPath, $propertyPath->getLength(), $this->throwExceptionOnInvalidIndex); + $propertyValues =& $this->readPropertiesUntil($objectOrArray, $propertyPath, $propertyPath->getLength(), $this->ignoreInvalidIndices); return $propertyValues[count($propertyValues) - 1][self::VALUE]; } @@ -116,7 +116,7 @@ public function setValue(&$objectOrArray, $propertyPath, $value) * * @throws UnexpectedTypeException If a value within the path is neither object nor array. */ - private function &readPropertiesUntil(&$objectOrArray, PropertyPathInterface $propertyPath, $lastIndex, $throwExceptionOnNonexistantIndex = false) + private function &readPropertiesUntil(&$objectOrArray, PropertyPathInterface $propertyPath, $lastIndex, $ignoreInvalidIndices = false) { $propertyValues = array(); @@ -131,9 +131,25 @@ private function &readPropertiesUntil(&$objectOrArray, PropertyPathInterface $pr // Create missing nested arrays on demand if ($isIndex && $isArrayAccess && !isset($objectOrArray[$property])) { - if ($throwExceptionOnNonexistantIndex) { - throw new NoSuchIndexException(sprintf('Cannot read property "%s". Available properties are "%s"', $property, print_r(array_keys($objectOrArray), true))); + if ($ignoreInvalidIndices) { + if (!is_array($objectOrArray)) { + if (!$objectOrArray instanceof \Traversable) { + throw new NoSuchIndexException(sprintf( + 'Cannot read property "%s".', + $property + )); + } + + $objectOrArray = iterator_to_array($objectOrArray); + } + + throw new NoSuchIndexException(sprintf( + 'Cannot read property "%s". Available properties are "%s"', + $property, + print_r(array_keys($objectOrArray), true) + )); } + $objectOrArray[$property] = $i + 1 < $propertyPath->getLength() ? array() : null; } @@ -412,8 +428,8 @@ private function findAdderAndRemover(\ReflectionClass $reflClass, array $singula $addMethod = 'add'.$singular; $removeMethod = 'remove'.$singular; - $addMethodFound = $this->isAccessible($reflClass, $addMethod, 1); - $removeMethodFound = $this->isAccessible($reflClass, $removeMethod, 1); + $addMethodFound = $this->isMethodAccessible($reflClass, $addMethod, 1); + $removeMethodFound = $this->isMethodAccessible($reflClass, $removeMethod, 1); if ($addMethodFound && $removeMethodFound) { return array($addMethod, $removeMethod); @@ -428,6 +444,8 @@ private function findAdderAndRemover(\ReflectionClass $reflClass, array $singula )); } } + + return null; } /** @@ -440,7 +458,7 @@ private function findAdderAndRemover(\ReflectionClass $reflClass, array $singula * @return bool Whether the method is public and has $parameters * required parameters */ - private function isAccessible(\ReflectionClass $class, $methodName, $parameters) + private function isMethodAccessible(\ReflectionClass $class, $methodName, $parameters) { if ($class->hasMethod($methodName)) { $method = $class->getMethod($methodName); diff --git a/src/Symfony/Component/PropertyAccess/Tests/Fixtures/Author.php b/src/Symfony/Component/PropertyAccess/Tests/Fixtures/Author.php deleted file mode 100644 index ed2331bab04f..000000000000 --- a/src/Symfony/Component/PropertyAccess/Tests/Fixtures/Author.php +++ /dev/null @@ -1,71 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Component\PropertyAccess\Tests\Fixtures; - -class Author -{ - public $firstName; - private $lastName; - private $australian; - public $child; - private $readPermissions; - - private $privateProperty; - - public function setLastName($lastName) - { - $this->lastName = $lastName; - } - - public function getLastName() - { - return $this->lastName; - } - - private function getPrivateGetter() - { - return 'foobar'; - } - - public function setAustralian($australian) - { - $this->australian = $australian; - } - - public function isAustralian() - { - return $this->australian; - } - - public function setReadPermissions($bool) - { - $this->readPermissions = $bool; - } - - public function hasReadPermissions() - { - return $this->readPermissions; - } - - private function isPrivateIsser() - { - return true; - } - - public function getPrivateSetter() - { - } - - private function setPrivateSetter($data) - { - } -} diff --git a/src/Symfony/Component/PropertyAccess/Tests/Fixtures/Magician.php b/src/Symfony/Component/PropertyAccess/Tests/Fixtures/Magician.php deleted file mode 100644 index 6faa5dbf7bb3..000000000000 --- a/src/Symfony/Component/PropertyAccess/Tests/Fixtures/Magician.php +++ /dev/null @@ -1,27 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Component\PropertyAccess\Tests\Fixtures; - -class Magician -{ - private $foobar; - - public function __set($property, $value) - { - $this->$property = $value; - } - - public function __get($property) - { - return isset($this->$property) ? $this->$property : null; - } -} diff --git a/src/Symfony/Component/PropertyAccess/Tests/Fixtures/MagicianCall.php b/src/Symfony/Component/PropertyAccess/Tests/Fixtures/MagicianCall.php deleted file mode 100644 index 0508a71da1e4..000000000000 --- a/src/Symfony/Component/PropertyAccess/Tests/Fixtures/MagicianCall.php +++ /dev/null @@ -1,28 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Component\PropertyAccess\Tests\Fixtures; - -class MagicianCall -{ - private $foobar; - - public function __call($name, $args) - { - $property = lcfirst(substr($name, 3)); - if ('get' === substr($name, 0, 3)) { - return isset($this->$property) ? $this->$property : null; - } elseif ('set' === substr($name, 0, 3)) { - $value = 1 == count($args) ? $args[0] : null; - $this->$property = $value; - } - } -} diff --git a/src/Symfony/Component/PropertyAccess/Tests/Fixtures/NonTraversableArrayObject.php b/src/Symfony/Component/PropertyAccess/Tests/Fixtures/NonTraversableArrayObject.php new file mode 100644 index 000000000000..fd00a730b831 --- /dev/null +++ b/src/Symfony/Component/PropertyAccess/Tests/Fixtures/NonTraversableArrayObject.php @@ -0,0 +1,65 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\PropertyAccess\Tests\Fixtures; + +/** + * This class is a hand written simplified version of PHP native `ArrayObject` + * class, to show that it behaves differently than the PHP native implementation. + */ +class NonTraversableArrayObject implements \ArrayAccess, \Countable, \Serializable +{ + private $array; + + public function __construct(array $array = null) + { + $this->array = $array ?: array(); + } + + public function offsetExists($offset) + { + return array_key_exists($offset, $this->array); + } + + public function offsetGet($offset) + { + return $this->array[$offset]; + } + + public function offsetSet($offset, $value) + { + if (null === $offset) { + $this->array[] = $value; + } else { + $this->array[$offset] = $value; + } + } + + public function offsetUnset($offset) + { + unset($this->array[$offset]); + } + + public function count() + { + return count($this->array); + } + + public function serialize() + { + return serialize($this->array); + } + + public function unserialize($serialized) + { + $this->array = (array) unserialize((string) $serialized); + } +} diff --git a/src/Symfony/Component/PropertyAccess/Tests/Fixtures/TestClass.php b/src/Symfony/Component/PropertyAccess/Tests/Fixtures/TestClass.php new file mode 100644 index 000000000000..178d7f618abb --- /dev/null +++ b/src/Symfony/Component/PropertyAccess/Tests/Fixtures/TestClass.php @@ -0,0 +1,115 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\PropertyAccess\Tests\Fixtures; + +class TestClass +{ + public $publicProperty; + protected $protectedProperty; + private $privateProperty; + + private $publicAccessor; + private $publicIsAccessor; + private $publicHasAccessor; + + public function __construct($value) + { + $this->publicProperty = $value; + $this->publicAccessor = $value; + $this->publicIsAccessor = $value; + $this->publicHasAccessor = $value; + } + + public function setPublicAccessor($value) + { + $this->publicAccessor = $value; + } + + public function getPublicAccessor() + { + return $this->publicAccessor; + } + + public function setPublicIsAccessor($value) + { + $this->publicIsAccessor = $value; + } + + public function isPublicIsAccessor() + { + return $this->publicIsAccessor; + } + + public function setPublicHasAccessor($value) + { + $this->publicHasAccessor = $value; + } + + public function hasPublicHasAccessor() + { + return $this->publicHasAccessor; + } + + protected function setProtectedAccessor($value) + { + } + + protected function getProtectedAccessor() + { + return 'foobar'; + } + + protected function setProtectedIsAccessor($value) + { + } + + protected function isProtectedIsAccessor() + { + return 'foobar'; + } + + protected function setProtectedHasAccessor($value) + { + } + + protected function hasProtectedHasAccessor() + { + return 'foobar'; + } + + private function setPrivateAccessor($value) + { + } + + private function getPrivateAccessor() + { + return 'foobar'; + } + + private function setPrivateIsAccessor($value) + { + } + + private function isPrivateIsAccessor() + { + return 'foobar'; + } + + private function setPrivateHasAccessor($value) + { + } + + private function hasPrivateHasAccessor() + { + return 'foobar'; + } +} diff --git a/src/Symfony/Component/PropertyAccess/Tests/Fixtures/TestClassMagicCall.php b/src/Symfony/Component/PropertyAccess/Tests/Fixtures/TestClassMagicCall.php new file mode 100644 index 000000000000..d49967abd1a6 --- /dev/null +++ b/src/Symfony/Component/PropertyAccess/Tests/Fixtures/TestClassMagicCall.php @@ -0,0 +1,39 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\PropertyAccess\Tests\Fixtures; + +class TestClassMagicCall +{ + private $magicCallProperty; + + public function __construct($value) + { + $this->magicCallProperty = $value; + } + + public function __call($method, array $args) + { + if ('getMagicCallProperty' === $method) { + return $this->magicCallProperty; + } + + if ('getConstantMagicCallProperty' === $method) { + return 'constant value'; + } + + if ('setMagicCallProperty' === $method) { + $this->magicCallProperty = reset($args); + } + + return null; + } +} diff --git a/src/Symfony/Component/PropertyAccess/Tests/Fixtures/TestClassMagicGet.php b/src/Symfony/Component/PropertyAccess/Tests/Fixtures/TestClassMagicGet.php new file mode 100644 index 000000000000..fee831896672 --- /dev/null +++ b/src/Symfony/Component/PropertyAccess/Tests/Fixtures/TestClassMagicGet.php @@ -0,0 +1,42 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\PropertyAccess\Tests\Fixtures; + +class TestClassMagicGet +{ + private $magicProperty; + + public function __construct($value) + { + $this->magicProperty = $value; + } + + public function __set($property, $value) + { + if ('magicProperty' === $property) { + $this->magicProperty = $value; + } + } + + public function __get($property) + { + if ('magicProperty' === $property) { + return $this->magicProperty; + } + + if ('constantMagicProperty' === $property) { + return 'constant value'; + } + + return null; + } +} diff --git a/src/Symfony/Component/PropertyAccess/Tests/Fixtures/CustomArrayObject.php b/src/Symfony/Component/PropertyAccess/Tests/Fixtures/TraversableArrayObject.php similarity index 93% rename from src/Symfony/Component/PropertyAccess/Tests/Fixtures/CustomArrayObject.php rename to src/Symfony/Component/PropertyAccess/Tests/Fixtures/TraversableArrayObject.php index cd23f7033fc6..3bd9795e6b25 100644 --- a/src/Symfony/Component/PropertyAccess/Tests/Fixtures/CustomArrayObject.php +++ b/src/Symfony/Component/PropertyAccess/Tests/Fixtures/TraversableArrayObject.php @@ -15,7 +15,7 @@ * This class is a hand written simplified version of PHP native `ArrayObject` * class, to show that it behaves differently than the PHP native implementation. */ -class CustomArrayObject implements \ArrayAccess, \IteratorAggregate, \Countable, \Serializable +class TraversableArrayObject implements \ArrayAccess, \IteratorAggregate, \Countable, \Serializable { private $array; diff --git a/src/Symfony/Component/PropertyAccess/Tests/PropertyAccessorArrayAccessTest.php b/src/Symfony/Component/PropertyAccess/Tests/PropertyAccessorArrayAccessTest.php new file mode 100644 index 000000000000..7c5d3a9a6056 --- /dev/null +++ b/src/Symfony/Component/PropertyAccess/Tests/PropertyAccessorArrayAccessTest.php @@ -0,0 +1,70 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\PropertyAccess\Tests; + +use Symfony\Component\PropertyAccess\PropertyAccess; +use Symfony\Component\PropertyAccess\PropertyAccessor; + +abstract class PropertyAccessorArrayAccessTest extends \PHPUnit_Framework_TestCase +{ + /** + * @var PropertyAccessor + */ + protected $propertyAccessor; + + protected function setUp() + { + $this->propertyAccessor = new PropertyAccessor(); + } + + abstract protected function getContainer(array $array); + + public function getValidPropertyPaths() + { + return array( + array($this->getContainer(array('firstName' => 'Bernhard')), '[firstName]', 'Bernhard'), + array($this->getContainer(array('person' => $this->getContainer(array('firstName' => 'Bernhard')))), '[person][firstName]', 'Bernhard'), + ); + } + + /** + * @dataProvider getValidPropertyPaths + */ + public function testGetValue($collection, $path, $value) + { + $this->assertSame($value, $this->propertyAccessor->getValue($collection, $path)); + } + + /** + * @expectedException \Symfony\Component\PropertyAccess\Exception\NoSuchIndexException + */ + public function testGetValueFailsIfNoSuchIndex() + { + $this->propertyAccessor = PropertyAccess::createPropertyAccessorBuilder() + ->enableExceptionOnInvalidIndex() + ->getPropertyAccessor(); + + $object = $this->getContainer(array('firstName' => 'Bernhard')); + + $this->propertyAccessor->getValue($object, '[lastName]'); + } + + /** + * @dataProvider getValidPropertyPaths + */ + public function testSetValue($collection, $path) + { + $this->propertyAccessor->setValue($collection, $path, 'Updated'); + + $this->assertSame('Updated', $this->propertyAccessor->getValue($collection, $path)); + } +} diff --git a/src/Symfony/Component/PropertyAccess/Tests/PropertyAccessorArrayObjectTest.php b/src/Symfony/Component/PropertyAccess/Tests/PropertyAccessorArrayObjectTest.php index aaa86b3c25f8..fb0b383789ba 100644 --- a/src/Symfony/Component/PropertyAccess/Tests/PropertyAccessorArrayObjectTest.php +++ b/src/Symfony/Component/PropertyAccess/Tests/PropertyAccessorArrayObjectTest.php @@ -13,7 +13,7 @@ class PropertyAccessorArrayObjectTest extends PropertyAccessorCollectionTest { - protected function getCollection(array $array) + protected function getContainer(array $array) { return new \ArrayObject($array); } diff --git a/src/Symfony/Component/PropertyAccess/Tests/PropertyAccessorArrayTest.php b/src/Symfony/Component/PropertyAccess/Tests/PropertyAccessorArrayTest.php index 5ab63c67cb32..c982826344ce 100644 --- a/src/Symfony/Component/PropertyAccess/Tests/PropertyAccessorArrayTest.php +++ b/src/Symfony/Component/PropertyAccess/Tests/PropertyAccessorArrayTest.php @@ -13,7 +13,7 @@ class PropertyAccessorArrayTest extends PropertyAccessorCollectionTest { - protected function getCollection(array $array) + protected function getContainer(array $array) { return $array; } diff --git a/src/Symfony/Component/PropertyAccess/Tests/PropertyAccessorCollectionTest.php b/src/Symfony/Component/PropertyAccess/Tests/PropertyAccessorCollectionTest.php index b0f75aa36661..a6f8d19ad904 100644 --- a/src/Symfony/Component/PropertyAccess/Tests/PropertyAccessorCollectionTest.php +++ b/src/Symfony/Component/PropertyAccess/Tests/PropertyAccessorCollectionTest.php @@ -47,19 +47,6 @@ public function getAxes() } } -class PropertyAccessorCollectionTest_CarCustomSingular -{ - public function addFoo($axis) {} - - public function removeFoo($axis) {} - - public function getAxes() {} -} - -class PropertyAccessorCollectionTest_Engine -{ -} - class PropertyAccessorCollectionTest_CarOnlyAdder { public function addAxis($axis) {} @@ -79,13 +66,6 @@ class PropertyAccessorCollectionTest_CarNoAdderAndRemover public function getAxes() {} } -class PropertyAccessorCollectionTest_CarNoAdderAndRemoverWithProperty -{ - protected $axes = array(); - - public function getAxes() {} -} - class PropertyAccessorCollectionTest_CompositeCar { public function getStructure() {} @@ -102,73 +82,13 @@ public function removeAxis($axis) {} public function getAxes() {} } -abstract class PropertyAccessorCollectionTest extends \PHPUnit_Framework_TestCase +abstract class PropertyAccessorCollectionTest extends PropertyAccessorArrayAccessTest { - /** - * @var PropertyAccessor - */ - private $propertyAccessor; - - protected function setUp() - { - $this->propertyAccessor = new PropertyAccessor(); - } - - abstract protected function getCollection(array $array); - - public function testGetValueReadsArrayAccess() - { - $object = $this->getCollection(array('firstName' => 'Bernhard')); - - $this->assertEquals('Bernhard', $this->propertyAccessor->getValue($object, '[firstName]')); - } - - public function testGetValueReadsNestedArrayAccess() - { - $object = $this->getCollection(array('person' => array('firstName' => 'Bernhard'))); - - $this->assertEquals('Bernhard', $this->propertyAccessor->getValue($object, '[person][firstName]')); - } - - /** - * @expectedException \Symfony\Component\PropertyAccess\Exception\NoSuchPropertyException - */ - public function testGetValueThrowsExceptionIfArrayAccessExpected() - { - $this->propertyAccessor->getValue(new \stdClass(), '[firstName]'); - } - - public function testSetValueUpdatesArrayAccess() - { - $object = $this->getCollection(array()); - - $this->propertyAccessor->setValue($object, '[firstName]', 'Bernhard'); - - $this->assertEquals('Bernhard', $object['firstName']); - } - - public function testSetValueUpdatesNestedArrayAccess() - { - $object = $this->getCollection(array()); - - $this->propertyAccessor->setValue($object, '[person][firstName]', 'Bernhard'); - - $this->assertEquals('Bernhard', $object['person']['firstName']); - } - - /** - * @expectedException \Symfony\Component\PropertyAccess\Exception\NoSuchPropertyException - */ - public function testSetValueThrowsExceptionIfArrayAccessExpected() - { - $this->propertyAccessor->setValue(new \stdClass(), '[firstName]', 'Bernhard'); - } - public function testSetValueCallsAdderAndRemoverForCollections() { - $axesBefore = $this->getCollection(array(1 => 'second', 3 => 'fourth', 4 => 'fifth')); - $axesMerged = $this->getCollection(array(1 => 'first', 2 => 'second', 3 => 'third')); - $axesAfter = $this->getCollection(array(1 => 'second', 5 => 'first', 6 => 'third')); + $axesBefore = $this->getContainer(array(1 => 'second', 3 => 'fourth', 4 => 'fifth')); + $axesMerged = $this->getContainer(array(1 => 'first', 2 => 'second', 3 => 'third')); + $axesAfter = $this->getContainer(array(1 => 'second', 5 => 'first', 6 => 'third')); $axesMergedCopy = is_object($axesMerged) ? clone $axesMerged : $axesMerged; // Don't use a mock in order to test whether the collections are @@ -187,8 +107,8 @@ public function testSetValueCallsAdderAndRemoverForNestedCollections() { $car = $this->getMock(__CLASS__.'_CompositeCar'); $structure = $this->getMock(__CLASS__.'_CarStructure'); - $axesBefore = $this->getCollection(array(1 => 'second', 3 => 'fourth')); - $axesAfter = $this->getCollection(array(0 => 'first', 1 => 'second', 2 => 'third')); + $axesBefore = $this->getContainer(array(1 => 'second', 3 => 'fourth')); + $axesAfter = $this->getContainer(array(0 => 'first', 1 => 'second', 2 => 'third')); $car->expects($this->any()) ->method('getStructure') @@ -210,38 +130,15 @@ public function testSetValueCallsAdderAndRemoverForNestedCollections() $this->propertyAccessor->setValue($car, 'structure.axes', $axesAfter); } - public function testSetValueCallsCustomAdderAndRemover() - { - $this->markTestSkipped('This feature is temporarily disabled as of 2.1'); - - $car = $this->getMock(__CLASS__.'_CarCustomSingular'); - $axesBefore = $this->getCollection(array(1 => 'second', 3 => 'fourth')); - $axesAfter = $this->getCollection(array(0 => 'first', 1 => 'second', 2 => 'third')); - - $car->expects($this->at(0)) - ->method('getAxes') - ->will($this->returnValue($axesBefore)); - $car->expects($this->at(1)) - ->method('removeFoo') - ->with('fourth'); - $car->expects($this->at(2)) - ->method('addFoo') - ->with('first'); - $car->expects($this->at(3)) - ->method('addFoo') - ->with('third'); - - $this->propertyAccessor->setValue($car, 'axes|foo', $axesAfter); - } - /** * @expectedException \Symfony\Component\PropertyAccess\Exception\NoSuchPropertyException + * @expectedExceptionMessage Found the public method "addAxis()", but did not find a public "removeAxis()" on class Mock_PropertyAccessorCollectionTest_CarOnlyAdder */ public function testSetValueFailsIfOnlyAdderFound() { $car = $this->getMock(__CLASS__.'_CarOnlyAdder'); - $axesBefore = $this->getCollection(array(1 => 'second', 3 => 'fourth')); - $axesAfter = $this->getCollection(array(0 => 'first', 1 => 'second', 2 => 'third')); + $axesBefore = $this->getContainer(array(1 => 'second', 3 => 'fourth')); + $axesAfter = $this->getContainer(array(0 => 'first', 1 => 'second', 2 => 'third')); $car->expects($this->any()) ->method('getAxes') @@ -252,12 +149,13 @@ public function testSetValueFailsIfOnlyAdderFound() /** * @expectedException \Symfony\Component\PropertyAccess\Exception\NoSuchPropertyException + * @expectedExceptionMessage Found the public method "removeAxis()", but did not find a public "addAxis()" on class Mock_PropertyAccessorCollectionTest_CarOnlyRemover */ public function testSetValueFailsIfOnlyRemoverFound() { $car = $this->getMock(__CLASS__.'_CarOnlyRemover'); - $axesBefore = $this->getCollection(array(1 => 'second', 3 => 'fourth')); - $axesAfter = $this->getCollection(array(0 => 'first', 1 => 'second', 2 => 'third')); + $axesBefore = $this->getContainer(array(1 => 'second', 3 => 'fourth')); + $axesAfter = $this->getContainer(array(0 => 'first', 1 => 'second', 2 => 'third')); $car->expects($this->any()) ->method('getAxes') @@ -267,58 +165,14 @@ public function testSetValueFailsIfOnlyRemoverFound() } /** - * @dataProvider noAdderRemoverData + * @expectedException \Symfony\Component\PropertyAccess\Exception\NoSuchPropertyException + * @expectedExceptionMessage Neither the property "axes" nor one of the methods "addAx()", "addAxe()", "addAxis()", "setAxes()", "__set()" or "__call()" exist and have public access in class "Mock_PropertyAccessorCollectionTest_CarNoAdderAndRemover */ - public function testNoAdderAndRemoverThrowsSensibleError($car, $path, $message) - { - $axes = $this->getCollection(array(0 => 'first', 1 => 'second', 2 => 'third')); - - try { - $this->propertyAccessor->setValue($car, $path, $axes); - $this->fail('An expected exception was not thrown!'); - } catch (ExceptionInterface $e) { - $this->assertEquals($message, $e->getMessage()); - } - } - - public function noAdderRemoverData() + public function testSetValueFailsIfNoAdderAndNoRemoverFound() { - $data = array(); - $car = $this->getMock(__CLASS__.'_CarNoAdderAndRemover'); - $propertyPath = 'axes'; - $expectedMessage = sprintf( - 'Neither the property "axes" nor one of the methods "addAx()", '. - '"addAxe()", "addAxis()", "setAxes()", "__set()" or "__call()" exist and have '. - 'public access in class "%s".', - get_class($car) - ); - $data[] = array($car, $propertyPath, $expectedMessage); - - /* - Temporarily disabled in 2.1 - - $propertyPath = new PropertyPath('axes|boo'); - $expectedMessage = sprintf( - 'Neither element "axes" nor method "setAxes()" exists in class ' - .'"%s", nor could adders and removers be found based on the ' - .'passed singular: %s', - get_class($car), - 'boo' - ); - $data[] = array($car, $propertyPath, $expectedMessage); - */ - - $car = $this->getMock(__CLASS__.'_CarNoAdderAndRemoverWithProperty'); - $propertyPath = 'axes'; - $expectedMessage = sprintf( - 'Neither the property "axes" nor one of the methods "addAx()", '. - '"addAxe()", "addAxis()", "setAxes()", "__set()" or "__call()" exist and have '. - 'public access in class "%s".', - get_class($car) - ); - $data[] = array($car, $propertyPath, $expectedMessage); - - return $data; + $axes = $this->getContainer(array(0 => 'first', 1 => 'second', 2 => 'third')); + + $this->propertyAccessor->setValue($car, 'axes', $axes); } } diff --git a/src/Symfony/Component/PropertyAccess/Tests/PropertyAccessorNonTraversableArrayObjectTest.php b/src/Symfony/Component/PropertyAccess/Tests/PropertyAccessorNonTraversableArrayObjectTest.php new file mode 100644 index 000000000000..6910d8be7031 --- /dev/null +++ b/src/Symfony/Component/PropertyAccess/Tests/PropertyAccessorNonTraversableArrayObjectTest.php @@ -0,0 +1,22 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\PropertyAccess\Tests; + +use Symfony\Component\PropertyAccess\Tests\Fixtures\NonTraversableArrayObject; + +class PropertyAccessorNonTraversableArrayObjectTest extends PropertyAccessorArrayAccessTest +{ + protected function getContainer(array $array) + { + return new NonTraversableArrayObject($array); + } +} diff --git a/src/Symfony/Component/PropertyAccess/Tests/PropertyAccessorTest.php b/src/Symfony/Component/PropertyAccess/Tests/PropertyAccessorTest.php index a64930a93a7b..5b64a227f6f4 100644 --- a/src/Symfony/Component/PropertyAccess/Tests/PropertyAccessorTest.php +++ b/src/Symfony/Component/PropertyAccess/Tests/PropertyAccessorTest.php @@ -12,221 +12,161 @@ namespace Symfony\Component\PropertyAccess\Tests; use Symfony\Component\PropertyAccess\PropertyAccessor; -use Symfony\Component\PropertyAccess\Tests\Fixtures\Author; +use Symfony\Component\PropertyAccess\Tests\Fixtures\TestClass; use Symfony\Component\PropertyAccess\Tests\Fixtures\Magician; -use Symfony\Component\PropertyAccess\Tests\Fixtures\MagicianCall; -use Symfony\Component\PropertyAccess\PropertyAccessorBuilder; +use Symfony\Component\PropertyAccess\Tests\Fixtures\TestClassMagicCall; +use Symfony\Component\PropertyAccess\Tests\Fixtures\TestClassMagicGet; class PropertyAccessorTest extends \PHPUnit_Framework_TestCase { /** - * @var PropertyAccessorBuilder + * @var PropertyAccessor */ - private $propertyAccessorBuilder; + private $propertyAccessor; protected function setUp() { - $this->propertyAccessorBuilder = new PropertyAccessorBuilder(); + $this->propertyAccessor = new PropertyAccessor(); } - /** - * Get PropertyAccessor configured - * - * @param string $withMagicCall - * @param string $throwExceptionOnInvalidIndex - * @return PropertyAccessorInterface - */ - protected function getPropertyAccessor($withMagicCall = false, $throwExceptionOnInvalidIndex = false) - { - if ($withMagicCall) { - $this->propertyAccessorBuilder->enableMagicCall(); - } else { - $this->propertyAccessorBuilder->disableMagicCall(); - } - - if ($throwExceptionOnInvalidIndex) { - $this->propertyAccessorBuilder->enableExceptionOnInvalidIndex(); - } else { - $this->propertyAccessorBuilder->disableExceptionOnInvalidIndex(); - } - - return $this->propertyAccessorBuilder->getPropertyAccessor(); - } - - public function testGetValueReadsArray() - { - $array = array('firstName' => 'Bernhard'); - - $this->assertEquals('Bernhard', $this->getPropertyAccessor()->getValue($array, '[firstName]')); - } - - /** - * @expectedException \Symfony\Component\PropertyAccess\Exception\NoSuchPropertyException - */ - public function testGetValueThrowsExceptionIfIndexNotationExpected() - { - $array = array('firstName' => 'Bernhard'); - - $this->getPropertyAccessor()->getValue($array, 'firstName'); - } - - public function testGetValueReadsZeroIndex() + public function getValidPropertyPaths() { - $array = array('Bernhard'); - - $this->assertEquals('Bernhard', $this->getPropertyAccessor()->getValue($array, '[0]')); - } + return array( + array(array('Bernhard', 'Schussek'), '[0]', 'Bernhard'), + array(array('Bernhard', 'Schussek'), '[1]', 'Schussek'), + array(array('firstName' => 'Bernhard'), '[firstName]', 'Bernhard'), + array(array('index' => array('firstName' => 'Bernhard')), '[index][firstName]', 'Bernhard'), + array((object) array('firstName' => 'Bernhard'), 'firstName', 'Bernhard'), + array((object) array('property' => array('firstName' => 'Bernhard')), 'property[firstName]', 'Bernhard'), + array(array('index' => (object) array('firstName' => 'Bernhard')), '[index].firstName', 'Bernhard'), + array((object) array('property' => (object) array('firstName' => 'Bernhard')), 'property.firstName', 'Bernhard'), - public function testGetValueReadsIndexWithSpecialChars() - { - $array = array('%!@$§.' => 'Bernhard'); + // Accessor methods + array(new TestClass('Bernhard'), 'publicProperty', 'Bernhard'), + array(new TestClass('Bernhard'), 'publicAccessor', 'Bernhard'), + array(new TestClass('Bernhard'), 'publicIsAccessor', 'Bernhard'), + array(new TestClass('Bernhard'), 'publicHasAccessor', 'Bernhard'), - $this->assertEquals('Bernhard', $this->getPropertyAccessor()->getValue($array, '[%!@$§.]')); - } + // Methods are camelized + array(new TestClass('Bernhard'), 'public_accessor', 'Bernhard'), - public function testGetValueReadsNestedIndexWithSpecialChars() - { - $array = array('root' => array('%!@$§.' => 'Bernhard')); + // Missing indices + array(array('index' => array()), '[index][firstName]', null), + array(array('root' => array('index' => array())), '[root][index][firstName]', null), - $this->assertEquals('Bernhard', $this->getPropertyAccessor()->getValue($array, '[root][%!@$§.]')); + // Special chars + array(array('%!@$§.' => 'Bernhard'), '[%!@$§.]', 'Bernhard'), + array(array('index' => array('%!@$§.' => 'Bernhard')), '[index][%!@$§.]', 'Bernhard'), + array((object) array('%!@$§' => 'Bernhard'), '%!@$§', 'Bernhard'), + ); } - public function testGetValueReadsArrayWithCustomPropertyPath() + public function getPathsWithMissingProperty() { - $array = array('child' => array('index' => array('firstName' => 'Bernhard'))); + return array( + array((object) array('firstName' => 'Bernhard'), 'lastName'), + array((object) array('property' => (object) array('firstName' => 'Bernhard')), 'property.lastName'), + array(array('index' => (object) array('firstName' => 'Bernhard')), '[index].lastName'), + array(new TestClass('Bernhard'), 'protectedProperty'), + array(new TestClass('Bernhard'), 'privateProperty'), + array(new TestClass('Bernhard'), 'protectedAccessor'), + array(new TestClass('Bernhard'), 'protectedIsAccessor'), + array(new TestClass('Bernhard'), 'protectedHasAccessor'), + array(new TestClass('Bernhard'), 'privateAccessor'), + array(new TestClass('Bernhard'), 'privateIsAccessor'), + array(new TestClass('Bernhard'), 'privateHasAccessor'), - $this->assertEquals('Bernhard', $this->getPropertyAccessor()->getValue($array, '[child][index][firstName]')); + // Properties are not camelized + array(new TestClass('Bernhard'), 'public_property'), + ); } - public function testGetValueReadsArrayWithMissingIndexForCustomPropertyPath() + public function getPathsWithMissingIndex() { - $array = array('child' => array('index' => array())); - - // No BC break - $this->assertNull($this->getPropertyAccessor()->getValue($array, '[child][index][firstName]')); - - try { - $this->getPropertyAccessor(false, true)->getValue($array, '[child][index][firstName]'); - $this->fail('Getting value on a nonexistent path from array should throw a Symfony\Component\PropertyAccess\Exception\NoSuchIndexException exception'); - } catch (\Exception $e) { - $this->assertInstanceof('Symfony\Component\PropertyAccess\Exception\NoSuchIndexException', $e, 'Getting value on a nonexistent path from array should throw a Symfony\Component\PropertyAccess\Exception\NoSuchIndexException exception'); - } + return array( + array(array('firstName' => 'Bernhard'), '[lastName]'), + array(array(), '[index][lastName]'), + array(array('index' => array()), '[index][lastName]'), + array(array('index' => array('firstName' => 'Bernhard')), '[index][lastName]'), + array((object) array('property' => array('firstName' => 'Bernhard')), 'property[lastName]'), + ); } - public function testGetValueReadsProperty() - { - $object = new Author(); - $object->firstName = 'Bernhard'; - - $this->assertEquals('Bernhard', $this->getPropertyAccessor()->getValue($object, 'firstName')); - } - - public function testGetValueIgnoresSingular() - { - $this->markTestSkipped('This feature is temporarily disabled as of 2.1'); - - $object = (object) array('children' => 'Many'); - - $this->assertEquals('Many', $this->getPropertyAccessor()->getValue($object, 'children|child')); - } - - public function testGetValueReadsPropertyWithSpecialCharsExceptDot() + /** + * @dataProvider getValidPropertyPaths + */ + public function testGetValue($objectOrArray, $path, $value) { - $array = (object) array('%!@$§' => 'Bernhard'); - - $this->assertEquals('Bernhard', $this->getPropertyAccessor()->getValue($array, '%!@$§')); - } - - public function testGetValueReadsPropertyWithCustomPropertyPath() - { - $object = new Author(); - $object->child = array(); - $object->child['index'] = new Author(); - $object->child['index']->firstName = 'Bernhard'; - - $this->assertEquals('Bernhard', $this->getPropertyAccessor()->getValue($object, 'child[index].firstName')); + $this->assertSame($value, $this->propertyAccessor->getValue($objectOrArray, $path)); } /** + * @dataProvider getPathsWithMissingProperty * @expectedException \Symfony\Component\PropertyAccess\Exception\NoSuchPropertyException */ - public function testGetValueThrowsExceptionIfPropertyIsNotPublic() + public function testGetValueThrowsExceptionIfPropertyNotFound($objectOrArray, $path) { - $this->getPropertyAccessor()->getValue(new Author(), 'privateProperty'); + $this->propertyAccessor->getValue($objectOrArray, $path); } - public function testGetValueReadsGetters() + /** + * @dataProvider getPathsWithMissingIndex + */ + public function testGetValueThrowsNoExceptionIfIndexNotFound($objectOrArray, $path) { - $object = new Author(); - $object->setLastName('Schussek'); - - $this->assertEquals('Schussek', $this->getPropertyAccessor()->getValue($object, 'lastName')); + $this->assertNull($this->propertyAccessor->getValue($objectOrArray, $path)); } - public function testGetValueCamelizesGetterNames() + /** + * @dataProvider getPathsWithMissingIndex + * @expectedException \Symfony\Component\PropertyAccess\Exception\NoSuchIndexException + */ + public function testGetValueThrowsExceptionIfIndexNotFoundAndIndexExceptionsEnabled($objectOrArray, $path) { - $object = new Author(); - $object->setLastName('Schussek'); - - $this->assertEquals('Schussek', $this->getPropertyAccessor()->getValue($object, 'last_name')); + $this->propertyAccessor = new PropertyAccessor(false, true); + $this->propertyAccessor->getValue($objectOrArray, $path); } /** * @expectedException \Symfony\Component\PropertyAccess\Exception\NoSuchPropertyException */ - public function testGetValueThrowsExceptionIfGetterIsNotPublic() + public function testGetValueThrowsExceptionIfNotArrayAccess() { - $this->getPropertyAccessor()->getValue(new Author(), 'privateGetter'); - } - - public function testGetValueReadsIssers() - { - $object = new Author(); - $object->setAustralian(false); - - $this->assertFalse($this->getPropertyAccessor()->getValue($object, 'australian')); - } - - public function testGetValueReadHassers() - { - $object = new Author(); - $object->setReadPermissions(true); - - $this->assertTrue($this->getPropertyAccessor()->getValue($object, 'read_permissions')); + $this->propertyAccessor->getValue(new \stdClass(), '[index]'); } public function testGetValueReadsMagicGet() { - $object = new Magician(); - $object->__set('magicProperty', 'foobar'); - - $this->assertSame('foobar', $this->getPropertyAccessor()->getValue($object, 'magicProperty')); + $this->assertSame('Bernhard', $this->propertyAccessor->getValue(new TestClassMagicGet('Bernhard'), 'magicProperty')); } - /* - * https://github.com/symfony/symfony/pull/4450 - */ + // https://github.com/symfony/symfony/pull/4450 public function testGetValueReadsMagicGetThatReturnsConstant() { - $object = new Magician(); - - $this->assertNull($this->getPropertyAccessor()->getValue($object, 'magicProperty')); + $this->assertSame('constant value', $this->propertyAccessor->getValue(new TestClassMagicGet('Bernhard'), 'constantMagicProperty')); } /** * @expectedException \Symfony\Component\PropertyAccess\Exception\NoSuchPropertyException */ - public function testGetValueThrowsExceptionIfIsserIsNotPublic() + public function testGetValueDoesNotReadMagicCallByDefault() { - $this->getPropertyAccessor()->getValue(new Author(), 'privateIsser'); + $this->propertyAccessor->getValue(new TestClassMagicCall('Bernhard'), 'magicCallProperty'); } - /** - * @expectedException \Symfony\Component\PropertyAccess\Exception\NoSuchPropertyException - */ - public function testGetValueThrowsExceptionIfPropertyDoesNotExist() + public function testGetValueReadsMagicCallIfEnabled() { - $this->getPropertyAccessor()->getValue(new Author(), 'foobar'); + $this->propertyAccessor = new PropertyAccessor(true); + + $this->assertSame('Bernhard', $this->propertyAccessor->getValue(new TestClassMagicCall('Bernhard'), 'magicCallProperty')); + } + + // https://github.com/symfony/symfony/pull/4450 + public function testGetValueReadsMagicCallThatReturnsConstant() + { + $this->propertyAccessor = new PropertyAccessor(true); + + $this->assertSame('constant value', $this->propertyAccessor->getValue(new TestClassMagicCall('Bernhard'), 'constantMagicCallProperty')); } /** @@ -234,7 +174,7 @@ public function testGetValueThrowsExceptionIfPropertyDoesNotExist() */ public function testGetValueThrowsExceptionIfNotObjectOrArray() { - $this->getPropertyAccessor()->getValue('baz', 'foobar'); + $this->propertyAccessor->getValue('baz', 'foobar'); } /** @@ -242,7 +182,7 @@ public function testGetValueThrowsExceptionIfNotObjectOrArray() */ public function testGetValueThrowsExceptionIfNull() { - $this->getPropertyAccessor()->getValue(null, 'foobar'); + $this->propertyAccessor->getValue(null, 'foobar'); } /** @@ -250,90 +190,85 @@ public function testGetValueThrowsExceptionIfNull() */ public function testGetValueThrowsExceptionIfEmpty() { - $this->getPropertyAccessor()->getValue('', 'foobar'); + $this->propertyAccessor->getValue('', 'foobar'); } - public function testSetValueUpdatesArrays() + /** + * @dataProvider getValidPropertyPaths + */ + public function testSetValue($objectOrArray, $path) { - $array = array(); + $this->propertyAccessor->setValue($objectOrArray, $path, 'Updated'); - $this->getPropertyAccessor()->setValue($array, '[firstName]', 'Bernhard'); - - $this->assertEquals(array('firstName' => 'Bernhard'), $array); + $this->assertSame('Updated', $this->propertyAccessor->getValue($objectOrArray, $path)); } /** + * @dataProvider getPathsWithMissingProperty * @expectedException \Symfony\Component\PropertyAccess\Exception\NoSuchPropertyException */ - public function testSetValueThrowsExceptionIfIndexNotationExpected() + public function testSetValueThrowsExceptionIfPropertyNotFound($objectOrArray, $path) { - $array = array(); - - $this->getPropertyAccessor()->setValue($array, 'firstName', 'Bernhard'); + $this->propertyAccessor->setValue($objectOrArray, $path, 'Updated'); } - public function testSetValueUpdatesArraysWithCustomPropertyPath() + /** + * @dataProvider getPathsWithMissingIndex + */ + public function testSetValueThrowsNoExceptionIfIndexNotFound($objectOrArray, $path) { - $array = array(); + $this->propertyAccessor->setValue($objectOrArray, $path, 'Updated'); - $this->getPropertyAccessor()->setValue($array, '[child][index][firstName]', 'Bernhard'); - - $this->assertEquals(array('child' => array('index' => array('firstName' => 'Bernhard'))), $array); + $this->assertSame('Updated', $this->propertyAccessor->getValue($objectOrArray, $path)); } - public function testSetValueUpdatesProperties() + /** + * @dataProvider getPathsWithMissingIndex + */ + public function testSetValueThrowsNoExceptionIfIndexNotFoundAndIndexExceptionsEnabled($objectOrArray, $path) { - $object = new Author(); + $this->propertyAccessor = new PropertyAccessor(false, true); + $this->propertyAccessor->setValue($objectOrArray, $path, 'Updated'); - $this->getPropertyAccessor()->setValue($object, 'firstName', 'Bernhard'); - - $this->assertEquals('Bernhard', $object->firstName); + $this->assertSame('Updated', $this->propertyAccessor->getValue($objectOrArray, $path)); } - public function testSetValueUpdatesPropertiesWithCustomPropertyPath() + /** + * @expectedException \Symfony\Component\PropertyAccess\Exception\NoSuchPropertyException + */ + public function testSetValueThrowsExceptionIfNotArrayAccess() { - $object = new Author(); - $object->child = array(); - $object->child['index'] = new Author(); - - $this->getPropertyAccessor()->setValue($object, 'child[index].firstName', 'Bernhard'); - - $this->assertEquals('Bernhard', $object->child['index']->firstName); + $this->propertyAccessor->setValue(new \stdClass(), '[index]', 'Updated'); } - public function testSetValueUpdateMagicSet() + public function testSetValueUpdatesMagicSet() { - $object = new Magician(); + $author = new TestClassMagicGet('Bernhard'); - $this->getPropertyAccessor()->setValue($object, 'magicProperty', 'foobar'); + $this->propertyAccessor->setValue($author, 'magicProperty', 'Updated'); - $this->assertEquals('foobar', $object->__get('magicProperty')); + $this->assertEquals('Updated', $author->__get('magicProperty')); } - public function testSetValueUpdatesSetters() + /** + * @expectedException \Symfony\Component\PropertyAccess\Exception\NoSuchPropertyException + */ + public function testSetValueDoesNotUpdateMagicCallByDefault() { - $object = new Author(); - - $this->getPropertyAccessor()->setValue($object, 'lastName', 'Schussek'); + $author = new TestClassMagicCall('Bernhard'); - $this->assertEquals('Schussek', $object->getLastName()); + $this->propertyAccessor->setValue($author, 'magicCallProperty', 'Updated'); } - public function testSetValueCamelizesSetterNames() + public function testSetValueUpdatesMagicCallIfEnabled() { - $object = new Author(); + $this->propertyAccessor = new PropertyAccessor(true); - $this->getPropertyAccessor()->setValue($object, 'last_name', 'Schussek'); + $author = new TestClassMagicCall('Bernhard'); - $this->assertEquals('Schussek', $object->getLastName()); - } + $this->propertyAccessor->setValue($author, 'magicCallProperty', 'Updated'); - /** - * @expectedException \Symfony\Component\PropertyAccess\Exception\NoSuchPropertyException - */ - public function testSetValueThrowsExceptionIfGetterIsNotPublic() - { - $this->getPropertyAccessor()->setValue(new Author(), 'privateSetter', 'foobar'); + $this->assertEquals('Updated', $author->__call('getMagicCallProperty', array())); } /** @@ -343,7 +278,7 @@ public function testSetValueThrowsExceptionIfNotObjectOrArray() { $value = 'baz'; - $this->getPropertyAccessor()->setValue($value, 'foobar', 'bam'); + $this->propertyAccessor->setValue($value, 'foobar', 'bam'); } /** @@ -353,7 +288,7 @@ public function testSetValueThrowsExceptionIfNull() { $value = null; - $this->getPropertyAccessor()->setValue($value, 'foobar', 'bam'); + $this->propertyAccessor->setValue($value, 'foobar', 'bam'); } /** @@ -363,54 +298,6 @@ public function testSetValueThrowsExceptionIfEmpty() { $value = ''; - $this->getPropertyAccessor()->setValue($value, 'foobar', 'bam'); + $this->propertyAccessor->setValue($value, 'foobar', 'bam'); } - - /** - * @expectedException \Symfony\Component\PropertyAccess\Exception\NoSuchPropertyException - */ - public function testSetValueFailsIfMagicCallDisabled() - { - $value = new MagicianCall(); - - $this->getPropertyAccessor()->setValue($value, 'foobar', 'bam'); - } - - /** - * @expectedException \Symfony\Component\PropertyAccess\Exception\NoSuchPropertyException - */ - public function testGetValueFailsIfMagicCallDisabled() - { - $value = new MagicianCall(); - - $this->getPropertyAccessor()->getValue($value, 'foobar', 'bam'); - } - - public function testGetValueReadsMagicCall() - { - $propertyAccessor = new PropertyAccessor(true); - $object = new MagicianCall(); - $object->setMagicProperty('foobar'); - - $this->assertSame('foobar', $propertyAccessor->getValue($object, 'magicProperty')); - } - - public function testGetValueReadsMagicCallThatReturnsConstant() - { - $propertyAccessor = new PropertyAccessor(true); - $object = new MagicianCall(); - - $this->assertNull($propertyAccessor->getValue($object, 'MagicProperty')); - } - - public function testSetValueUpdatesMagicCall() - { - $propertyAccessor = new PropertyAccessor(true); - $object = new MagicianCall(); - - $propertyAccessor->setValue($object, 'magicProperty', 'foobar'); - - $this->assertEquals('foobar', $object->getMagicProperty()); - } - } diff --git a/src/Symfony/Component/PropertyAccess/Tests/PropertyAccessorCustomArrayObjectTest.php b/src/Symfony/Component/PropertyAccess/Tests/PropertyAccessorTraversableArrayObjectTest.php similarity index 53% rename from src/Symfony/Component/PropertyAccess/Tests/PropertyAccessorCustomArrayObjectTest.php rename to src/Symfony/Component/PropertyAccess/Tests/PropertyAccessorTraversableArrayObjectTest.php index 7340df720fbf..4e45001176d0 100644 --- a/src/Symfony/Component/PropertyAccess/Tests/PropertyAccessorCustomArrayObjectTest.php +++ b/src/Symfony/Component/PropertyAccess/Tests/PropertyAccessorTraversableArrayObjectTest.php @@ -11,12 +11,12 @@ namespace Symfony\Component\PropertyAccess\Tests; -use Symfony\Component\PropertyAccess\Tests\Fixtures\CustomArrayObject; +use Symfony\Component\PropertyAccess\Tests\Fixtures\TraversableArrayObject; -class PropertyAccessorCustomArrayObjectTest extends PropertyAccessorCollectionTest +class PropertyAccessorTraversableArrayObjectTest extends PropertyAccessorCollectionTest { - protected function getCollection(array $array) + protected function getContainer(array $array) { - return new CustomArrayObject($array); + return new TraversableArrayObject($array); } }