8000 Remove eval trick · symfony/symfony@650dc51 · GitHub
[go: up one dir, main page]

Skip to content

Commit 650dc51

Browse files
committed
Remove eval trick
1 parent 1355464 commit 650dc51

33 files changed

+78
-78
lines changed

src/Symfony/Bridge/Doctrine/Tests/Validator/Constraints/UniqueEntityValidatorTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ public function provideUniquenessConstraints(): iterable
193193
'em' => self::EM_NAME,
194194
])];
195195

196-
yield 'Named arguments' => [eval('return new \Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity(message: "myMessage", fields: ["name"], em: "foo");')];
196+
yield 'Named arguments' => [new UniqueEntity(message: "myMessage", fields: ["name"], em: "foo")];
197197
}
198198

199199
/**
@@ -227,7 +227,7 @@ public function provideConstraintsWithCustomErrorPath(): iterable
227227
'errorPath' => 'bar',
228228
])];
229229

230-
yield 'Named arguments' => [eval('return new \Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity(message: "myMessage", fields: ["name"], em: "foo", errorPath: "bar");')];
230+
yield 'Named arguments' => [new UniqueEntity(message: "myMessage", fields: ["name"], em: "foo", errorPath: "bar")];
231231
}
232232

233233
/**
@@ -286,7 +286,7 @@ public function provideConstraintsWithIgnoreNullDisabled(): iterable
286286
'ignoreNull' => false,
287287
])];
288288

289-
yield 'Named arguments' => [eval('return new \Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity(message: "myMessage", fields: ["name", "name2"], em: "foo", ignoreNull: false);')];
289+
yield 'Named arguments' => [new UniqueEntity(message: "myMessage", fields: ["name", "name2"], em: "foo", ignoreNull: false)];
290290
}
291291

292292
/**
@@ -333,7 +333,7 @@ public function provideConstraintsWithIgnoreNullEnabled(): iterable
333333
'ignoreNull' => true,
334334
])];
335335

336-
yield 'Named arguments' => [eval('return new \Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity(message: "myMessage", fields: ["name", "name2"], em: "foo", ignoreNull: true);')];
336+
yield 'Named arguments' => [new UniqueEntity(message: "myMessage", fields: ["name", "name2"], em: "foo", ignoreNull: true)];
337337
}
338338

339339
public function testValidateUniquenessWithValidCustomErrorPath()
@@ -432,7 +432,7 @@ public function provideConstraintsWithCustomRepositoryMethod(): iterable
432432
'repositoryMethod' => 'findByCustom',
433433
])];
434434

435-
yield 'Named arguments' => [eval('return new \Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity(message: "myMessage", fields: ["name"], em: "foo", repositoryMethod: "findByCustom");')];
435+
yield 'Named arguments' => [new UniqueEntity(message: "myMessage", fields: ["name"], em: "foo", repositoryMethod: "findByCustom")];
436436
}
437437

438438
/**

src/Symfony/Component/Security/Core/Tests/Validator/Constraints/UserPasswordTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public function provideServiceValidatedConstraints(): iterable
3737
{
3838
yield 'Doctrine style' => [new UserPassword(['service' => 'my_service'])];
3939

40-
yield 'named arguments' => [eval('return new \Symfony\Component\Security\Core\Validator\Constraints\UserPassword(service: "my_service");')];
40+
yield 'named arguments' => [new UserPassword(service: "my_service")];
4141

4242
$metadata = new ClassMetadata(UserPasswordDummy::class);
4343
self::assertTrue((new AnnotationLoader())->loadClassMetadata($metadata));

src/Symfony/Component/Security/Core/Tests/Validator/Constraints/UserPasswordValidatorTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ public function provideConstraints(): iterable
9595
{
9696
yield 'Doctrine style' => [new UserPassword(['message' => 'myMessage'])];
9797

98-
yield 'named arguments' => [eval('return new \Symfony\Component\Security\Core\Validator\Constraints\UserPassword(message: "myMessage");')];
98+
yield 'named arguments' => [new UserPassword(message: "myMessage")];
9999
}
100100

101101
/**

src/Symfony/Component/Validator/Tests/Constraints/BicValidatorTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ public function testInvalidBics($bic, $code)
223223
*/
224224
public function testInvalidBicsNamed($bic, $code)
225225
{
226-
$constraint = eval('return new \Symfony\Component\Validator\Constraints\Bic(message: "myMessage");');
226+
$constraint = new Bic(message: "myMessage");
227227

228228
$this->validator->validate($bic, $constraint);
229229

src/Symfony/Component/Validator/Tests/Constraints/CallbackValidatorTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ public function testPayloadIsPassedToCallback()
243243
$this->assertEquals('Hello world!', $payloadCopy);
244244

245245
$payloadCopy = 'Replace me!';
246-
$constraint = eval('return new \Symfony\Component\Validator\Constraints\Callback(callback: $callback, payload: "Hello world!");');
246+
$constraint = new Callback(callback: $callback, payload: "Hello world!");
247247
$this->validator->validate($object, $constraint);
248248
$this->assertEquals('Hello world!', $payloadCopy);
249249
$payloadCopy = 'Replace me!';

src/Symfony/Component/Validator/Tests/Constraints/ChoiceValidatorTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ public function provideConstraintsWithChoicesArray(): iterable
8989
yield 'Doctrine style' => [new Choice(['choices' => ['foo', 'bar']])];
9090
yield 'Doctrine default option' => [new Choice(['value' => ['foo', 'bar']])];
9191
yield 'first argument' => [new Choice(['foo', 'bar'])];
92-
yield 'named arguments' => [eval('return new \Symfony\Component\Validator\Constraints\Choice(choices: ["foo", "bar"]);')];
92+
yield 'named arguments' => [new Choice(choices: ["foo", "bar"])];
9393
}
9494

