Skip to content

Commit 8072323

Browse files
committed
Fix deprecated phpunit annotation
1 parent ee43e58 commit 8072323

39 files changed

+167
-205
lines changed

Tests/ConstraintTest.php

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -207,11 +207,9 @@ public function testSerializeKeepsCustomGroups()
207207
$this->assertSame(['MyGroup'], $constraint->groups);
208208
}
209209

210-
/**
211-
* @expectedException \Symfony\Component\Validator\Exception\InvalidArgumentException
212-
*/
213210
public function testGetErrorNameForUnknownCode()
214211
{
212+
$this->expectException('Symfony\Component\Validator\Exception\InvalidArgumentException');
215213
Constraint::getErrorName(1);
216214
}
217215

@@ -226,12 +224,10 @@ public function testOptionsAsDefaultOption()
226224
$this->assertEquals($options, $constraint->property2);
227225
}
228226

229-
/**
230-
* @expectedException \Symfony\Component\Validator\Exception\InvalidOptionsException
231-
* @expectedExceptionMessage The options "0", "5" do not exist in constraint "Symfony\Component\Validator\Tests\Fixtures\ConstraintA".
232-
*/
233227
public function testInvalidOptions()
234228
{
229+
$this->expectException('Symfony\Component\Validator\Exception\InvalidOptionsException');
230+
$this->expectExceptionMessage('The options "0", "5" do not exist in constraint "Symfony\Component\Validator\Tests\Fixtures\ConstraintA".');
235231
new ConstraintA(['property2' => 'foo', 'bar', 5 => 'baz']);
236232
}
237233

@@ -246,12 +242,10 @@ public function testOptionsWithInvalidInternalPointer()
246242
$this->assertEquals('foo', $constraint->property1);
247243
}
248244

249-
/**
250-
* @expectedException \Symfony\Component\Validator\Exception\ConstraintDefinitionException
251-
* @expectedExceptionMessage No default option is configured for constraint "Symfony\Component\Validator\Tests\Fixtures\ConstraintB".
252-
*/
253245
public function testAnnotationSetUndefinedDefaultOption()
254246
{
247+
$this->expectException('Symfony\Component\Validator\Exception\ConstraintDefinitionException');
248+
$this->expectExceptionMessage('No default option is configured for constraint "Symfony\Component\Validator\Tests\Fixtures\ConstraintB".');
255249
new ConstraintB(['value' => 1]);
256250
}
257251
}

Tests/Constraints/AbstractComparisonValidatorTestCase.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -84,20 +84,18 @@ public function provideInvalidConstraintOptions()
8484

8585
/**
8686
* @dataProvider provideInvalidConstraintOptions
87-
* @expectedException \Symfony\Component\Validator\Exception\ConstraintDefinitionException
88-
* @expectedExceptionMessage requires either the "value" or "propertyPath" option to be set.
8987
*/
9088
public function testThrowsConstraintExceptionIfNoValueOrPropertyPath($options)
9189
{
90+
$this->expectException('Symfony\Component\Validator\Exception\ConstraintDefinitionException');
91+
$this->expectExceptionMessage('requires either the "value" or "propertyPath" option to be set.');
9292
$this->createConstraint($options);
9393
}
9494

