api/symfony/Component/Validator/Tests/Mapping/Loader/PropertyInfoLoaderTest.yaml
2024-09-26 02:03:21 -07:00

224 lines
12 KiB
YAML

name: PropertyInfoLoaderTest
class_comment: "# * @author K\xE9vin Dunglas <dunglas@gmail.com>"
dependencies:
- name: TestCase
type: class
source: PHPUnit\Framework\TestCase
- name: PropertyAccessExtractorInterface
type: class
source: Symfony\Component\PropertyInfo\PropertyAccessExtractorInterface
- name: PropertyListExtractorInterface
type: class
source: Symfony\Component\PropertyInfo\PropertyListExtractorInterface
- name: PropertyTypeExtractorInterface
type: class
source: Symfony\Component\PropertyInfo\PropertyTypeExtractorInterface
- name: LegacyType
type: class
source: Symfony\Component\PropertyInfo\Type
- name: Type
type: class
source: Symfony\Component\TypeInfo\Type
- name: All
type: class
source: Symfony\Component\Validator\Constraints\All
- name: Iban
type: class
source: Symfony\Component\Validator\Constraints\Iban
- name: NotBlank
type: class
source: Symfony\Component\Validator\Constraints\NotBlank
- name: NotNull
type: class
source: Symfony\Component\Validator\Constraints\NotNull
- name: TypeConstraint
type: class
source: Symfony\Component\Validator\Constraints\Type
- name: AutoMappingStrategy
type: class
source: Symfony\Component\Validator\Mapping\AutoMappingStrategy
- name: ClassMetadata
type: class
source: Symfony\Component\Validator\Mapping\ClassMetadata
- name: PropertyInfoLoader
type: class
source: Symfony\Component\Validator\Mapping\Loader\PropertyInfoLoader
- name: PropertyMetadata
type: class
source: Symfony\Component\Validator\Mapping\PropertyMetadata
- name: Entity
type: class
source: Symfony\Component\Validator\Tests\Fixtures\NestedAttribute\Entity
- name: PropertyInfoLoaderEntity
type: class
source: Symfony\Component\Validator\Tests\Fixtures\PropertyInfoLoaderEntity
- name: PropertyInfoLoaderNoAutoMappingEntity
type: class
source: Symfony\Component\Validator\Tests\Fixtures\PropertyInfoLoaderNoAutoMappingEntity
- name: Validation
type: class
source: Symfony\Component\Validator\Validation
properties: []
methods:
- name: testClassValidator
visibility: public
parameters:
- name: expected
- name: classValidatorRegexp
default: 'null'
comment: "# * @author K\xE9vin Dunglas <dunglas@gmail.com>\n# */\n# class PropertyInfoLoaderTest\
\ extends TestCase\n# {\n# public function testLoadClassMetadata()\n# {\n# $propertyListExtractor\
\ = $this->createMock(PropertyListExtractorInterface::class);\n# $propertyListExtractor\n\
# ->method('getProperties')\n# ->willReturn([\n# 'nullableString',\n# 'string',\n\
# 'scalar',\n# 'object',\n# 'collection',\n# 'collectionOfUnknown',\n# 'alreadyMappedType',\n\
# 'alreadyMappedNotNull',\n# 'alreadyMappedNotBlank',\n# 'alreadyPartiallyMappedCollection',\n\
# 'readOnly',\n# 'nonExistentField',\n# 'noAutoMapping',\n# ])\n# ;\n# \n# $propertyTypeExtractor\
\ = new class implements PropertyTypeExtractorInterface {\n# private int $i =\
\ 0;\n# private int $j = 0;\n# private array $types;\n# private array $legacyTypes;\n\
# \n# public function getType(string $class, string $property, array $context\
\ = []): ?Type\n# {\n# $this->types ??= [\n# Type::nullable(Type::string()),\n\
# Type::string(),\n# Type::union(Type::string(), Type::int(), Type::bool(), Type::null()),\n\
# Type::nullable(Type::object(Entity::class)),\n# Type::nullable(Type::array(Type::object(Entity::class))),\n\
# Type::nullable(Type::array()),\n# Type::nullable(Type::float()), // The existing\
\ constraint is float\n# Type::nullable(Type::string()),\n# Type::nullable(Type::string()),\n\
# Type::nullable(Type::array(Type::float())),\n# Type::string(),\n# Type::string(),\n\
# ];\n# \n# $type = $this->types[$this->i];\n# ++$this->i;\n# \n# return $type;\n\
# }\n# \n# public function getTypes(string $class, string $property, array $context\
\ = []): ?array\n# {\n# $this->legacyTypes ??= [\n# [new LegacyType('string',\
\ true)],\n# [new LegacyType('string')],\n# [new LegacyType('string', true), new\
\ LegacyType('int'), new LegacyType('bool')],\n# [new LegacyType('object', true,\
\ Entity::class)],\n# [new LegacyType('array', true, null, true, null, new LegacyType('object',\
\ false, Entity::class))],\n# [new LegacyType('array', true, null, true)],\n#\
\ [new LegacyType('float', true)], // The existing constraint is float\n# [new\
\ LegacyType('string', true)],\n# [new LegacyType('string', true)],\n# [new LegacyType('array',\
\ true, null, true, null, new LegacyType('float'))],\n# [new LegacyType('string')],\n\
# [new LegacyType('string')],\n# ];\n# \n# $legacyType = $this->legacyTypes[$this->j];\n\
# ++$this->j;\n# \n# return $legacyType;\n# }\n# };\n# \n# $propertyAccessExtractor\
\ = $this->createMock(PropertyAccessExtractorInterface::class);\n# $propertyAccessExtractor\n\
# ->method('isWritable')\n# ->willReturn(\n# true,\n# true,\n# true,\n# true,\n\
# true,\n# true,\n# true,\n# true,\n# true,\n# true,\n# false,\n# true\n# )\n\
# ;\n# \n# $propertyInfoLoader = new PropertyInfoLoader($propertyListExtractor,\
\ $propertyTypeExtractor, $propertyAccessExtractor, '{.*}');\n# \n# $validator\
\ = Validation::createValidatorBuilder()\n# ->enableAttributeMapping()\n# ->addLoader($propertyInfoLoader)\n\
# ->getValidator()\n# ;\n# \n# $classMetadata = $validator->getMetadataFor(new\
\ PropertyInfoLoaderEntity());\n# \n# $nullableStringMetadata = $classMetadata->getPropertyMetadata('nullableString');\n\
# $this->assertCount(1, $nullableStringMetadata);\n# $nullableStringConstraints\
\ = $nullableStringMetadata[0]->getConstraints();\n# $this->assertCount(1, $nullableStringConstraints);\n\
# $this->assertInstanceOf(TypeConstraint::class, $nullableStringConstraints[0]);\n\
# $this->assertSame('string', $nullableStringConstraints[0]->type);\n# \n# $stringMetadata\
\ = $classMetadata->getPropertyMetadata('string');\n# $this->assertCount(1, $stringMetadata);\n\
# $stringConstraints = $stringMetadata[0]->getConstraints();\n# $this->assertCount(2,\
\ $stringConstraints);\n# $this->assertInstanceOf(TypeConstraint::class, $stringConstraints[0]);\n\
# $this->assertSame('string', $stringConstraints[0]->type);\n# $this->assertInstanceOf(NotNull::class,\
\ $stringConstraints[1]);\n# \n# $scalarMetadata = $classMetadata->getPropertyMetadata('scalar');\n\
# $this->assertCount(1, $scalarMetadata);\n# $scalarConstraints = $scalarMetadata[0]->getConstraints();\n\
# $this->assertCount(1, $scalarConstraints);\n# $this->assertInstanceOf(TypeConstraint::class,\
\ $scalarConstraints[0]);\n# $this->assertSame('scalar', $scalarConstraints[0]->type);\n\
# \n# $objectMetadata = $classMetadata->getPropertyMetadata('object');\n# $this->assertCount(1,\
\ $objectMetadata);\n# $objectConstraints = $objectMetadata[0]->getConstraints();\n\
# $this->assertCount(1, $objectConstraints);\n# $this->assertInstanceOf(TypeConstraint::class,\
\ $objectConstraints[0]);\n# $this->assertSame(Entity::class, $objectConstraints[0]->type);\n\
# \n# $collectionMetadata = $classMetadata->getPropertyMetadata('collection');\n\
# $this->assertCount(1, $collectionMetadata);\n# $collectionConstraints = $collectionMetadata[0]->getConstraints();\n\
# $this->assertCount(2, $collectionConstraints);\n# $this->assertInstanceOf(All::class,\
\ $collectionConstraints[0]);\n# $this->assertInstanceOf(NotNull::class, $collectionConstraints[0]->constraints[0]);\n\
# $this->assertInstanceOf(TypeConstraint::class, $collectionConstraints[0]->constraints[1]);\n\
# $this->assertSame(Entity::class, $collectionConstraints[0]->constraints[1]->type);\n\
# \n# $collectionOfUnknownMetadata = $classMetadata->getPropertyMetadata('collectionOfUnknown');\n\
# $this->assertCount(1, $collectionOfUnknownMetadata);\n# $collectionOfUnknownConstraints\
\ = $collectionOfUnknownMetadata[0]->getConstraints();\n# $this->assertCount(1,\
\ $collectionOfUnknownConstraints);\n# $this->assertInstanceOf(TypeConstraint::class,\
\ $collectionOfUnknownConstraints[0]);\n# $this->assertSame('array', $collectionOfUnknownConstraints[0]->type);\n\
# \n# $alreadyMappedTypeMetadata = $classMetadata->getPropertyMetadata('alreadyMappedType');\n\
# $this->assertCount(1, $alreadyMappedTypeMetadata);\n# $alreadyMappedTypeConstraints\
\ = $alreadyMappedTypeMetadata[0]->getConstraints();\n# $this->assertCount(1,\
\ $alreadyMappedTypeMetadata);\n# $this->assertInstanceOf(TypeConstraint::class,\
\ $alreadyMappedTypeConstraints[0]);\n# \n# $alreadyMappedNotNullMetadata = $classMetadata->getPropertyMetadata('alreadyMappedNotNull');\n\
# $this->assertCount(1, $alreadyMappedNotNullMetadata);\n# $alreadyMappedNotNullConstraints\
\ = $alreadyMappedNotNullMetadata[0]->getConstraints();\n# $this->assertCount(1,\
\ $alreadyMappedNotNullMetadata);\n# $this->assertInstanceOf(NotNull::class, $alreadyMappedNotNullConstraints[0]);\n\
# \n# $alreadyMappedNotBlankMetadata = $classMetadata->getPropertyMetadata('alreadyMappedNotBlank');\n\
# $this->assertCount(1, $alreadyMappedNotBlankMetadata);\n# $alreadyMappedNotBlankConstraints\
\ = $alreadyMappedNotBlankMetadata[0]->getConstraints();\n# $this->assertCount(1,\
\ $alreadyMappedNotBlankMetadata);\n# $this->assertInstanceOf(NotBlank::class,\
\ $alreadyMappedNotBlankConstraints[0]);\n# \n# $alreadyPartiallyMappedCollectionMetadata\
\ = $classMetadata->getPropertyMetadata('alreadyPartiallyMappedCollection');\n\
# $this->assertCount(1, $alreadyPartiallyMappedCollectionMetadata);\n# $alreadyPartiallyMappedCollectionConstraints\
\ = $alreadyPartiallyMappedCollectionMetadata[0]->getConstraints();\n# $this->assertCount(2,\
\ $alreadyPartiallyMappedCollectionConstraints);\n# $this->assertInstanceOf(All::class,\
\ $alreadyPartiallyMappedCollectionConstraints[0]);\n# $this->assertInstanceOf(TypeConstraint::class,\
\ $alreadyPartiallyMappedCollectionConstraints[0]->constraints[0]);\n# $this->assertSame('string',\
\ $alreadyPartiallyMappedCollectionConstraints[0]->constraints[0]->type);\n# $this->assertInstanceOf(Iban::class,\
\ $alreadyPartiallyMappedCollectionConstraints[0]->constraints[1]);\n# \n# $readOnlyMetadata\
\ = $classMetadata->getPropertyMetadata('readOnly');\n# $this->assertEmpty($readOnlyMetadata);\n\
# \n# /** @var PropertyMetadata[] $noAutoMappingMetadata */\n# $noAutoMappingMetadata\
\ = $classMetadata->getPropertyMetadata('noAutoMapping');\n# $this->assertCount(1,\
\ $noAutoMappingMetadata);\n# $this->assertSame(AutoMappingStrategy::DISABLED,\
\ $noAutoMappingMetadata[0]->getAutoMappingStrategy());\n# $noAutoMappingConstraints\
\ = $noAutoMappingMetadata[0]->getConstraints();\n# $this->assertCount(0, $noAutoMappingConstraints,\
\ 'DisableAutoMapping constraint is not added in the list');\n# }\n# \n# /**\n\
# * @dataProvider regexpProvider"
- name: getType
visibility: public
parameters:
- name: class
- name: property
- name: context
default: '[]'
comment: null
- name: getTypes
visibility: public
parameters:
- name: class
- name: property
- name: context
default: '[]'
comment: null
- name: regexpProvider
visibility: public
parameters: []
comment: null
- name: testClassNoAutoMapping
visibility: public
parameters:
- name: propertyListExtractor
default: 'null'
comment: null
- name: getType
visibility: public
parameters:
- name: class
- name: property
- name: context
default: '[]'
comment: null
- name: getTypes
visibility: public
parameters:
- name: class
- name: property
- name: context
default: '[]'
comment: null
traits:
- PHPUnit\Framework\TestCase
- Symfony\Component\PropertyInfo\PropertyAccessExtractorInterface
- Symfony\Component\PropertyInfo\PropertyListExtractorInterface
- Symfony\Component\PropertyInfo\PropertyTypeExtractorInterface
- Symfony\Component\TypeInfo\Type
- Symfony\Component\Validator\Constraints\All
- Symfony\Component\Validator\Constraints\Iban
- Symfony\Component\Validator\Constraints\NotBlank
- Symfony\Component\Validator\Constraints\NotNull
- Symfony\Component\Validator\Mapping\AutoMappingStrategy
- Symfony\Component\Validator\Mapping\ClassMetadata
- Symfony\Component\Validator\Mapping\Loader\PropertyInfoLoader
- Symfony\Component\Validator\Mapping\PropertyMetadata
- Symfony\Component\Validator\Tests\Fixtures\NestedAttribute\Entity
- Symfony\Component\Validator\Tests\Fixtures\PropertyInfoLoaderEntity
- Symfony\Component\Validator\Tests\Fixtures\PropertyInfoLoaderNoAutoMappingEntity
- Symfony\Component\Validator\Validation
interfaces:
- PropertyTypeExtractorInterface
- PropertyTypeExtractorInterface
- PropertyTypeExtractorInterface