8000 Added test cases for issue #8930 by thunderer · Pull Request #9767 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

Added test cases for issue #8930 #9767

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 17 additions & 20 deletions src/Symfony/Component/PropertyAccess/Tests/PropertyAccessorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
0