Recursively iterates through the given array and turns objects
into an arrays containing the identity of the domain object.
public convertObjectsToIdentityArrays ( array $array ) : array | ||
$array | array | The array to be iterated over |
Résultat | array | The modified array without objects |
/** * @test */ public function convertObjectsToIdentityArraysConvertsObjectsInIterators() { $object1 = new \stdClass(); $object2 = new \stdClass(); $this->abstractPersistenceManager->expects($this->at(0))->method('getIdentifierByObject')->with($object1)->will($this->returnValue('identifier1')); $this->abstractPersistenceManager->expects($this->at(1))->method('getIdentifierByObject')->with($object2)->will($this->returnValue('identifier2')); $originalArray = ['foo' => 'bar', 'object1' => $object1, 'baz' => new \ArrayObject(['object2' => $object2])]; $expectedResult = ['foo' => 'bar', 'object1' => ['__identity' => 'identifier1'], 'baz' => ['object2' => ['__identity' => 'identifier2']]]; $actualResult = $this->abstractPersistenceManager->convertObjectsToIdentityArrays($originalArray); $this->assertEquals($expectedResult, $actualResult); }