diff --git a/src/Symfony/Component/PropertyAccess/Tests/PropertyAccessorTest.php b/src/Symfony/Component/PropertyAccess/Tests/PropertyAccessorTest.php index a64930a93a7b..8dc395b90bc9 100644 --- a/src/Symfony/Component/PropertyAccess/Tests/PropertyAccessorTest.php +++ b/src/Symfony/Component/PropertyAccess/Tests/PropertyAccessorTest.php @@ -70,32 +70,29 @@ public function testGetValueThrowsExceptionIfIndexNotationExpected() $this->getPropertyAccessor()->getValue($array, 'firstName'); } - public function testGetValueReadsZeroIndex() - { - $array = array('Bernhard'); - - $this->assertEquals('Bernhard', $this->getPropertyAccessor()->getValue($array, '[0]')); - } - - public function testGetValueReadsIndexWithSpecialChars() + /** + * @dataProvider provideValueReads + */ + public function testGetValueReads($propertyPath, $expectedValue, $testedData) { - $array = array('%!@$§.' => 'Bernhard'); - - $this->assertEquals('Bernhard', $this->getPropertyAccessor()->getValue($array, '[%!@$§.]')); + $this->assertEquals($expectedValue, $this->getPropertyAccessor()->getValue($testedData, $propertyPath)); } - public function testGetValueReadsNestedIndexWithSpecialChars() + public function provideValueReads() { - $array = array('root' => array('%!@$§.' => 'Bernhard')); + return array( + array('%!@$§', 'Bernhard', (object) array('%!@$§' => 'Bernhard')), + array('[0]', 'Bernhard', array('Bernhard')), + array('[%!@$§.]', 'Bernhard', array('%!@$§.' => 'Bernhard')), - $this->assertEquals('Bernhard', $this->getPropertyAccessor()->getValue($array, '[root][%!@$§.]')); - } - - public function testGetValueReadsArrayWithCustomPropertyPath() - { - $array = array('child' => array('index' => array('firstName' => 'Bernhard'))); + array('[root][%!@$§.]', 'Bernhard', array('root' => array('%!@$§.' => 'Bernhard'))), + array('[child][index][firstName]', 'Bernhard', array('child' => array('index' => array('firstName' => 'Bernhard')))), - $this->assertEquals('Bernhard', $this->getPropertyAccessor()->getValue($array, '[child][index][firstName]')); + // additional tests for #8930 + array('[@name]', 'Thunderer', array('@name' => 'Thunderer')), + array('@name', 'Thunderer', (object) array('@name' => 'Thunderer')), + array('_name', 'Thunderer', (object) array('_name' => 'Thunderer')), + ); } public function testGetValueReadsArrayWithMissingIndexForCustomPropertyPath()