Skip to content

Commit 13213ab

Browse files
committed
Fix deprecated usages of symfony/validator
1 parent 02d0e33 commit 13213ab

File tree

2 files changed

+25
-9
lines changed

2 files changed

+25
-9
lines changed

Tests/Controller/Annotations/AbstractScalarParamTest.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,10 @@ public function testScalarRequirements()
8080
$this->param->requirements = 'foo %bar% %%';
8181
$this->assertEquals([
8282
new NotNull(),
83-
new Regex([
84-
'pattern' => '#^(?:foo %bar% %%)$#xsu',
85-
'message' => "Parameter 'bar' value, does not match requirements 'foo %bar% %%'",
86-
]),
83+
new Regex(
84+
'#^(?:foo %bar% %%)$#xsu',
85+
"Parameter 'bar' value, does not match requirements 'foo %bar% %%'",
86+
),
8787
], $this->param->getConstraints());
8888
}
8989

@@ -95,10 +95,10 @@ public function testArrayRequirements()
9595
];
9696
$this->assertEquals([
9797
new NotNull(),
98-
new Regex([
99-
'pattern' => '#^(?:foo)$#xsu',
100-
'message' => 'bar',
101-
]),
98+
new Regex(
99+
'#^(?:foo)$#xsu',
100+
'bar',
101+
),
102102
], $this->param->getConstraints());
103103
}
104104

Tests/Fixtures/Annotations/IdenticalToRequestParam.php

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace FOS\RestBundle\Tests\Fixtures\Annotations;
1313

14+
use Composer\InstalledVersions;
1415
use FOS\RestBundle\Controller\Annotations\RequestParam;
1516
use Symfony\Component\Validator\Constraints\IdenticalTo;
1617

@@ -41,6 +42,21 @@ public function __construct(
4142
bool $nullable = false,
4243
bool $allowBlank = true
4344
) {
44-
parent::__construct($name, $key, null !== $identicalTo ? new IdenticalTo($identicalTo) : null, $default, $description, $incompatibles, $strict, $map, $nullable, $allowBlank);
45+
$validatorSupportsArrayConfig = true;
46+
if (class_exists(InstalledVersions::class)) {
47+
$validatorVersion = InstalledVersions::getVersion('symfony/validator');
48+
49+
$validatorSupportsArrayConfig = version_compare($validatorVersion, '8.0', '<');
50+
}
51+
52+
if (null === $identicalTo) {
53+
$options = null;
54+
} elseif ($validatorSupportsArrayConfig) {
55+
$options = $identicalTo;
56+
} else {
57+
$options = $identicalTo['value'];
58+
}
59+
60+
parent::__construct($name, $key, null !== $options ? new IdenticalTo($options) : null, $default, $description, $incompatibles, $strict, $map, $nullable, $allowBlank);
4561
}
4662
}

0 commit comments

Comments
 (0)