Repository: symfony/symfony
File: src/Symfony/Component/Serializer/Tests/Normalizer/AbstractObjectNormalizerTest.php (PHP)

Code before:
                    );
                }

                throw new InvalidArgumentException();
            }

            public function hasMetadataFor($value): bool
            {
                return AbstractDummy::class === $value;
            }
        };

        $discriminatorResolver = new ClassDiscriminatorFromClassMetadata($loaderMock);
        $normalizer = new AbstractObjectNormalizerDummy($factory, null, new PhpDocExtractor(), $discriminatorResolver);
        $serializer = new Serializer([$normalizer]);
        $normalizer->setSerializer($serializer);
        $normalizedData = $normalizer->denormalize(['foo' => 'foo', 'baz' => 'baz', 'quux' => ['value' => 'quux'], 'type' => $typeValue], AbstractDummy::class);

        if ($shouldFail) {
            $this->fail('Expected exception not thrown.');
        }

        $this->assertInstanceOf(DummyFirstChildQuux::class, $normalizedData->quux);
    }

    public function provideInvalidDiscriminatorTypes()
    {
        $toStringObject = new class() {
            public function __toString()
            {
                return 'first';
            }
        };

        return [
            [[], true],
            [new StdClass(), true],
            [123, true],
            [false, true],
            ['first', false],
            [$toStringObject, false],
        ];
    }

    public function testDenormalizeWithDiscriminatorMapUsesCorrectClassname()
    {
        $factory = new ClassMetadataFactory(new AttributeLoader());

        $loaderMock = new class implements ClassMetadataFactoryInterface {
            public function getMetadataFor($value): ClassMetadataInterface
            {

Review comment (suggestion):
```suggestion
    /**
     * @return iterable<array{0: mixed, 1: bool}>
     */
    public function provideInvalidDiscriminatorTypes(): iterable
```


Code after:
                }

                throw new InvalidArgumentException();
            }

            public function hasMetadataFor($value): bool
            {
                return AbstractDummy::class === $value;
            }
        };

        $discriminatorResolver = new ClassDiscriminatorFromClassMetadata($loaderMock);
        $normalizer = new AbstractObjectNormalizerDummy($factory, null, new ReflectionExtractor(), $discriminatorResolver);
        $serializer = new Serializer([$normalizer]);
        $normalizer->setSerializer($serializer);
        $normalizedData = $normalizer->denormalize(['foo' => 'foo', 'baz' => 'baz', 'quux' => ['value' => 'quux'], 'type' => $typeValue], AbstractDummy::class);

        $this->assertInstanceOf(DummyFirstChildQuux::class, $normalizedData->quux);
    }

    /**
     * @return iterable<array{0: mixed, 1: bool}>
     */
    public static function provideInvalidDiscriminatorTypes(): array
    {
        $toStringObject = new class {
            public function __toString()
            {
                return 'first';
            }
        };

        return [
            [[], true],
            [new \stdClass(), true],
            [123, true],
            [false, true],
            ['first', false],
            [$toStringObject, false],
        ];
    }

    public function testDenormalizeWithDiscriminatorMapUsesCorrectClassname()
    {
        $factory = new ClassMetadataFactory(new AttributeLoader());

        $loaderMock = new class implements ClassMetadataFactoryInterface {
            public function getMetadataFor($value): ClassMetadataInterface
            {
                if (AbstractDummy::class === $value) {
                    return new ClassMetadata(