Skip to content

Commit

Permalink
Merge branch '6.1' into 6.2
Browse files Browse the repository at this point in the history
* 6.1:
  Fix integration test gha
  Update RedisTrait.php
  Use static methods inside data providers
  [VarExporter] Fix exporting classes with __unserialize() but not __serialize()
  [Validator] Fix IBAN format for Tunisia and Mauritania
  [Workflow] Allow spaces in place names so the PUML dump doesn't break
  • Loading branch information
nicolas-grekas committed Dec 22, 2022
2 parents 72b9203 + 5d3feff commit d055d12
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Internal/Exporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ public static function prepare($values, $objectsPool, &$refsPool, &$objectsCount
}
if (null !== $sleep) {
if (!isset($sleep[$n]) || ($i && $c !== $class)) {
unset($arrayValue[$name]);
continue;
}
$sleep[$n] = false;
Expand All @@ -166,6 +167,9 @@ public static function prepare($values, $objectsPool, &$refsPool, &$objectsCount
}
}
}
if (method_exists($class, '__unserialize')) {
$properties = $arrayValue;
}

prepare_value:
$objectsPool[$value] = [$id = \count($objectsPool)];
Expand Down
15 changes: 15 additions & 0 deletions Tests/Fixtures/__unserialize-but-no-__serialize.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

return \Symfony\Component\VarExporter\Internal\Hydrator::hydrate(
$o = [
clone (\Symfony\Component\VarExporter\Internal\Registry::$prototypes['Symfony\\Component\\VarExporter\\Tests\\__UnserializeButNo__Serialize'] ?? \Symfony\Component\VarExporter\Internal\Registry::p('Symfony\\Component\\VarExporter\\Tests\\__UnserializeButNo__Serialize')),
],
null,
[],
$o[0],
[
[
'foo' => 'ccc',
],
]
);
17 changes: 17 additions & 0 deletions Tests/VarExporterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,8 @@ public function provideExport()

yield ['php74-serializable', new Php74Serializable()];

yield ['__unserialize-but-no-__serialize', new __UnserializeButNo__Serialize()];

yield ['unit-enum', [FooUnitEnum::Bar], true];
yield ['readonly', new FooReadonly('k', 'v')];
}
Expand Down Expand Up @@ -437,3 +439,18 @@ public function unserialize($ser)
class ArrayObject extends \ArrayObject
{
}

class __UnserializeButNo__Serialize
{
public $foo;

public function __construct()
{
$this->foo = 'ccc';
}

public function __unserialize(array $data): void
{
$this->foo = $data['foo'];
}
}

0 comments on commit d055d12

Please sign in to comment.