passing properties to recursive call if properties of top object are not specified

fixes #7717
close #10960
This commit is contained in:
Vladimir Khramov
2016-02-25 18:03:43 +10:00
committed by Carsten Brandt
parent 627233715b
commit c6d04644d3
3 changed files with 42 additions and 1 deletions

View File

@@ -27,6 +27,7 @@ class Post2 extends Object
class Post3 extends Object
{
public $id = 33;
/** @var Object */
public $subObject;
public function init()
@@ -88,6 +89,45 @@ class ArrayHelperTest extends TestCase
'content' => 'test',
],
], ArrayHelper::toArray($object));
//recursive with attributes of object and subobject
$this->assertEquals([
'id' => 33,
'id_plus_1' => 34,
'subObject' => [
'id' => 123,
'id_plus_1' => 124,
],
], ArrayHelper::toArray($object, [
$object->className() => [
'id', 'subObject',
'id_plus_1' => function ($post) {
return $post->id+1;
}
],
$object->subObject->className() => [
'id',
'id_plus_1' => function ($post) {
return $post->id+1;
}
],
]));
//recursive with attributes of subobject only
$this->assertEquals([
'id' => 33,
'subObject' => [
'id' => 123,
'id_plus_1' => 124,
],
], ArrayHelper::toArray($object, [
$object->subObject->className() => [
'id',
'id_plus_1' => function ($post) {
return $post->id+1;
}
],
]));
}
public function testRemove()