Skip to content

Commit

Permalink
#1601 test for Assert\Choice results in numeric array
Browse files Browse the repository at this point in the history
  • Loading branch information
katin-dev committed Mar 14, 2020
1 parent 82aa08e commit 97530a6
Showing 1 changed file with 27 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,31 @@ public function testUpdatePropertyFix1283()
// 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']);
}
}

0 comments on commit 97530a6

Please sign in to comment.