entity: assoc array to stdClass

This commit is contained in:
Yuri Kuznetsov
2024-01-11 16:47:37 +02:00
parent 5c34d57012
commit cb972fdf17
2 changed files with 37 additions and 0 deletions
+6
View File
@@ -1007,6 +1007,12 @@ class BaseEntity implements Entity
}
if (is_array($item)) {
if (!array_is_list($item)) {
$copy[$i] = $this->cloneObject((object) $item);
continue;
}
$copy[$i] = $this->cloneArray($item);
continue;
+31
View File
@@ -340,6 +340,37 @@ class EntityTest extends TestCase
$this->assertEquals(json_decode($value), $entity->get('object'));
}
public function testGetJsonArray(): void
{
$entity = $this->createEntity('Job');
$entity->set('array', [0, 1]);
$this->assertEquals([0, 1], $entity->get('array'));
$entity->set('array', [[0], [1]]);
$this->assertEquals([[0], [1]], $entity->get('array'));
$entity->set('array', [
(object) ['test' => 0],
(object) ['test' => 1],
]);
$this->assertEquals([
(object) ['test' => 0],
(object) ['test' => 1],
], $entity->get('array'));
$entity->set('array', [
['test' => 0],
['test' => 1],
]);
$this->assertEquals([
(object) ['test' => 0],
(object) ['test' => 1],
], $entity->get('array'));
}
public function testSetWrongType()
{
$entity = $this->createEntity('Test');