UnwrappingDenormalizer example

/** * @author Eduard Bulava <bulavaeduard@gmail.com> */
class UnwrappinDenormalizerTest extends TestCase
{
    private UnwrappingDenormalizer $denormalizer;
    private MockObject&Serializer $serializer;

    protected function setUp(): void
    {
        $this->serializer = $this->createMock(Serializer::class);
        $this->denormalizer = new UnwrappingDenormalizer();
        $this->denormalizer->setSerializer($this->serializer);
    }

    public function testSupportsNormalization()
    {
        $this->assertTrue($this->denormalizer->supportsDenormalization([], 'stdClass', 'any', [UnwrappingDenormalizer::UNWRAP_PATH => '[baz][inner]']));
        $this->assertFalse($this->denormalizer->supportsDenormalization([], 'stdClass', 'any', [UnwrappingDenormalizer::UNWRAP_PATH => '[baz][inner]', 'unwrapped' => true]));
        $this->assertFalse($this->denormalizer->supportsDenormalization([], 'stdClass', 'any', []));
    }

    public function testDenormalize()
    {
$fooDummyObjects = $obj->getFoo();
        $this->assertCount(1, $fooDummyObjects);

        $fooDummyObject = $fooDummyObjects[0];
        $this->assertInstanceOf(FooImplementationDummy::class$fooDummyObject);
        $this->assertSame('bar', $fooDummyObject->name);
    }

    public function testDeserializeWrappedScalar()
    {
        $serializer = new Serializer([new UnwrappingDenormalizer()]['json' => new JsonEncoder()]);

        $this->assertSame(42, $serializer->deserialize('{"wrapper": 42}', 'int', 'json', [UnwrappingDenormalizer::UNWRAP_PATH => '[wrapper]']));
    }

    public function testUnionTypeDeserializable()
    {
        $classMetadataFactory = new ClassMetadataFactory(new AnnotationLoader());
        $extractor = new PropertyInfoExtractor([][new PhpDocExtractor()new ReflectionExtractor()]);
        $serializer = new Serializer(
            [
                new DateTimeNormalizer(),
                
Home | Imprint | This part of the site doesn't use cookies.