diff --git a/src/Symfony/Component/PropertyAccess/Tests/PropertyAccessorTest.php b/src/Symfony/Component/PropertyAccess/Tests/PropertyAccessorTest.php index e22ca097be56d..42918aadc469b 100644 --- a/src/Symfony/Component/PropertyAccess/Tests/PropertyAccessorTest.php +++ b/src/Symfony/Component/PropertyAccess/Tests/PropertyAccessorTest.php @@ -45,32 +45,28 @@ public function testGetValueThrowsExceptionIfIndexNotationExpected() $this->propertyAccessor->getValue($array, 'firstName'); } - public function testGetValueReadsZeroIndex() - { - $array = array('Bernhard'); - - $this->assertEquals('Bernhard', $this->propertyAccessor->getValue($array, '[0]')); - } - - public function testGetValueReadsIndexWithSpecialChars() + /** + * @dataProvider provideValueReads + */ + public function testGetValueReads($propertyPath, $expectedValue, $testedData) { - $array = array('%!@$§.' => 'Bernhard'); - - $this->assertEquals('Bernhard', $this->propertyAccessor->getValue($array, '[%!@$§.]')); + $this->assertEquals($expectedValue, $this->propertyAccessor->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->propertyAccessor->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->propertyAccessor->getValue($array, '[child][index][firstName]')); + array('[@name]', 'Thunderer', array('@name' => 'Thunderer')), + array('@name', 'Thunderer', (object) array('@name' => 'Thunderer')), + array('_name', 'Thunderer', (object) array('_name' => 'Thunderer')), + ); } public function testGetValueReadsArrayWithMissingIndexForCustomPropertyPath() @@ -97,13 +93,6 @@ public function testGetValueIgnoresSingular() $this->assertEquals('Many', $this->propertyAccessor->getValue($object, 'children|child')); } - public function testGetValueReadsPropertyWithSpecialCharsExceptDot() - { - $array = (object) array('%!@$§' => 'Bernhard'); - - $this->assertEquals('Bernhard', $this->propertyAccessor->getValue($array, '%!@$§')); - } - public function testGetValueReadsPropertyWithCustomPropertyPath() { $object = new Author();