Skip to content

Commit

Permalink
Merge branch '7.0' into 7.1
Browse files Browse the repository at this point in the history
* 7.0:
  fix compatibility with Redis Relay 0.8.1
  use more entropy with uniqid()
  [Cache] Improve `dbindex` DSN parameter parsing
  Support for PHP-CS-Fixer's parallel runner
  use more entropy with uniqid()
  [Contracts][HttpClient] Skip tests when zlib's `ob_gzhandler()` doesn't exist
  [Serializer] Raise correct exception in ArrayDenormalizer
  • Loading branch information
xabbuh committed Jul 17, 2024
2 parents d207767 + 79b073c commit 0d5ddac
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 9 deletions.
12 changes: 6 additions & 6 deletions Debug/TraceableSerializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function __construct(

public function serialize(mixed $data, string $format, array $context = []): string
{
$context[self::DEBUG_TRACE_ID] = $traceId = uniqid();
$context[self::DEBUG_TRACE_ID] = $traceId = uniqid('', true);

$startTime = microtime(true);
$result = $this->serializer->serialize($data, $format, $context);
Expand All @@ -52,7 +52,7 @@ public function serialize(mixed $data, string $format, array $context = []): str

public function deserialize(mixed $data, string $type, string $format, array $context = []): mixed
{
$context[self::DEBUG_TRACE_ID] = $traceId = uniqid();
$context[self::DEBUG_TRACE_ID] = $traceId = uniqid('', true);

$startTime = microtime(true);
$result = $this->serializer->deserialize($data, $type, $format, $context);
Expand All @@ -67,7 +67,7 @@ public function deserialize(mixed $data, string $type, string $format, array $co

public function normalize(mixed $object, ?string $format = null, array $context = []): array|string|int|float|bool|\ArrayObject|null
{
$context[self::DEBUG_TRACE_ID] = $traceId = uniqid();
$context[self::DEBUG_TRACE_ID] = $traceId = uniqid('', true);

$startTime = microtime(true);
$result = $this->serializer->normalize($object, $format, $context);
Expand All @@ -82,7 +82,7 @@ public function normalize(mixed $object, ?string $format = null, array $context

public function denormalize(mixed $data, string $type, ?string $format = null, array $context = []): mixed
{
$context[self::DEBUG_TRACE_ID] = $traceId = uniqid();
$context[self::DEBUG_TRACE_ID] = $traceId = uniqid('', true);

$startTime = microtime(true);
$result = $this->serializer->denormalize($data, $type, $format, $context);
Expand All @@ -97,7 +97,7 @@ public function denormalize(mixed $data, string $type, ?string $format = null, a

public function encode(mixed $data, string $format, array $context = []): string
{
$context[self::DEBUG_TRACE_ID] = $traceId = uniqid();
$context[self::DEBUG_TRACE_ID] = $traceId = uniqid('', true);

$startTime = microtime(true);
$result = $this->serializer->encode($data, $format, $context);
Expand All @@ -112,7 +112,7 @@ public function encode(mixed $data, string $format, array $context = []): string

public function decode(string $data, string $format, array $context = []): mixed
{
$context[self::DEBUG_TRACE_ID] = $traceId = uniqid();
$context[self::DEBUG_TRACE_ID] = $traceId = uniqid('', true);

$startTime = microtime(true);
$result = $this->serializer->decode($data, $format, $context);
Expand Down
4 changes: 2 additions & 2 deletions Normalizer/ArrayDenormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function getSupportedTypes(?string $format): array
*/
public function denormalize(mixed $data, string $type, ?string $format = null, array $context = []): array
{
if (null === $this->denormalizer) {
if (!isset($this->denormalizer)) {
throw new BadMethodCallException('Please set a denormalizer before calling denormalize()!');
}
if (!\is_array($data)) {
Expand Down Expand Up @@ -79,7 +79,7 @@ public function denormalize(mixed $data, string $type, ?string $format = null, a

public function supportsDenormalization(mixed $data, string $type, ?string $format = null, array $context = []): bool
{
if (null === $this->denormalizer) {
if (!isset($this->denormalizer)) {
throw new BadMethodCallException(sprintf('The nested denormalizer needs to be set to allow "%s()" to be used.', __METHOD__));
}

Expand Down
2 changes: 1 addition & 1 deletion Tests/Mapping/Factory/ClassMetadataFactoryCompilerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ final class ClassMetadataFactoryCompilerTest extends TestCase

protected function setUp(): void
{
$this->dumpPath = sys_get_temp_dir().\DIRECTORY_SEPARATOR.'php_serializer_metadata.'.uniqid('CompiledClassMetadataFactory').'.php';
$this->dumpPath = sys_get_temp_dir().\DIRECTORY_SEPARATOR.'php_serializer_metadata.'.uniqid('CompiledClassMetadataFactory', true).'.php';
}

protected function tearDown(): void
Expand Down
16 changes: 16 additions & 0 deletions Tests/Normalizer/ArrayDenormalizerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,22 @@ public function testSupportsNoArray()
)
);
}

public function testDenormalizeWithoutDenormalizer()
{
$arrayDenormalizer = new ArrayDenormalizer();

$this->expectException(\BadMethodCallException::class);
$arrayDenormalizer->denormalize([], 'string[]');
}

public function testSupportsDenormalizationWithoutDenormalizer()
{
$arrayDenormalizer = new ArrayDenormalizer();

$this->expectException(\BadMethodCallException::class);
$arrayDenormalizer->supportsDenormalization([], 'string[]');
}
}

class ArrayDummy
Expand Down

0 comments on commit 0d5ddac

Please sign in to comment.