Skip to content

Commit 77e23a5

Browse files
Merge branch '3.4' into 4.3
* 3.4: Fix tests Fix deprecated phpunit annotation
2 parents 47df72e + 234328e commit 77e23a5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+242
-359
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\UnexpectedValueException
36-
*/
3737
public function testThrowsExceptionIfNotTraversable()
3838
{
39+
$this->expectException('Symfony\Component\Validator\Exception\UnexpectedValueException');
3940
$this->validator->validate('foo.barbar', new All(new Range(['min' => 4])));
4041
}
4142

Tests/Constraints/BicValidatorTest.php

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -103,12 +103,10 @@ public function testNoViolationOnNullObjectWithPropertyPath()
103103
$this->assertNoViolation();
104104
}
105105

106-
/**
107-
* @expectedException \Symfony\Component\Validator\Exception\ConstraintDefinitionException
108-
* @expectedExceptionMessage The "iban" and "ibanPropertyPath" options of the Iban constraint cannot be used at the same time
109-
*/
110106
public function testThrowsConstraintExceptionIfBothValueAndPropertyPath()
111107
{
108+
$this->expectException('Symfony\Component\Validator\Exception\ConstraintDefinitionException');
109+
$this->expectExceptionMessage('The "iban" and "ibanPropertyPath" options of the Iban constraint cannot be used at the same time');
112110
new Bic([
113111
'iban' => 'value',
114112
'ibanPropertyPath' => 'propertyPath',
@@ -129,11 +127,9 @@ public function testInvalidValuePath()
129127
$this->validator->validate('UNCRIT2B912', $constraint);
130128
}
131129

132-
/**
133-
* @expectedException \Symfony\Component\Validator\Exception\UnexpectedValueException
134-
*/
135130
public function testExpectsStringCompatibleType()
136131
{
132+
$this->expectException('Symfony\Component\Validator\Exception\UnexpectedValueException');
137133
$this->validator->validate(new \stdClass(), new Bic());
138134
}
139135

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\UnexpectedValueException
42-
*/
4343
public function testExpectArrayIfMultipleIsTrue()
4444
{
45+
$this->expectException('Symfony\Component\Validator\Exception\UnexpectedValueException');
4546
$constraint = new Choice([
4647
'choices' => ['foo', 'bar'],
4748
'multiple' => true,
@@ -62,19 +63,15 @@ public function testNullIsValid()
6263
$this->assertNoViolation();
6364
}
6465

65-
/**
66-
* @expectedException \Symfony\Component\Validator\Exception\ConstraintDefinitionException
67-
*/
6866
public function testChoicesOrCallbackExpected()
6967
{
68+
$this->expectException('Symfony\Component\Validator\Exception\ConstraintDefinitionException');
7069
$this->validator->validate('foobar', new Choice());
7170
}
7271

73-
/**
74-
* @expectedException \Symfony\Component\Validator\Exception\ConstraintDefinitionException
75-
*/
7672
public function testValidCallbackExpected()
7773
{
74+
$this->expectException('Symfony\Component\Validator\Exception\ConstraintDefinitionException');
7875
$this->validator->validate('foobar', new Choice(['callback' => 'abcd']));
7976
}
8077

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\UnexpectedValueException
57-
*/
5858
public function testThrowsExceptionIfNotTraversable()
5959
{
60+
$this->expectException('Symfony\Component\Validator\Exception\UnexpectedValueException');
6061
$this->validator->validate('foobar', new Collection(['fields' => [
6162
'foo' => new Range(['min' => 4]),
6263
]]));

0 commit comments

Comments
 (0)