mirror of
https://github.com/retailcrm/NelmioApiDocBundle.git
synced 2025-03-11 10:06:09 +03:00
#1601 test for Assert\Choice results in numeric array
This commit is contained in:
parent
82aa08e5ff
commit
97530a6eee
@ -46,4 +46,31 @@ class SymfonyConstraintAnnotationReaderTest extends TestCase
|
||||
// expect required to be numeric array with sequential keys (not [0 => ..., 2 => ...])
|
||||
$this->assertEquals($schema->getRequired(), ['property1', '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 Schema();
|
||||
$schema->getProperties()->set('property1', new Schema());
|
||||
|
||||
$symfonyConstraintAnnotationReader = new SymfonyConstraintAnnotationReader(new AnnotationReader());
|
||||
$symfonyConstraintAnnotationReader->setSchema($schema);
|
||||
|
||||
$symfonyConstraintAnnotationReader->updateProperty(new \ReflectionProperty($entity, 'property1'), $schema->getProperties()->get('property1'));
|
||||
|
||||
// expect enum to be numeric array with sequential keys (not [1 => "active", 2 => "active"])
|
||||
$this->assertEquals($schema->getProperties()->get('property1')->getEnum(), ['active', 'blocked']);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user