fix(SymfonyConstraintAnnotationReader): fixed enum guessing in Assert… (#1325)

* fix(SymfonyConstraintAnnotationReader): fixed enum guessing in Assert\Choicewhen callback parameter is used

* fix(SymfonyConstraints): turn double quotes in single quotes
This commit is contained in:
Palluel-Lafleur Frédéric 2018-05-20 15:59:52 +02:00 committed by Guilhem N
parent 4954feb232
commit c2f036c159
3 changed files with 28 additions and 1 deletions

View File

@ -70,7 +70,7 @@ class SymfonyConstraintAnnotationReader
}
if ($annotation instanceof Assert\Choice) {
$property->setEnum($annotation->choices);
$property->setEnum($annotation->callback ? call_user_func($annotation->callback) : $annotation->choices);
}
if ($annotation instanceof Assert\Expression) {

View File

@ -64,6 +64,13 @@ class SymfonyConstraints
*/
private $propertyChoice;
/**
* @var int
*
* @Assert\Choice(callback={SymfonyConstraints::class,"fetchAllowedChoices"})
*/
private $propertyChoiceWithCallback;
/**
* @var int
*
@ -130,6 +137,14 @@ class SymfonyConstraints
$this->propertyChoice = $propertyChoice;
}
/**
* @param int $propertyChoiceWithCallback
*/
public function setPropertyChoiceWithCallback(int $propertyChoiceWithCallback): void
{
$this->propertyChoiceWithCallback = $propertyChoiceWithCallback;
}
/**
* @param int $propertyExpression
*/
@ -137,4 +152,12 @@ class SymfonyConstraints
{
$this->propertyExpression = $propertyExpression;
}
/**
* @return array
*/
public static function fetchAllowedChoices()
{
return ['choice1', 'choice2'];
}
}

View File

@ -341,6 +341,10 @@ class FunctionalTest extends WebTestCase
'type' => 'integer',
'enum' => ['choice1', 'choice2'],
],
'propertyChoiceWithCallback' => [
'type' => 'integer',
'enum' => ['choice1', 'choice2'],
],
'propertyExpression' => [
'type' => 'integer',
'pattern' => 'If this is a tech post, the category should be either php or symfony!',