From b4c818ff9c8a97cfede8d170c4e7a1358104302d Mon Sep 17 00:00:00 2001 From: Oleg Zinchenko <1cdecoder@gmail.com> Date: Sun, 10 Mar 2013 02:46:05 +0200 Subject: [PATCH 1/2] added CustomArrayObject. Actually copied it from `Symfony\Component\Form\Tests\Fixtures\CustomArrayObject` --- .../Tests/Fixtures/CustomArrayObject.php | 70 +++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 src/Symfony/Component/PropertyAccess/Tests/Fixtures/CustomArrayObject.php diff --git a/src/Symfony/Component/PropertyAccess/Tests/Fixtures/CustomArrayObject.php b/src/Symfony/Component/PropertyAccess/Tests/Fixtures/CustomArrayObject.php new file mode 100644 index 0000000000000..cd23f7033fc6f --- /dev/null +++ b/src/Symfony/Component/PropertyAccess/Tests/Fixtures/CustomArrayObject.php @@ -0,0 +1,70 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\PropertyAccess\Tests\Fixtures; + +/** + * This class is a hand written simplified version of PHP native `ArrayObject` + * class, to show that it behaves differently than the PHP native implementation. + */ +class CustomArrayObject implements \ArrayAccess, \IteratorAggregate, \Countable, \Serializable +{ + private $array; + + public function __construct(array $array = null) + { + $this->array = $array ?: array(); + } + + public function offsetExists($offset) + { + return array_key_exists($offset, $this->array); + } + + public function offsetGet($offset) + { + return $this->array[$offset]; + } + + public function offsetSet($offset, $value) + { + if (null === $offset) { + $this->array[] = $value; + } else { + $this->array[$offset] = $value; + } + } + + public function offsetUnset($offset) + { + unset($this->array[$offset]); + } + + public function getIterator() + { + return new \ArrayIterator($this->array); + } + + public function count() + { + return count($this->array); + } + + public function serialize() + { + return serialize($this->array); + } + + public function unserialize($serialized) + { + $this->array = (array) unserialize((string) $serialized); + } +} From e972dc79c3a69b5dd4aa5996bba9a6ace2797b85 Mon Sep 17 00:00:00 2001 From: Oleg Zinchenko <1cdecoder@gmail.com> Date: Sun, 10 Mar 2013 02:47:10 +0200 Subject: [PATCH 2/2] used own CustomArrayObject instead of `Symfony\Component\Form\Tests\Fixtures\CustomArrayObject`. To be able run tests separately from Form component, --- .../Tests/PropertyAccessorCustomArrayObjectTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Component/PropertyAccess/Tests/PropertyAccessorCustomArrayObjectTest.php b/src/Symfony/Component/PropertyAccess/Tests/PropertyAccessorCustomArrayObjectTest.php index 369614c70f7f9..7340df720fbf9 100644 --- a/src/Symfony/Component/PropertyAccess/Tests/PropertyAccessorCustomArrayObjectTest.php +++ b/src/Symfony/Component/PropertyAccess/Tests/PropertyAccessorCustomArrayObjectTest.php @@ -11,7 +11,7 @@ namespace Symfony\Component\PropertyAccess\Tests; -use Symfony\Component\Form\Tests\Fixtures\CustomArrayObject; +use Symfony\Component\PropertyAccess\Tests\Fixtures\CustomArrayObject; class PropertyAccessorCustomArrayObjectTest extends PropertyAccessorCollectionTest {