@@ -162,15 +162,11 @@ private function createSchema($em)
162
162
163
163
/**
164
164
* This is a functional test as there is a large integration necessary to get the validator working.
165
+ *
166
+ * @dataProvider provideUniquenessConstraints
165
167
*/
166
- public function testValidateUniqueness ()
168
+ public function testValidateUniqueness (UniqueEntity $ constraint )
167
169
{
168
- $ constraint = new UniqueEntity ([
169
- 'message ' => 'myMessage ' ,
170
- 'fields ' => ['name ' ],
171
- 'em ' => self ::EM_NAME ,
172
- ]);
173
-
174
170
$ entity1 = new SingleIntIdEntity (1 , 'Foo ' );
175
171
$ entity2 = new SingleIntIdEntity (2 , 'Foo ' );
176
172
@@ -196,15 +192,24 @@ public function testValidateUniqueness()
196
192
->assertRaised ();
197
193
}
198
194
199
- public function testValidateCustomErrorPath ()
195
+ public function provideUniquenessConstraints (): iterable
200
196
{
201
- $ constraint = new UniqueEntity ([
197
+ yield ' Doctrine style ' => [ new UniqueEntity ([
202
198
'message ' => 'myMessage ' ,
203
199
'fields ' => ['name ' ],
204
200
'em ' => self ::EM_NAME ,
205
- 'errorPath ' => 'bar ' ,
206
- ]);
201
+ ])];
202
+
203
+ if (\PHP_VERSION_ID >= 80000 ) {
204
+ yield 'Named arguments ' => [eval ('return new \Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity(message: "myMessage", fields: ["name"], em: "foo"); ' )];
205
+ }
206
+ }
207
207
208
+ /**
209
+ * @dataProvider provideConstraintsWithCustomErrorPath
210
+ */
211
+ public function testValidateCustomErrorPath (UniqueEntity $ constraint )
212
+ {
208
213
$ entity1 = new SingleIntIdEntity (1 , 'Foo ' );
209
214
$ entity2 = new SingleIntIdEntity (2 , 'Foo ' );
210
215
@@ -222,14 +227,25 @@ public function testValidateCustomErrorPath()
222
227
->assertRaised ();
223
228
}
224
229
225
- public function testValidateUniquenessWithNull ()
230
+ public function provideConstraintsWithCustomErrorPath (): iterable
226
231
{
227
- $ constraint = new UniqueEntity ([
232
+ yield ' Doctrine style ' => [ new UniqueEntity ([
228
233
'message ' => 'myMessage ' ,
229
234
'fields ' => ['name ' ],
230
235
'em ' => self ::EM_NAME ,
231
- ]);
236
+ 'errorPath ' => 'bar ' ,
237
+ ])];
232
238
239
+ if (\PHP_VERSION_ID >= 80000 ) {
240
+ yield 'Named arguments ' => [eval ('return new \Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity(message: "myMessage", fields: ["name"], em: "foo", errorPath: "bar"); ' )];
241
+ }
242
+ }
243
+
244
+ /**
245
+ * @dataProvider provideUniquenessConstraints
246
+ */
247
+ public function testValidateUniquenessWithNull (UniqueEntity $ constraint )
248
+ {
233
249
$ entity1 = new SingleIntIdEntity (1 , null );
234
250
$ entity2 = new SingleIntIdEntity (2 , null );
235
251
@@ -242,15 +258,11 @@ public function testValidateUniquenessWithNull()
242
258
$ this ->assertNoViolation ();
243
259
}
244
260
245
- public function testValidateUniquenessWithIgnoreNullDisabled ()
261
+ /**
262
+ * @dataProvider provideConstraintsWithIgnoreNullDisabled
263
+ */
264
+ public function testValidateUniquenessWithIgnoreNullDisabled (UniqueEntity $ constraint )
246
265
{
247
- $ constraint = new UniqueEntity ([
248
- 'message ' => 'myMessage ' ,
249
- 'fields ' => ['name ' , 'name2 ' ],
250
- 'em ' => self ::EM_NAME ,
251
- 'ignoreNull ' => false ,
252
- ]);
253
-
254
266
$ entity1 = new DoubleNameEntity (1 , 'Foo ' , null );
255
267
$ entity2 = new DoubleNameEntity (2 , 'Foo ' , null );
256
268
@@ -276,30 +288,36 @@ public function testValidateUniquenessWithIgnoreNullDisabled()
276
288
->assertRaised ();
277
289
}
278
290
279
- public function testAllConfiguredFieldsAreCheckedOfBeingMappedByDoctrineWithIgnoreNullEnabled ()
291
+ public function provideConstraintsWithIgnoreNullDisabled (): iterable
280
292
{
281
- $ this ->expectException ('Symfony\Component\Validator\Exception\ConstraintDefinitionException ' );
282
- $ constraint = new UniqueEntity ([
293
+ yield 'Doctrine style ' => [new UniqueEntity ([
283
294
'message ' => 'myMessage ' ,
284
295
'fields ' => ['name ' , 'name2 ' ],
285
296
'em ' => self ::EM_NAME ,
286
- 'ignoreNull ' => true ,
287
- ]);
297
+ 'ignoreNull ' => false ,
298
+ ])] ;
288
299
300
+ if (\PHP_VERSION_ID >= 80000 ) {
301
+ yield 'Named arguments ' => [eval ('return new \Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity(message: "myMessage", fields: ["name", "name2"], em: "foo", ignoreNull: false); ' )];
302
+ }
303
+ }
304
+
305
+ /**
306
+ * @dataProvider provideConstraintsWithIgnoreNullEnabled
307
+ */
308
+ public function testAllConfiguredFieldsAreCheckedOfBeingMappedByDoctrineWithIgnoreNullEnabled (UniqueEntity $ constraint )
309
+ {
289
310
$ entity1 = new SingleIntIdEntity (1 , null );
290
311
312
+ $ this ->expectException ('Symfony\Component\Validator\Exception\ConstraintDefinitionException ' );
291
313
$ this ->validator ->validate ($ entity1 , $ constraint );
292
314
}
293
315
294
- public function testNoValidationIfFirstFieldIsNullAndNullValuesAreIgnored ()
316
+ /**
317
+ * @dataProvider provideConstraintsWithIgnoreNullEnabled
318
+ */
319
+ public function testNoValidationIfFirstFieldIsNullAndNullValuesAreIgnored (UniqueEntity $ constraint )
295
320
{
296
- $ constraint = new UniqueEntity ([
297
- 'message ' => 'myMessage ' ,
298
- 'fields ' => ['name ' , 'name2 ' ],
299
- 'em ' => self ::EM_NAME ,
300
- 'ignoreNull ' => true ,
301
- ]);
302
-
303
321
$ entity1 = new DoubleNullableNameEntity (1 , null , 'Foo ' );
304
322
$ entity2 = new DoubleNullableNameEntity (2 , null , 'Foo ' );
305
323
@@ -319,6 +337,20 @@ public function testNoValidationIfFirstFieldIsNullAndNullValuesAreIgnored()
319
337
$ this ->assertNoViolation ();
320
338
}
321
339
340
+ public function provideConstraintsWithIgnoreNullEnabled (): iterable
341
+ {
342
+ yield 'Doctrine style ' => [new UniqueEntity ([
343
+ 'message ' => 'myMessage ' ,
344
+ 'fields ' => ['name ' , 'name2 ' ],
345
+ 'em ' => self ::EM_NAME ,
346
+ 'ignoreNull ' => true ,
347
+ ])];
348
+
349
+ if (\PHP_VERSION_ID >= 80000 ) {
350
+ yield 'Named arguments ' => [eval ('return new \Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity(message: "myMessage", fields: ["name", "name2"], em: "foo", ignoreNull: true); ' )];
351
+ }
352
+ }
353
+
322
354
public function testValidateUniquenessWithValidCustomErrorPath ()
323
355
{
324
356
$ constraint = new UniqueEntity ([
@@ -353,15 +385,11 @@ public function testValidateUniquenessWithValidCustomErrorPath()
353
385
->assertRaised ();
354
386
}
355
387
356
- public function testValidateUniquenessUsingCustomRepositoryMethod ()
388
+ /**
389
+ * @dataProvider provideConstraintsWithCustomRepositoryMethod
390
+ */
391
+ public function testValidateUniquenessUsingCustomRepositoryMethod (UniqueEntity $ constraint )
357
392
{
358
- $ constraint = new UniqueEntity ([
359
- 'message ' => 'myMessage ' ,
360
- 'fields ' => ['name ' ],
361
- 'em ' => self ::EM_NAME ,
362
- 'repositoryMethod ' => 'findByCustom ' ,
363
- ]);
364
-
365
393
$ repository = $ this ->createRepositoryMock ();
366
394
$ repository ->expects ($ this ->once ())
367
395
->method ('findByCustom ' )
@@ -379,15 +407,11 @@ public function testValidateUniquenessUsingCustomRepositoryMethod()
379
407
$ this ->assertNoViolation ();
380
408
}
381
409
382
- public function testValidateUniquenessWithUnrewoundArray ()
410
+ /**
411
+ * @dataProvider provideConstraintsWithCustomRepositoryMethod
412
+ */
413
+ public function testValidateUniquenessWithUnrewoundArray (UniqueEntity $ constraint )
383
414
{
384
- $ constraint = new UniqueEntity ([
385
- 'message ' => 'myMessage ' ,
386
- 'fields ' => ['name ' ],
387
- 'em ' => self ::EM_NAME ,
388
- 'repositoryMethod ' => 'findByCustom ' ,
389
- ]);
390
-
391
415
$ entity = new SingleIntIdEntity (1 , 'foo ' );
392
416
393
417
$ repository = $ this ->createRepositoryMock ();
@@ -414,6 +438,20 @@ function () use ($entity) {
414
438
$ this ->assertNoViolation ();
415
439
}
416
440
441
+ public function provideConstraintsWithCustomRepositoryMethod (): iterable
442
+ {
443
+ yield 'Doctrine style ' => [new UniqueEntity ([
444
+ 'message ' => 'myMessage ' ,
445
+ 'fields ' => ['name ' ],
446
+ 'em ' => self ::EM_NAME ,
447
+ 'repositoryMethod ' => 'findByCustom ' ,
448
+ ])];
449
+
450
+ if (\PHP_VERSION_ID >= 80000 ) {
451
+ yield 'Named arguments ' => [eval ('return new \Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity(message: "myMessage", fields: ["name"], em: "foo", repositoryMethod: "findByCustom"); ' )];
452
+ }
453
+ }
454
+
417
455
/**
418
456
* @dataProvider resultTypesProvider
419
457
*/
0 commit comments