diff --git a/Debug/TraceableSerializer.php b/Debug/TraceableSerializer.php index f3d14a2b..9cf7bad8 100644 --- a/Debug/TraceableSerializer.php +++ b/Debug/TraceableSerializer.php @@ -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); @@ -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); @@ -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); @@ -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); @@ -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); @@ -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); diff --git a/Normalizer/ArrayDenormalizer.php b/Normalizer/ArrayDenormalizer.php index 1bd6c54b..347030c2 100644 --- a/Normalizer/ArrayDenormalizer.php +++ b/Normalizer/ArrayDenormalizer.php @@ -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)) { @@ -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__)); } diff --git a/Tests/Mapping/Factory/ClassMetadataFactoryCompilerTest.php b/Tests/Mapping/Factory/ClassMetadataFactoryCompilerTest.php index 1826d3dc..20b05721 100644 --- a/Tests/Mapping/Factory/ClassMetadataFactoryCompilerTest.php +++ b/Tests/Mapping/Factory/ClassMetadataFactoryCompilerTest.php @@ -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 diff --git a/Tests/Normalizer/ArrayDenormalizerTest.php b/Tests/Normalizer/ArrayDenormalizerTest.php index be4a30d8..b60f57ba 100644 --- a/Tests/Normalizer/ArrayDenormalizerTest.php +++ b/Tests/Normalizer/ArrayDenormalizerTest.php @@ -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