Skip to content

Commit 24ad367

Browse files
committed
handle embedded fields better
Signed-off-by: Robert Landers <landers.robert@gmail.com>
1 parent 1fa9f8d commit 24ad367

2 files changed

Lines changed: 13 additions & 3 deletions

File tree

src/State/Exporter.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,11 @@ public function canExport(Field $field, mixed $value, string $format): bool
3131
public function importValue(Deserializer $deserializer, Field $field, mixed $source): mixed
3232
{
3333
$reflectedRecord = new ReflectionClass($field->phpType);
34-
error_log(print_r($source, true));
35-
if ($source === null || $source['root'] === null) {
34+
if ($source === null || $source[$field->phpName] === null) {
3635
return null;
3736
}
3837

39-
$record = $reflectedRecord->getMethod('fromArgs')->invoke(null, ...($source['root']));
38+
$record = $reflectedRecord->getMethod('fromArgs')->invoke(null, ...($source[$field->phpName]));
4039

4140
return $record;
4241
}

tests/Unit/RecordTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
<?php
22

3+
use Bottledcode\DurablePhp\Events\RaiseEvent;
4+
use Bottledcode\DurablePhp\Events\WithEntity;
35
use Bottledcode\DurablePhp\State\EntityId;
6+
use Bottledcode\DurablePhp\State\Ids\StateId;
47
use Bottledcode\DurablePhp\State\OrchestrationInstance;
58
use Bottledcode\DurablePhp\State\Serializer;
69

@@ -20,3 +23,11 @@
2023
$result = Serializer::deserialize($result, OrchestrationInstance::class);
2124
expect($result)->toBe($record);
2225
});
26+
27+
it('can serialize an event', function (): void {
28+
$entity = EntityId('name', 'id');
29+
$event = WithEntity::forInstance(StateId::fromEntityId($entity), RaiseEvent::forOperation('get', ['test' => 'test']));
30+
$result = Serializer::serialize($event);
31+
$result = Serializer::deserialize($result, WithEntity::class);
32+
expect($result->target)->toBe($event->target);
33+
});

0 commit comments

Comments
 (0)