Skip to content

Commit bbbe4ed

Browse files
committed
avoid deprecation notices in tests with Symfony >= 7.3
1 parent b69bb79 commit bbbe4ed

8 files changed

Lines changed: 45 additions & 21 deletions

File tree

Tests/IntegrationTestBundle/Entity/Issue149Data.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace Craue\FormFlowBundle\Tests\IntegrationTestBundle\Entity;
44

5-
use Symfony\Component\Validator\Constraints as Assert;
5+
use Symfony\Component\Validator\Constraints\Valid;
66
use Symfony\Component\Validator\Mapping\ClassMetadata;
77

88
/**
@@ -18,7 +18,8 @@ class Issue149Data {
1818
public $photo;
1919

2020
public static function loadValidatorMetadata(ClassMetadata $metadata) : void {
21-
$metadata->addPropertyConstraint('photo', new Assert\Valid(['groups' => 'flow_issue149_step1']));
21+
$options = ['groups' => ['flow_issue149_step1']];
22+
$metadata->addPropertyConstraint('photo', \version_compare(\PHP_VERSION, '8.0', '<') ? new Valid($options) : new Valid(...$options));
2223
}
2324

2425
}

Tests/IntegrationTestBundle/Entity/Issue64Data.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
namespace Craue\FormFlowBundle\Tests\IntegrationTestBundle\Entity;
44

5-
use Symfony\Component\Validator\Constraints as Assert;
5+
use Symfony\Component\Validator\Constraints\NotNull;
6+
use Symfony\Component\Validator\Constraints\Valid;
67
use Symfony\Component\Validator\Mapping\ClassMetadata;
78

89
/**
@@ -18,8 +19,9 @@ class Issue64Data {
1819
public $sub;
1920

2021
public static function loadValidatorMetadata(ClassMetadata $metadata) : void {
21-
$metadata->addPropertyConstraint('sub', new Assert\NotNull(['groups' => ['flow_issue64_step1', 'flow_issue64_step2', 'flow_issue64_step3']]));
22-
$metadata->addPropertyConstraint('sub', new Assert\Valid(['groups' => ['flow_issue64_step1', 'flow_issue64_step2', 'flow_issue64_step3']]));
22+
$options = ['groups' => ['flow_issue64_step1', 'flow_issue64_step2', 'flow_issue64_step3']];
23+
$metadata->addPropertyConstraint('sub', \version_compare(\PHP_VERSION, '8.0', '<') ? new NotNull($options) : new NotNull(...$options));
24+
$metadata->addPropertyConstraint('sub', \version_compare(\PHP_VERSION, '8.0', '<') ? new Valid($options) : new Valid(...$options));
2325
}
2426

2527
}

Tests/IntegrationTestBundle/Entity/Issue64SubData.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace Craue\FormFlowBundle\Tests\IntegrationTestBundle\Entity;
44

5-
use Symfony\Component\Validator\Constraints as Assert;
5+
use Symfony\Component\Validator\Constraints\NotBlank;
66
use Symfony\Component\Validator\Mapping\ClassMetadata;
77

88
/**
@@ -23,8 +23,10 @@ class Issue64SubData {
2323
public $prop2;
2424

2525
public static function loadValidatorMetadata(ClassMetadata $metadata) : void {
26-
$metadata->addPropertyConstraint('prop1', new Assert\NotBlank(['groups' => 'flow_issue64_step1']));
27-
$metadata->addPropertyConstraint('prop2', new Assert\NotBlank(['groups' => 'flow_issue64_step2']));
26+
$prop1NotBlankOptions = ['groups' => ['flow_issue64_step1']];
27+
$prop2NotBlankOptions = ['groups' => ['flow_issue64_step2']];
28+
$metadata->addPropertyConstraint('prop1', \version_compare(\PHP_VERSION, '8.0', '<') ? new NotBlank($prop1NotBlankOptions) : new NotBlank(...$prop1NotBlankOptions));
29+
$metadata->addPropertyConstraint('prop2', \version_compare(\PHP_VERSION, '8.0', '<') ? new NotBlank($prop2NotBlankOptions) : new NotBlank(...$prop2NotBlankOptions));
2830
}
2931

3032
}

Tests/IntegrationTestBundle/Entity/PhotoUpload.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
namespace Craue\FormFlowBundle\Tests\IntegrationTestBundle\Entity;
44

55
use Symfony\Component\HttpFoundation\File\UploadedFile;
6-
use Symfony\Component\Validator\Constraints as Assert;
6+
use Symfony\Component\Validator\Constraints\Image;
7+
use Symfony\Component\Validator\Constraints\NotNull;
78
use Symfony\Component\Validator\Mapping\ClassMetadata;
89

910
/**
@@ -32,8 +33,9 @@ public function getPhotoMimeType() {
3233
}
3334

3435
public static function loadValidatorMetadata(ClassMetadata $metadata) : void {
35-
$metadata->addPropertyConstraint('photo', new Assert\NotNull(['groups' => 'flow_photoUpload_step1']));
36-
$metadata->addPropertyConstraint('photo', new Assert\Image(['groups' => 'flow_photoUpload_step1']));
36+
$options = ['groups' => ['flow_photoUpload_step1']];
37+
$metadata->addPropertyConstraint('photo', \version_compare(\PHP_VERSION, '8.0', '<') ? new NotNull($options) : new NotNull(...$options));
38+
$metadata->addPropertyConstraint('photo', \version_compare(\PHP_VERSION, '8.0', '<') ? new Image($options) : new Image(...$options));
3739
}
3840

3941
}

Tests/IntegrationTestBundle/Entity/RevalidatePreviousStepsData.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace Craue\FormFlowBundle\Tests\IntegrationTestBundle\Entity;
44

5-
use Symfony\Component\Validator\Constraints as Assert;
5+
use Symfony\Component\Validator\Constraints\Callback;
66
use Symfony\Component\Validator\Context\ExecutionContextInterface;
77
use Symfony\Component\Validator\Mapping\ClassMetadata;
88

@@ -27,7 +27,8 @@ public function isDataValid(ExecutionContextInterface $context) {
2727
}
2828

2929
public static function loadValidatorMetadata(ClassMetadata $metadata) : void {
30-
$metadata->addConstraint(new Assert\Callback(['groups' => 'flow_revalidatePreviousSteps_step1', 'callback' => 'isDataValid']));
30+
$options = ['groups' => ['flow_revalidatePreviousSteps_step1'], 'callback' => 'isDataValid'];
31+
$metadata->addConstraint(\version_compare(\PHP_VERSION, '8.0', '<') ? new Callback($options) : new Callback(...$options));
3132
}
3233

3334
}

Tests/IntegrationTestBundle/Entity/Topic.php

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
namespace Craue\FormFlowBundle\Tests\IntegrationTestBundle\Entity;
44

5-
use Symfony\Component\Validator\Constraints as Assert;
5+
use Symfony\Component\Validator\Constraints\Choice;
6+
use Symfony\Component\Validator\Constraints\NotBlank;
67
use Symfony\Component\Validator\Mapping\ClassMetadata;
78

89
/**
@@ -50,10 +51,14 @@ public static function getValidCategories() {
5051
}
5152

5253
public static function loadValidatorMetadata(ClassMetadata $metadata) : void {
53-
$metadata->addPropertyConstraint('title', new Assert\NotBlank(['groups' => 'flow_createTopic_step1']));
54-
$metadata->addPropertyConstraint('category', new Assert\Choice(['groups' => 'flow_createTopic_step1', 'callback' => 'getValidCategories', 'strict' => true]));
55-
$metadata->addPropertyConstraint('category', new Assert\NotBlank(['groups' => 'flow_createTopic_step1']));
56-
$metadata->addPropertyConstraint('details', new Assert\NotBlank(['groups' => 'flow_createTopic_step3']));
54+
$titleNotBlankOptions = ['groups' => ['flow_createTopic_step1']];
55+
$metadata->addPropertyConstraint('title', \version_compare(\PHP_VERSION, '8.0', '<') ? new NotBlank($titleNotBlankOptions) : new NotBlank(...$titleNotBlankOptions));
56+
$categoryChoiceOptions = ['groups' => ['flow_createTopic_step1'], 'callback' => 'getValidCategories', 'strict' => true];
57+
$metadata->addPropertyConstraint('category', \version_compare(\PHP_VERSION, '8.0', '<') ? new Choice($categoryChoiceOptions) : new Choice(...$categoryChoiceOptions));
58+
$categoryNotBlankOptions = ['groups' => ['flow_createTopic_step1']];
59+
$metadata->addPropertyConstraint('category', \version_compare(\PHP_VERSION, '8.0', '<') ? new NotBlank($categoryNotBlankOptions) : new NotBlank(...$categoryNotBlankOptions));
60+
$detailsNotBlankOptions = ['groups' => ['flow_createTopic_step3']];
61+
$metadata->addPropertyConstraint('details', \version_compare(\PHP_VERSION, '8.0', '<') ? new NotBlank($detailsNotBlankOptions) : new NotBlank(...$detailsNotBlankOptions));
5762
}
5863

5964
}

Tests/IntegrationTestBundle/Entity/Vehicle.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace Craue\FormFlowBundle\Tests\IntegrationTestBundle\Entity;
44

5-
use Symfony\Component\Validator\Constraints as Assert;
5+
use Symfony\Component\Validator\Constraints\NotBlank;
66
use Symfony\Component\Validator\Mapping\ClassMetadata;
77

88
/**
@@ -27,8 +27,10 @@ public function canHaveEngine() {
2727
}
2828

2929
public static function loadValidatorMetadata(ClassMetadata $metadata) : void {
30-
$metadata->addPropertyConstraint('numberOfWheels', new Assert\NotBlank(['groups' => 'flow_createVehicle_step1']));
31-
$metadata->addPropertyConstraint('engine', new Assert\NotBlank(['groups' => 'flow_createVehicle_step2']));
30+
$numberOfWheelsNotBlankOptions = ['groups' => ['flow_createVehicle_step1']];
31+
$metadata->addPropertyConstraint('numberOfWheels', \version_compare(\PHP_VERSION, '8.0', '<') ? new NotBlank($numberOfWheelsNotBlankOptions) : new NotBlank(...$numberOfWheelsNotBlankOptions));
32+
$engineNotBlankOptions = ['groups' => ['flow_createVehicle_step2']];
33+
$metadata->addPropertyConstraint('engine', \version_compare(\PHP_VERSION, '8.0', '<') ? new NotBlank($engineNotBlankOptions) : new NotBlank(...$engineNotBlankOptions));
3234
}
3335

3436
}

Tests/config/config_hacks.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,3 +67,12 @@
6767
'http_method_override' => false,
6868
]);
6969
}
70+
71+
// TODO remove as soon as Symfony >= 7.3 is required
72+
if (Kernel::VERSION_ID >= 70300) {
73+
$container->loadFromExtension('framework', [
74+
'property_info' => [
75+
'with_constructor_extractor' => true,
76+
],
77+
]);
78+
}

0 commit comments

Comments
 (0)