9595
/**
@@ -111,9 +111,9 @@ public function provideConstraintsWithCallbackFunction(): iterable
111111
},
112112
])];
113113
yield 'doctrine style, static method' => [new Choice(['callback' => [__CLASS__, 'staticCallback']])];
114-
yield 'named arguments, namespaced function' => [eval("return new \Symfony\Component\Validator\Constraints\Choice(callback: 'Symfony\Component\Validator\Tests\Constraints\choice_callback');")];
115-
yield 'named arguments, closure' => [eval('return new \Symfony\Component\Validator\Constraints\Choice(callback: fn () => ["foo", "bar"]);')];
116-
yield 'named arguments, static method' => [eval('return new \Symfony\Component\Validator\Constraints\Choice(callback: ["Symfony\Component\Validator\Tests\Constraints\ChoiceValidatorTest", "staticCallback"]);')];
114+
yield 'named arguments, namespaced function' => [new Choice(callback: 'Symfony\Component\Validator\Tests\Constraints\choice_callback')];
115+
yield 'named arguments, closure' => [new Choice(callback: fn () => ["foo", "bar"])];
116+
yield 'named arguments, static method' => [new Choice(callback: ["Symfony\Component\Validator\Tests\Constraints\ChoiceValidatorTest", "staticCallback"])];
117117
}
118118

119119
public function testValidChoiceCallbackContextMethod()
@@ -179,7 +179,7 @@ public function testInvalidChoice(Choice $constraint)
179179
public function provideConstraintsWithMessage(): iterable
180180
{
181181
yield 'Doctrine style' => [new Choice(['choices' => ['foo', 'bar'], 'message' => 'myMessage'])];
182-
yield 'named arguments' => [eval('return new \Symfony\Component\Validator\Constraints\Choice(choices: ["foo", "bar"], message: "myMessage");')];
182+
yield 'named arguments' => [new Choice(choices: ["foo", "bar"], message: "myMessage")];
183183
}
184184

185185
public function testInvalidChoiceEmptyChoices()

src/Symfony/Component/Validator/Tests/Constraints/CountValidatorTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ public function testValidValuesMax($value)
8585
*/
8686
public function testValidValuesMaxNamed($value)
8787
{
88-
$constraint = eval('return new \Symfony\Component\Validator\Constraints\Count(max: 3);');
88+
$constraint = new Count(max: 3);
8989
$this->validator->validate($value, $constraint);
9090

9191
$this->assertNoViolation();
@@ -107,7 +107,7 @@ public function testValidValuesMin($value)
107107
*/
108108
public function testValidValuesMinNamed($value)
109109
{
110-
$constraint = eval('return new \Symfony\Component\Validator\Constraints\Count(min: 5);');
110+
$constraint = new Count(min: 5);
111111
$this->validator->validate($value, $constraint);
112112

113113
$this->assertNoViolation();
@@ -129,7 +129,7 @@ public function testValidValuesExact($value)
129129
*/
130130
public function testValidValuesExactNamed($value)
131131
{
132-
$constraint = eval('return new \Symfony\Component\Validator\Constraints\Count(exactly: 4);');
132+
$constraint = new Count(exactly: 4);
133133
$this->validator->validate($value, $constraint);
134134

135135
$this->assertNoViolation();
@@ -161,7 +161,7 @@ public function testTooManyValues($value)
161161
*/
162162
public function testTooManyValuesNamed($value)
163163
{
164-
$constraint = eval('return new \Symfony\Component\Validator\Constraints\Count(max: 4, maxMessage: "myMessage");');
164+
$constraint = new Count(max: 4, maxMessage: "myMessage");
165165

166166
$this->validator->validate($value, $constraint);
167167

@@ -200,7 +200,7 @@ public function testTooFewValues($value)
200200
*/
201201
public function testTooFewValuesNamed($value)
202202
{
203-
$constraint = eval('return new \Symfony\Component\Validator\Constraints\Count(min: 4, minMessage: "myMessage");');
203+
$constraint = new Count(min: 4, minMessage: "myMessage");
204204

205205
$this->validator->validate($value, $constraint);
206206

@@ -240,7 +240,7 @@ public function testTooManyValuesExact($value)
240240
*/
241241
public function testTooManyValuesExactNamed($value)
242242
{
243-
$constraint = eval('return new \Symfony\Component\Validator\Constraints\Count(exactly: 4, exactMessage: "myMessage");');
243+
$constraint = new Count(exactly: 4, exactMessage: "myMessage");
244244

245245
$this->validator->validate($value, $constraint);
246246

src/Symfony/Component/Validator/Tests/Constraints/CountryValidatorTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ public function testInvalidAlpha3CountryNamed()
157157
{
158158
$this->validator->validate(
159159
'DE',
160-
eval('return new \Symfony\Component\Validator\Constraints\Country(alpha3: true, message: "myMessage");')
160+
new Country(alpha3: true, message: "myMessage")
161161
);
162162

163163
$this->buildViolation('myMessage')

src/Symfony/Component/Validator/Tests/Constraints/CurrencyValidatorTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ public function testInvalidCurrencies($currency)
117117
*/
118118
public function testInvalidCurrenciesNamed($currency)
119119
{
120-
$constraint = eval('return new \Symfony\Component\Validator\Constraints\Currency(message: "myMessage");');
120+
$constraint = new Currency(message: "myMessage");
121121

122122
$this->validator->validate($currency, $constraint);
123123

src/Symfony/Component/Validator/Tests/Constraints/DateTimeValidatorTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ public function getInvalidDateTimes()
118118

119119
public function testInvalidDateTimeNamed()
120120
{
121-
$constraint = eval('return new \Symfony\Component\Validator\Constraints\DateTime(message: "myMessage", format: "Y-m-d");');
121+
$constraint = new DateTime(message: "myMessage", format: "Y-m-d");
122122

123123
$this->validator->validate('2010-01-01 00:00:00', $constraint);
124124

0 commit comments

Comments
 (0)
0