Skip to content

Commit

Permalink
Add test to document that mixed properties with objects don't work.
Browse files Browse the repository at this point in the history
  • Loading branch information
Crell committed Oct 20, 2023
1 parent 76a7656 commit df58388
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 8 deletions.
4 changes: 1 addition & 3 deletions src/PropertyHandler/MixedExporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,9 @@ class MixedExporter implements Importer, Exporter
{
public function exportValue(Serializer $serializer, Field $field, mixed $value, mixed $runningValue): mixed
{
$type = \get_debug_type($value);

return $serializer->serialize($value, $runningValue, Field::create(
serializedName: $field->serializedName,
phpType: $type,
phpType: \get_debug_type($value),
));
}

Expand Down
1 change: 0 additions & 1 deletion tests/ArrayBasedFormatterTestCases.php
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,5 @@ public function non_sequence_arrays_are_normalized_to_sequences_validate(mixed $

self::assertIsList($toTest['strict']);
self::assertIsList($toTest['nonstrict']);

}
}
23 changes: 19 additions & 4 deletions tests/SerdeTestCases.php
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,6 @@ protected function all_fields_validate(mixed $serialized): void

}


#[Test]
public function float_fields_take_ints(): void
{
Expand Down Expand Up @@ -1237,16 +1236,32 @@ public static function mixed_val_property_examples(): iterable
yield 'float' => [new MixedVal(3.14)];
yield 'sequence' => [new MixedVal(['a', 'b', 'c'])];
yield 'dict' => [new MixedVal(['a' => 'A', 'b' => 'B', 'c' => 'C'])];
// Objects can't work, because they cannot be imported without type data.
// Exporting might. Todo for later.
//yield 'object' => [new Point(3, 4, 5)];
}

public function mixed_val_property_validate(mixed $serialized, mixed $data): void
{

}

/**
* This isn't a desired feature; it's just confirmation for the future why it is how it is.
*/
#[Test]
public function mixed_val_object_does_not_serialize(): void
{
// MixedExporter sends the property value back through the Serialize pipeline
// a second time with a new Field definition. However, that trips the circular
// reference detection. Ideally we will fix that somehow, but I'm not sure how.
// Importing an object to mixed will never work correctly.
$this->expectException(CircularReferenceDetected::class);

$data = new MixedVal(new Point(3, 4, 5));

$s = new SerdeCommon(formatters: $this->formatters);

$serialized = $s->serialize($data, $this->format);
}

#[Test]
public function generator_property_is_run_out(): void
{
Expand Down

0 comments on commit df58388

Please sign in to comment.