merged branch cystbear/PropertyAccessor-CustomArrayObject-Fix (PR #7320)

This PR was submitted for the master branch but it was merged into the 2.2 branch instead (closes #7320).

Commits
-------

7ff2d52 Property accessor custom array object fix

Discussion
----------

Property accessor custom array object fix

Copied `Symfony\Component\Form\Tests\Fixtures\CustomArrayObject` to Fixtures dir, and used it in tests to be able run tests separately from Form component,
This commit is contained in:
Fabien Potencier 2013-03-11 18:33:58 +01:00
commit 26a7222b06
2 changed files with 71 additions and 1 deletions

View File

@ -0,0 +1,70 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* 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);
}
}

View File

@ -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
{