-
-
Notifications
You must be signed in to change notification settings - Fork 9.7k
Closed
Labels
Description
This TestCase demonstrates the issue:
namespace Test;
use Symfony\Component\PropertyAccess\PropertyAccess;
class Bar {
private $foo;
public function setFoo($foo) {
$this->foo = $foo;
}
public function getFoo() {
return $this->foo;
}
}
class A {
private $bars;
public function __construct() {
$this->bars = array(
'a' => new Bar(),
'b' => new Bar(),
);
}
public function getBars() {
return $this->bars;
}
}
class MyTest extends \PHPUnit_Framework_TestCase {
public function testPropertyAccessor() {
$accessor = PropertyAccess::createPropertyAccessor();
$a = new A();
$accessor->setValue($a, 'bars[a].foo', 'baz');
$this->assertEquals('baz', $a->getBars()['a']->getFoo());
}
}
I'm expecting the test case to pass.
Instead the following exception is thrown:
Symfony\Component\PropertyAccess\Exception\NoSuchPropertyException: Neither the property "bars" nor one of the methods "addBar()"/"removeBar()", "setBars()", "bars()", "__set()" or "__call()" exist and have public access in class "Test\A"
I don't understand why PropertyAccessor wants to replace the "bars" array on my object.
I can work around the issue by adding an empty setBars method to A, then the test case passes. So it's not like setting a new array is needed.