95-
/**
96-
* @expectedException \Symfony\Component\Validator\Exception\ConstraintDefinitionException
97-
* @expectedExceptionMessage requires only one of the "value" or "propertyPath" options to be set, not both.
98-
*/
9995
public function testThrowsConstraintExceptionIfBothValueAndPropertyPath()
10096
{
97+
$this->expectException('Symfony\Component\Validator\Exception\ConstraintDefinitionException');
98+
$this->expectExceptionMessage('requires only one of the "value" or "propertyPath" options to be set, not both.');
10199
$this->createConstraint(([
102100
'value' => 'value',
103101
'propertyPath' => 'propertyPath',

Tests/Constraints/AllTest.php

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Component\Validator\Tests\Constraints;
1313

1414
use PHPUnit\Framework\TestCase;
15+
use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait;
1516
use Symfony\Component\Validator\Constraints\All;
1617
use Symfony\Component\Validator\Constraints\Valid;
1718

@@ -20,21 +21,19 @@
2021
*/
2122
class AllTest extends TestCase
2223
{
23-
/**
24-
* @expectedException \Symfony\Component\Validator\Exception\ConstraintDefinitionException
25-
*/
24+
use ForwardCompatTestTrait;
25+
2626
public function testRejectNonConstraints()
2727
{
28+
$this->expectException('Symfony\Component\Validator\Exception\ConstraintDefinitionException');
2829
new All([
2930
'foo',
3031
]);
3132
}
3233

33-
/**
34-
* @expectedException \Symfony\Component\Validator\Exception\ConstraintDefinitionException
35-
*/
3634
public function testRejectValidConstraint()
3735
{
36+
$this->expectException('Symfony\Component\Validator\Exception\ConstraintDefinitionException');
3837
new All([
3938
new Valid(),
4039
]);

Tests/Constraints/AllValidatorTest.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Symfony\Component\Validator\Tests\Constraints;
1313

14+
use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait;
1415
use Symfony\Component\Validator\Constraints\All;
1516
use Symfony\Component\Validator\Constraints\AllValidator;
1617
use Symfony\Component\Validator\Constraints\NotNull;
@@ -19,6 +20,8 @@
1920

2021
class AllValidatorTest extends ConstraintValidatorTestCase
2122
{
23+
use ForwardCompatTestTrait;
24+
2225
protected function createValidator()
2326
{
2427
return new AllValidator();
@@ -31,11 +34,9 @@ public function testNullIsValid()
3134
$this->assertNoViolation();
3235
}
3336

34-
/**
35-
* @expectedException \Symfony\Component\Validator\Exception\UnexpectedTypeException
36-
*/
3737
public function testThrowsExceptionIfNotTraversable()
3838
{
39+
$this->expectException('Symfony\Component\Validator\Exception\UnexpectedTypeException');
3940
$this->validator->validate('foo.barbar', new All(new Range(['min' => 4])));
4041
}
4142

Tests/Constraints/CallbackValidatorTest.php

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Symfony\Component\Validator\Tests\Constraints;
1313

14+
use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait;
1415
use Symfony\Component\Validator\Constraint;
1516
use Symfony\Component\Validator\Constraints\Callback;
1617
use Symfony\Component\Validator\Constraints\CallbackValidator;
@@ -46,6 +47,8 @@ public static function validateStatic($object, ExecutionContextInterface $contex
4647

4748
class CallbackValidatorTest extends ConstraintValidatorTestCase
4849
{
50+
use ForwardCompatTestTrait;
51+
4952
protected function createValidator()
5053
{
5154
return new CallbackValidator();
@@ -180,21 +183,17 @@ public function testArrayCallableExplicitName()
180183
->assertRaised();
181184
}
182185

183-
/**
184-
* @expectedException \Symfony\Component\Validator\Exception\ConstraintDefinitionException
185-
*/
186186
public function testExpectValidMethods()
187187
{
188+
$this->expectException('Symfony\Component\Validator\Exception\ConstraintDefinitionException');
188189
$object = new CallbackValidatorTest_Object();
189190

190191
$this->validator->validate($object, new Callback(['callback' => ['foobar']]));
191192
}
192193

193-
/**
194-
* @expectedException \Symfony\Component\Validator\Exception\ConstraintDefinitionException
195-
*/
196194
public function testExpectValidCallbacks()
197195
{
196+
$this->expectException('Symfony\Component\Validator\Exception\ConstraintDefinitionException');
198197
$object = new CallbackValidatorTest_Object();
199198

200199
$this->validator->validate($object, new Callback(['callback' => ['foo', 'bar']]));

Tests/Constraints/ChoiceValidatorTest.php

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Symfony\Component\Validator\Tests\Constraints;
1313

14+
use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait;
1415
use Symfony\Component\Validator\Constraints\Choice;
1516
use Symfony\Component\Validator\Constraints\ChoiceValidator;
1617
use Symfony\Component\Validator\Test\ConstraintValidatorTestCase;
@@ -22,6 +23,8 @@ function choice_callback()
2223

2324
class ChoiceValidatorTest extends ConstraintValidatorTestCase
2425
{
26+
use ForwardCompatTestTrait;
27+
2528
protected function createValidator()
2629
{
2730
return new ChoiceValidator();
@@ -37,11 +40,9 @@ public function objectMethodCallback()
3740
return ['foo', 'bar'];
3841
}
3942

40-
/**
41-
* @expectedException \Symfony\Component\Validator\Exception\UnexpectedTypeException
42-
*/
4343
public function testExpectArrayIfMultipleIsTrue()
4444
{
45+
$this->expectException('Symfony\Component\Validator\Exception\UnexpectedTypeException');
4546
$constraint = new Choice([
4647
'choices' => ['foo', 'bar'],
4748
'multiple' => true,
@@ -64,19 +65,15 @@ public function testNullIsValid()
6465
$this->assertNoViolation();
6566
}
6667

67-
/**
68-
* @expectedException \Symfony\Component\Validator\Exception\ConstraintDefinitionException
69-
*/
7068
public function testChoicesOrCallbackExpected()
7169
{
70+
$this->expectException('Symfony\Component\Validator\Exception\ConstraintDefinitionException');
7271
$this->validator->validate('foobar', new Choice(['strict' => true]));
7372
}
7473

75-
/**
76-
* @expectedException \Symfony\Component\Validator\Exception\ConstraintDefinitionException
77-
*/
7874
public function testValidCallbackExpected()
7975
{
76+
$this->expectException('Symfony\Component\Validator\Exception\ConstraintDefinitionException');
8077
$this->validator->validate('foobar', new Choice(['callback' => 'abcd', 'strict' => true]));
8178
}
8279

Tests/Constraints/CollectionTest.php

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Component\Validator\Tests\Constraints;
1313

1414
use PHPUnit\Framework\TestCase;
15+
use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait;
1516
use Symfony\Component\Validator\Constraints\Collection;
1617
use Symfony\Component\Validator\Constraints\Email;
1718
use Symfony\Component\Validator\Constraints\Optional;
@@ -23,51 +24,43 @@
2324
*/
2425
class CollectionTest extends TestCase
2526
{
26-
/**
27-
* @expectedException \Symfony\Component\Validator\Exception\ConstraintDefinitionException
28-
*/
27+
use ForwardCompatTestTrait;
28+
2929
public function testRejectInvalidFieldsOption()
3030
{
31+
$this->expectException('Symfony\Component\Validator\Exception\ConstraintDefinitionException');
3132
new Collection([
3233
'fields' => 'foo',
3334
]);
3435
}
3536

36-
/**
37-
* @expectedException \Symfony\Component\Validator\Exception\ConstraintDefinitionException
38-
*/
3937
public function testRejectNonConstraints()
4038
{
39+
$this->expectException('Symfony\Component\Validator\Exception\ConstraintDefinitionException');
4140
new Collection([
4241
'foo' => 'bar',
4342
]);
4443
}
4544

46-
/**
47-
* @expectedException \Symfony\Component\Validator\Exception\ConstraintDefinitionException
48-
*/
4945
public function testRejectValidConstraint()
5046
{
47+
$this->expectException('Symfony\Component\Validator\Exception\ConstraintDefinitionException');
5148
new Collection([
5249
'foo' => new Valid(),
5350
]);
5451
}
5552

56-
/**
57-
* @expectedException \Symfony\Component\Validator\Exception\ConstraintDefinitionException
58-
*/
5953
public function testRejectValidConstraintWithinOptional()
6054
{
55+
$this->expectException('Symfony\Component\Validator\Exception\ConstraintDefinitionException');
6156
new Collection([
6257
'foo' => new Optional(new Valid()),
6358
]);
6459
}
6560

66-
/**
67-
* @expectedException \Symfony\Component\Validator\Exception\ConstraintDefinitionException
68-
*/
6961
public function testRejectValidConstraintWithinRequired()
7062
{
63+
$this->expectException('Symfony\Component\Validator\Exception\ConstraintDefinitionException');
7164
new Collection([
7265
'foo' => new Required(new Valid()),
7366
]);

Tests/Constraints/CollectionValidatorTest.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Symfony\Component\Validator\Tests\Constraints;
1313

14+
use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait;
1415
use Symfony\Component\Validator\Constraints\Collection;
1516
use Symfony\Component\Validator\Constraints\CollectionValidator;
1617
use Symfony\Component\Validator\Constraints\NotNull;
@@ -21,6 +22,8 @@
2122

2223
abstract class CollectionValidatorTest extends ConstraintValidatorTestCase
2324
{
25+
use ForwardCompatTestTrait;
26+
2427
protected function createValidator()
2528
{
2629
return new CollectionValidator();
@@ -52,11 +55,9 @@ public function testFieldsAsDefaultOption()
5255
$this->assertNoViolation();
5356
}
5457

55-
/**
56-
* @expectedException \Symfony\Component\Validator\Exception\UnexpectedTypeException
57-
*/
5858
public function testThrowsExceptionIfNotTraversable()
5959
{
60+
$this->expectException('Symfony\Component\Validator\Exception\UnexpectedTypeException');
6061
$this->validator->validate('foobar', new Collection(['fields' => [
6162
'foo' => new Range(['min' => 4]),
6263
]]));

Tests/Constraints/CompositeTest.php

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Component\Validator\Tests\Constraints;
1313

1414
use PHPUnit\Framework\TestCase;
15+
use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait;
1516
use Symfony\Component\Validator\Constraints\Composite;
1617
use Symfony\Component\Validator\Constraints\NotBlank;
1718
use Symfony\Component\Validator\Constraints\NotNull;
@@ -37,6 +38,8 @@ public function getDefaultOption()
3738
*/
3839
class CompositeTest extends TestCase
3940
{
41+
use ForwardCompatTestTrait;
42+
4043
public function testMergeNestedGroupsIfNoExplicitParentGroup()
4144
{
4245
$constraint = new ConcreteComposite([
@@ -79,11 +82,9 @@ public function testExplicitNestedGroupsMustBeSubsetOfExplicitParentGroups()
7982
$this->assertEquals(['Strict'], $constraint->constraints[1]->groups);
8083
}
8184

82-
/**
83-
* @expectedException \Symfony\Component\Validator\Exception\ConstraintDefinitionException
84-
*/
8585
public function testFailIfExplicitNestedGroupsNotSubsetOfExplicitParentGroups()
8686
{
87+
$this->expectException('Symfony\Component\Validator\Exception\ConstraintDefinitionException');
8788
new ConcreteComposite([
8889
'constraints' => [
8990
new NotNull(['groups' => ['Default', 'Foobar']]),
@@ -114,33 +115,27 @@ public function testSingleConstraintsAccepted()
114115
$this->assertEquals([$nestedConstraint], $constraint->constraints);
115116
}
116117

117-
/**
118-
* @expectedException \Symfony\Component\Validator\Exception\ConstraintDefinitionException
119-
*/
120118
public function testFailIfNoConstraint()
121119
{
120+
$this->expectException('Symfony\Component\Validator\Exception\ConstraintDefinitionException');
122121
new ConcreteComposite([
123122
new NotNull(['groups' => 'Default']),
124123
'NotBlank',
125124
]);
126125
}
127126

128-
/**
129-
* @expectedException \Symfony\Component\Validator\Exception\ConstraintDefinitionException
130-
*/
131127
public function testFailIfNoConstraintObject()
132128
{
129+
$this->expectException('Symfony\Component\Validator\Exception\ConstraintDefinitionException');
133130
new ConcreteComposite([
134131
new NotNull(['groups' => 'Default']),
135132
new \ArrayObject(),
136133
]);
137134
}
138135

139-
/**
140-
* @expectedException \Symfony\Component\Validator\Exception\ConstraintDefinitionException
141-
*/
142136
public function testValidCantBeNested()
143137
{
138+
$this->expectException('Symfony\Component\Validator\Exception\ConstraintDefinitionException');
144139
new ConcreteComposite([
145140
new Valid(),
146141
]);

0 commit comments

Comments
 (0)