diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml
index a1fc2f3..d2364e3 100644
--- a/.github/workflows/tests.yml
+++ b/.github/workflows/tests.yml
@@ -16,8 +16,8 @@ jobs:
include:
- php-version: '8.2'
symfony-version: '7.0.*'
- - php-version: '8.3'
- symfony-version: '7.1.*'
+ - php-version: '8.4'
+ symfony-version: '7.3.*'
steps:
- name: "Checkout"
@@ -55,7 +55,7 @@ jobs:
uses: shivammathur/setup-php@v2
with:
coverage: xdebug
- php-version: '8.3'
+ php-version: '8.4'
- name: "Install dependencies with composer"
run: composer update --no-interaction --no-progress
@@ -81,7 +81,7 @@ jobs:
uses: shivammathur/setup-php@v2
with:
coverage: none
- php-version: '8.3'
+ php-version: '8.4'
- name: "Install dependencies with composer"
run: composer update --no-interaction --no-progress
@@ -101,7 +101,7 @@ jobs:
uses: shivammathur/setup-php@v2
with:
coverage: none
- php-version: '8.3'
+ php-version: '8.4'
- name: "Install dependencies with composer"
run: composer update --no-interaction --no-progress
diff --git a/composer.json b/composer.json
index b65c703..0e0b26d 100644
--- a/composer.json
+++ b/composer.json
@@ -20,6 +20,7 @@
"phpunit/phpunit": "^9.6",
"symfony/form": "^7.0",
"symfony/http-kernel": "^7.0",
+ "symfony/phpunit-bridge": "^7.3",
"symfony/translation": "^7.0",
"symfony/twig-bundle": "^7.0",
"symfony/validator": "^7.0",
diff --git a/phpunit.xml.dist b/phpunit.xml.dist
index 7f4c4a0..ae4a825 100644
--- a/phpunit.xml.dist
+++ b/phpunit.xml.dist
@@ -5,6 +5,7 @@
bootstrap="vendor/autoload.php">
+
diff --git a/src/Form/Type/EnumType.php b/src/Form/Type/EnumType.php
index 5078ac4..9c9c245 100644
--- a/src/Form/Type/EnumType.php
+++ b/src/Form/Type/EnumType.php
@@ -39,30 +39,16 @@ function (string $name): bool {
function (Options $options): array {
/** @var string $name */
$name = $options['enum'];
- $choices = $this->enumRegistry->get($name)->getChoices();
- if ($options['enum_choice_value'] === null) {
- foreach ($choices as $value) {
- if (!\is_scalar($value)) {
- @\trigger_error(
- 'Not configuring the "enum_choice_value" option is deprecated.' .
- ' It will default to "true" in 5.0.',
- \E_USER_DEPRECATED
- );
- break;
- }
- }
- }
-
- return $choices;
+ return $this->enumRegistry->get($name)->getChoices();
}
)
- ->setAllowedTypes('enum_choice_value', ['bool', 'null'])
- ->setDefault('enum_choice_value', null)
+ ->setAllowedTypes('enum_choice_value', ['bool'])
+ ->setDefault('enum_choice_value', true)
->setDefault(
'choice_value',
static function (Options $options) {
- if ($options['enum_choice_value'] !== true) {
+ if (!$options['enum_choice_value']) {
return null;
}
diff --git a/src/MyCLabsEnum.php b/src/MyCLabsEnum.php
index bf26639..d71b225 100644
--- a/src/MyCLabsEnum.php
+++ b/src/MyCLabsEnum.php
@@ -12,7 +12,7 @@
*/
class MyCLabsEnum extends Enum
{
- public function __construct(string $enum, string $name = null)
+ public function __construct(string $enum, string|null $name = null)
{
if (!\is_a($enum, ActualMyCLabsEnum::class, true)) {
throw LogicException::invalidMyClabsEnumClass($enum);
diff --git a/src/MyCLabsTranslatedEnum.php b/src/MyCLabsTranslatedEnum.php
index 8d5c883..74a5e8c 100644
--- a/src/MyCLabsTranslatedEnum.php
+++ b/src/MyCLabsTranslatedEnum.php
@@ -18,7 +18,7 @@ public function __construct(
TranslatorInterface $translator,
string $transPattern,
string $transDomain = 'messages',
- string $name = null
+ string|null $name = null
) {
if (!\is_a($enum, ActualMyCLabsEnum::class, true)) {
throw LogicException::invalidMyClabsEnumClass($enum);
diff --git a/src/NativeEnum.php b/src/NativeEnum.php
index 3dcb69b..5c59878 100644
--- a/src/NativeEnum.php
+++ b/src/NativeEnum.php
@@ -12,7 +12,7 @@
*/
class NativeEnum extends Enum
{
- public function __construct(string $enum, string $name = null)
+ public function __construct(string $enum, string|null $name = null)
{
if (!\is_a($enum, UnitEnum::class, true)) {
throw LogicException::invalidUnitEnum($enum);
diff --git a/src/NativeTranslatedEnum.php b/src/NativeTranslatedEnum.php
index 4121dea..fa1162c 100644
--- a/src/NativeTranslatedEnum.php
+++ b/src/NativeTranslatedEnum.php
@@ -18,7 +18,7 @@ public function __construct(
TranslatorInterface $translator,
string $transPattern,
string $transDomain = 'messages',
- string $name = null
+ string|null $name = null
) {
if (!\is_a($enum, UnitEnum::class, true)) {
throw LogicException::invalidUnitEnum($enum);
diff --git a/src/Validator/Constraints/Enum.php b/src/Validator/Constraints/Enum.php
index 3357414..e6a7b1a 100644
--- a/src/Validator/Constraints/Enum.php
+++ b/src/Validator/Constraints/Enum.php
@@ -21,24 +21,33 @@ public function __construct(
array $options = [],
string|null $enum = null,
callable|null|string $callback = null,
- bool $multiple = null,
- bool $strict = null,
- int $min = null,
- int $max = null,
- string $message = null,
- string $multipleMessage = null,
- string $minMessage = null,
- string $maxMessage = null,
+ bool|null $multiple = null,
+ bool|null $strict = null,
+ int|null $min = null,
+ int|null $max = null,
+ string|null $message = null,
+ string|null $multipleMessage = null,
+ string|null $minMessage = null,
+ string|null $maxMessage = null,
array|null $groups = null,
mixed $payload = null,
) {
+ if (\is_array($options) && $options !== []) {
+ \trigger_deprecation(
+ 'symfony/validator',
+ '7.3',
+ 'Passing an array of options to configure the "%s" constraint is deprecated, use named arguments instead.',
+ static::class,
+ );
+ }
+
if (\is_string($enum)) {
$this->enum = $enum;
}
// Since Symfony 5.3, first argument of Choice is $options
parent::__construct(
- $options,
+ [],
null,
$callback,
$multiple,
diff --git a/tests/Integration/tests/PullRequestFormTest.php b/tests/Integration/tests/PullRequestFormTest.php
index 72abe94..c88ac9d 100644
--- a/tests/Integration/tests/PullRequestFormTest.php
+++ b/tests/Integration/tests/PullRequestFormTest.php
@@ -108,13 +108,13 @@ public function valid(): Generator
{
foreach ($this->classes() as [$class]) {
yield [
- ['status' => 0, 'labels' => ['bugfix', '1.x']],
+ ['status' => 'opened', 'labels' => ['bugfix', '1.x']],
self::pullRequest($class),
self::pullRequest($class, 'opened', ['bugfix', '1.x']),
];
yield [
- ['status' => 2, 'labels' => ['bugfix', '2.x']],
+ ['status' => 'closed', 'labels' => ['bugfix', '2.x']],
self::pullRequest($class, 'opened', ['bugfix', '1.x']),
self::pullRequest($class, 'closed', ['bugfix', '2.x']),
];
@@ -171,7 +171,7 @@ public function invalid(): Generator
private static function pullRequest(
string $class,
- string $status = null,
+ string|null $status = null,
array $labels = [],
): MyCLabsPullRequest|NativeEnumPullRequest {
return (match ($class) {
diff --git a/tests/Unit/Form/Extension/EnumTypeGuesserTest.php b/tests/Unit/Form/Extension/EnumTypeGuesserTest.php
index 8fbecd1..326d78c 100644
--- a/tests/Unit/Form/Extension/EnumTypeGuesserTest.php
+++ b/tests/Unit/Form/Extension/EnumTypeGuesserTest.php
@@ -43,15 +43,15 @@ protected function setUp(): void
$this->enumRegistry->add(new StateEnum());
$metadata = new ClassMetadata(self::TEST_CLASS);
- $metadata->addPropertyConstraint(self::TEST_PROPERTY_NONE, new Choice(['choices' => ['new', 'validated']]));
- $metadata->addPropertyConstraint(self::TEST_PROPERTY_DIRECT, new Enum(['enum' => StateEnum::class]));
+ $metadata->addPropertyConstraint(self::TEST_PROPERTY_NONE, new Choice(choices: ['new', 'validated']));
+ $metadata->addPropertyConstraint(self::TEST_PROPERTY_DIRECT, new Enum(enum: StateEnum::class));
if (\class_exists(Compound::class)) {
$metadata->addPropertyConstraint(
self::TEST_PROPERTY_COMPOUND,
new class() extends Compound {
protected function getConstraints(array $options): array
{
- return [new Enum(['enum' => StateEnum::class])];
+ return [new Enum(enum: StateEnum::class)];
}
}
);
diff --git a/tests/Unit/Form/TestExtension.php b/tests/Unit/Form/TestExtension.php
index d142c3b..71bd6c0 100644
--- a/tests/Unit/Form/TestExtension.php
+++ b/tests/Unit/Form/TestExtension.php
@@ -19,7 +19,7 @@ class TestExtension extends AbstractExtension
private MetadataFactoryInterface|null $metadataFactory;
- public function __construct(EnumRegistry $enumRegistry, MetadataFactoryInterface $metadataFactory = null)
+ public function __construct(EnumRegistry $enumRegistry, MetadataFactoryInterface|null $metadataFactory = null)
{
$this->enumRegistry = $enumRegistry;
$this->metadataFactory = $metadataFactory;
diff --git a/tests/Unit/Form/Type/EnumTypeTest.php b/tests/Unit/Form/Type/EnumTypeTest.php
index 306c9ef..10ddf94 100644
--- a/tests/Unit/Form/Type/EnumTypeTest.php
+++ b/tests/Unit/Form/Type/EnumTypeTest.php
@@ -61,65 +61,65 @@ public static function submit(): \Generator
{
yield [
StateEnum::class,
- [],
+ ['enum_choice_value' => false],
'new',
'new',
];
yield [
StateEnum::class,
- ['enum_choice_value' => true],
+ [],
'new',
'new',
];
yield [
ActionEnum::class,
- [],
+ ['enum_choice_value' => false],
1,
Action::EDIT(),
];
yield [
ActionEnum::class,
- ['enum_choice_value' => true],
+ [],
'edit',
Action::EDIT(),
];
yield [
Picture::class,
- [],
+ ['enum_choice_value' => false],
0,
Picture::Landscape,
];
yield [
Picture::class,
- ['enum_choice_value' => true],
+ [],
'Landscape',
Picture::Landscape,
];
yield [
HTTPMethod::class,
- [],
+ ['enum_choice_value' => false],
0,
HTTPMethod::GET,
];
yield [
HTTPMethod::class,
- ['enum_choice_value' => true],
+ [],
'get',
HTTPMethod::GET,
];
yield [
HTTPStatus::class,
- ['enum_choice_value' => true],
+ [],
200,
HTTPStatus::OK,
];
yield [
HTTPStatus::class,
- [],
+ ['enum_choice_value' => false],
0,
HTTPStatus::OK,
];
diff --git a/tests/Unit/Translator.php b/tests/Unit/Translator.php
index 2e7080c..bb584db 100644
--- a/tests/Unit/Translator.php
+++ b/tests/Unit/Translator.php
@@ -32,8 +32,12 @@ public function getLocale(): string
return 'fr';
}
- public function trans(string $id, array $parameters = [], string $domain = null, string $locale = null): string
- {
+ public function trans(
+ string $id,
+ array $parameters = [],
+ string|null $domain = null,
+ string|null $locale = null,
+ ): string {
if ($domain !== $this->domain) {
return $id;
}
diff --git a/tests/Unit/Validator/Constraints/EnumValidatorTest.php b/tests/Unit/Validator/Constraints/EnumValidatorTest.php
index 0c9e99e..8e86db8 100644
--- a/tests/Unit/Validator/Constraints/EnumValidatorTest.php
+++ b/tests/Unit/Validator/Constraints/EnumValidatorTest.php
@@ -65,7 +65,7 @@ public function testValidSingleEnum(): void
public function testInvalidSingleEnum(): void
{
- $constraint = new Enum(['enum' => 'type', 'message' => 'myMessage']);
+ $constraint = new Enum(enum: 'type', message: 'myMessage');
$this->validator->validate('foo', $constraint);
@@ -78,7 +78,7 @@ public function testInvalidSingleEnum(): void
public function testValidMultipleEnum(): void
{
- $constraint = new Enum(['enum' => 'type', 'multiple' => true]);
+ $constraint = new Enum(enum: 'type', multiple: true);
$this->validator->validate(['customer', 'prospect'], $constraint);
@@ -87,7 +87,7 @@ public function testValidMultipleEnum(): void
public function testInvalidMultipleEnum(): void
{
- $constraint = new Enum(['enum' => 'type', 'multiple' => true, 'multipleMessage' => 'myMessage']);
+ $constraint = new Enum(enum: 'type', multiple: true, multipleMessage: 'myMessage');
$this->validator->validate(['customer', 'foo'], $constraint);