From f93fe9906efa6d0764e65fc5035a99bd2f8c9cfe Mon Sep 17 00:00:00 2001 From: Tomasz Kowalczyk Date: Sat, 14 Dec 2013 14:14:19 +0100 Subject: [PATCH 1/2] Added test cases for issue #8930 --- .../Tests/PropertyAccessorTest.php | 37 +++++++++---------- 1 file changed, 17 insertions(+), 20 deletions(-) diff --git a/src/Symfony/Component/PropertyAccess/Tests/PropertyAccessorTest.php b/src/Symfony/Component/PropertyAccess/Tests/PropertyAccessorTest.php index a64930a93a7ba..9e8e7bcc5bf1b 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() From 08ce8fc2d2586f4100e0e106479864638b7ada96 Mon Sep 17 00:00:00 2001 From: Tomasz Kowalczyk Date: Sat, 14 Dec 2013 14:56:59 +0100 Subject: [PATCH 2/2] CS fixes --- .../Component/PropertyAccess/Tests/PropertyAccessorTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Component/PropertyAccess/Tests/PropertyAccessorTest.php b/src/Symfony/Component/PropertyAccess/Tests/PropertyAccessorTest.php index 9e8e7bcc5bf1b..8dc395b90bc9f 100644 --- a/src/Symfony/Component/PropertyAccess/Tests/PropertyAccessorTest.php +++ b/src/Symfony/Component/PropertyAccess/Tests/PropertyAccessorTest.php @@ -92,7 +92,7 @@ public function provideValueReads() array('[@name]', 'Thunderer', array('@name' => 'Thunderer')), array('@name', 'Thunderer', (object) array('@name' => 'Thunderer')), array('_name', 'Thunderer', (object) array('_name' => 'Thunderer')), - ); + ); } public function testGetValueReadsArrayWithMissingIndexForCustomPropertyPath()