merge([new OA\Property(['property' => 'property1'])]); $schema->merge([new OA\Property(['property' => 'property2'])]); $symfonyConstraintAnnotationReader = new SymfonyConstraintAnnotationReader(new AnnotationReader()); $symfonyConstraintAnnotationReader->setSchema($schema); $symfonyConstraintAnnotationReader->updateProperty(new \ReflectionProperty($entity, 'property1'), $schema->properties[0]); $symfonyConstraintAnnotationReader->updateProperty(new \ReflectionProperty($entity, 'property2'), $schema->properties[1]); // expect required to be numeric array with sequential keys (not [0 => ..., 2 => ...]) $this->assertEquals($schema->required, ['property1', 'property2']); } public function testOptionalProperty() { $entity = new class() { /** * @Assert\NotBlank(allowNull = true) * @Assert\Length(min = 1) */ private $property1; /** * @Assert\NotBlank() */ private $property2; }; $schema = new OA\Schema([]); $schema->merge([new OA\Property(['property' => 'property1'])]); $schema->merge([new OA\Property(['property' => 'property2'])]); $symfonyConstraintAnnotationReader = new SymfonyConstraintAnnotationReader(new AnnotationReader()); $symfonyConstraintAnnotationReader->setSchema($schema); $symfonyConstraintAnnotationReader->updateProperty(new \ReflectionProperty($entity, 'property1'), $schema->properties[0]); $symfonyConstraintAnnotationReader->updateProperty(new \ReflectionProperty($entity, 'property2'), $schema->properties[1]); // expect required to be numeric array with sequential keys (not [0 => ..., 2 => ...]) $this->assertEquals($schema->required, ['property2']); } public function testAssertChoiceResultsInNumericArray() { define('TEST_ASSERT_CHOICE_STATUSES', [ 1 => 'active', 2 => 'blocked', ]); $entity = new class() { /** * @Assert\Length(min = 1) * @Assert\Choice(choices=TEST_ASSERT_CHOICE_STATUSES) */ private $property1; }; $schema = new OA\Schema([]); $schema->merge([new OA\Property(['property' => 'property1'])]); $symfonyConstraintAnnotationReader = new SymfonyConstraintAnnotationReader(new AnnotationReader()); $symfonyConstraintAnnotationReader->setSchema($schema); $symfonyConstraintAnnotationReader->updateProperty(new \ReflectionProperty($entity, 'property1'), $schema->properties[0]); // expect enum to be numeric array with sequential keys (not [1 => "active", 2 => "active"]) $this->assertEquals($schema->properties[0]->enum, ['active', 'blocked']); } }