Skip to content

Commit

Permalink
Merge branch '6.3' into 6.4
Browse files Browse the repository at this point in the history
* 6.3:
  [WebProfilerBundle] Fix JS error when evaluating scripts
  don't fail when optional dependencies are not present
  fix syntax error on PHP 7.2
  Do not instantiate object if it is not instantiable
  Add missing translation for Uzbek (uz)
  [CI] Show exit code when job fails
  [CI] Use stable version of psalm
  Add check for lazy object interface
  [Notifier] [Bridges] Provide EventDispatcher and HttpClient to the transports
  • Loading branch information
xabbuh committed Dec 21, 2023
2 parents 1073a69 + daac4e8 commit ff92113
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
9 changes: 9 additions & 0 deletions Normalizer/AbstractNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,15 @@ protected function instantiateObject(array &$data, string $class, array &$contex

unset($context['has_constructor']);

if (!$reflectionClass->isInstantiable()) {
throw NotNormalizableValueException::createForUnexpectedDataType(
sprintf('Failed to create object because the class "%s" is not instantiable.', $class),
$data,
['unknown'],
$context['deserialization_path'] ?? null
);
}

return new $class();
}

Expand Down
14 changes: 14 additions & 0 deletions Tests/Normalizer/AbstractNormalizerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use Symfony\Component\PropertyInfo\Extractor\PhpDocExtractor;
use Symfony\Component\Serializer\Encoder\JsonEncoder;
use Symfony\Component\Serializer\Exception\MissingConstructorArgumentsException;
use Symfony\Component\Serializer\Exception\NotNormalizableValueException;
use Symfony\Component\Serializer\Mapping\AttributeMetadata;
use Symfony\Component\Serializer\Mapping\ClassMetadata;
use Symfony\Component\Serializer\Mapping\Factory\ClassMetadataFactory;
Expand All @@ -33,6 +34,7 @@
use Symfony\Component\Serializer\Tests\Fixtures\NullableOptionalConstructorArgumentDummy;
use Symfony\Component\Serializer\Tests\Fixtures\StaticConstructorDummy;
use Symfony\Component\Serializer\Tests\Fixtures\StaticConstructorNormalizer;
use Symfony\Component\Serializer\Tests\Fixtures\UnitEnumDummy;
use Symfony\Component\Serializer\Tests\Fixtures\VariadicConstructorTypedArgsDummy;

/**
Expand Down Expand Up @@ -280,4 +282,16 @@ public function testIgnore()

$this->assertSame([], $normalizer->normalize($dummy));
}

/**
* @requires PHP 8.1
*/
public function testDenormalizeWhenObjectNotInstantiable()
{
$this->expectException(NotNormalizableValueException::class);

$normalizer = new ObjectNormalizer();

$normalizer->denormalize('{}', UnitEnumDummy::class);
}
}

0 comments on commit ff92113

Please sign in to comment.