Skip to content

Commit 9edf674

Browse files
Merge branch '5.1' into 5.2
* 5.1: Use createMock() and use import instead of FQCN
2 parents c4077f2 + abcd19e commit 9edf674

Some content is hidden

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

57 files changed

+207
-135
lines changed

Test/ConstraintValidatorTestCase.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
use Symfony\Component\Validator\Mapping\ClassMetadata;
3131
use Symfony\Component\Validator\Mapping\PropertyMetadata;
3232
use Symfony\Component\Validator\Validator\ContextualValidatorInterface;
33+
use Symfony\Component\Validator\Validator\ValidatorInterface;
3334
use Symfony\Contracts\Translation\TranslatorInterface;
3435

3536
/**
@@ -110,9 +111,9 @@ protected function restoreDefaultTimezone()
110111

111112
protected function createContext()
112113
{
113-
$translator = $this->getMockBuilder(TranslatorInterface::class)->getMock();
114+
$translator = $this->createMock(TranslatorInterface::class);
114115
$translator->expects($this->any())->method('trans')->willReturnArgument(0);
115-
$validator = $this->getMockBuilder(\Symfony\Component\Validator\Validator\ValidatorInterface::class)->getMock();
116+
$validator = $this->createMock(ValidatorInterface::class);
116117
$validator->expects($this->any())
117118
->method('validate')
118119
->willReturnCallback(function () {

Tests/ConstraintTest.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@
1313

1414
use PHPUnit\Framework\TestCase;
1515
use Symfony\Component\Validator\Constraint;
16+
use Symfony\Component\Validator\Exception\ConstraintDefinitionException;
17+
use Symfony\Component\Validator\Exception\InvalidArgumentException;
1618
use Symfony\Component\Validator\Exception\InvalidOptionsException;
19+
use Symfony\Component\Validator\Exception\MissingOptionsException;
1720
use Symfony\Component\Validator\Tests\Fixtures\ClassConstraint;
1821
use Symfony\Component\Validator\Tests\Fixtures\ConstraintA;
1922
use Symfony\Component\Validator\Tests\Fixtures\ConstraintB;
@@ -104,14 +107,14 @@ public function testDontSetDefaultPropertyIfValuePropertyExists()
104107

105108
public function testSetUndefinedDefaultProperty()
106109
{
107-
$this->expectException(\Symfony\Component\Validator\Exception\ConstraintDefinitionException::class);
110+
$this->expectException(ConstraintDefinitionException::class);
108111

109112
new ConstraintB('foo');
110113
}
111114

112115
public function testRequiredOptionsMustBeDefined()
113116
{
114-
$this->expectException(\Symfony\Component\Validator\Exception\MissingOptionsException::class);
117+
$this->expectException(MissingOptionsException::class);
115118

116119
new ConstraintC();
117120
}
@@ -209,7 +212,7 @@ public function testSerializeKeepsCustomGroups()
209212

210213
public function testGetErrorNameForUnknownCode()
211214
{
212-
$this->expectException(\Symfony\Component\Validator\Exception\InvalidArgumentException::class);
215+
$this->expectException(InvalidArgumentException::class);
213216
Constraint::getErrorName(1);
214217
}
215218

@@ -244,7 +247,7 @@ public function testOptionsWithInvalidInternalPointer()
244247

245248
public function testAnnotationSetUndefinedDefaultOption()
246249
{
247-
$this->expectException(\Symfony\Component\Validator\Exception\ConstraintDefinitionException::class);
250+
$this->expectException(ConstraintDefinitionException::class);
248251
$this->expectExceptionMessage('No default option is configured for constraint "Symfony\Component\Validator\Tests\Fixtures\ConstraintB".');
249252
new ConstraintB(['value' => 1]);
250253
}

Tests/Constraints/AllTest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use PHPUnit\Framework\TestCase;
1515
use Symfony\Component\Validator\Constraints\All;
1616
use Symfony\Component\Validator\Constraints\Valid;
17+
use Symfony\Component\Validator\Exception\ConstraintDefinitionException;
1718

1819
/**
1920
* @author Bernhard Schussek <[email protected]>
@@ -22,15 +23,15 @@ class AllTest extends TestCase
2223
{
2324
public function testRejectNonConstraints()
2425
{
25-
$this->expectException(\Symfony\Component\Validator\Exception\ConstraintDefinitionException::class);
26+
$this->expectException(ConstraintDefinitionException::class);
2627
new All([
2728
'foo',
2829
]);
2930
}
3031

3132
public function testRejectValidConstraint()
3233
{
33-
$this->expectException(\Symfony\Component\Validator\Exception\ConstraintDefinitionException::class);
34+
$this->expectException(ConstraintDefinitionException::class);
3435
new All([
3536
new Valid(),
3637
]);

Tests/Constraints/AllValidatorTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Symfony\Component\Validator\Constraints\AllValidator;
1616
use Symfony\Component\Validator\Constraints\NotNull;
1717
use Symfony\Component\Validator\Constraints\Range;
18+
use Symfony\Component\Validator\Exception\UnexpectedValueException;
1819
use Symfony\Component\Validator\Test\ConstraintValidatorTestCase;
1920

2021
class AllValidatorTest extends ConstraintValidatorTestCase
@@ -33,7 +34,7 @@ public function testNullIsValid()
3334

3435
public function testThrowsExceptionIfNotTraversable()
3536
{
36-
$this->expectException(\Symfony\Component\Validator\Exception\UnexpectedValueException::class);
37+
$this->expectException(UnexpectedValueException::class);
3738
$this->validator->validate('foo.barbar', new All(new Range(['min' => 4])));
3839
}
3940

Tests/Constraints/BicValidatorTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Symfony\Component\Validator\Constraints\Bic;
1515
use Symfony\Component\Validator\Constraints\BicValidator;
1616
use Symfony\Component\Validator\Exception\ConstraintDefinitionException;
17+
use Symfony\Component\Validator\Exception\UnexpectedValueException;
1718
use Symfony\Component\Validator\Mapping\ClassMetadata;
1819
use Symfony\Component\Validator\Mapping\Loader\AnnotationLoader;
1920
use Symfony\Component\Validator\Test\ConstraintValidatorTestCase;
@@ -182,7 +183,7 @@ public function testInvalidValuePath()
182183

183184
public function testExpectsStringCompatibleType()
184185
{
185-
$this->expectException(\Symfony\Component\Validator\Exception\UnexpectedValueException::class);
186+
$this->expectException(UnexpectedValueException::class);
186187
$this->validator->validate(new \stdClass(), new Bic());
187188
}
188189

Tests/Constraints/CallbackValidatorTest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Symfony\Component\Validator\Constraints\Callback;
1616
use Symfony\Component\Validator\Constraints\CallbackValidator;
1717
use Symfony\Component\Validator\Context\ExecutionContextInterface;
18+
use Symfony\Component\Validator\Exception\ConstraintDefinitionException;
1819
use Symfony\Component\Validator\Test\ConstraintValidatorTestCase;
1920

2021
class CallbackValidatorTest_Class
@@ -182,15 +183,15 @@ public function testArrayCallableExplicitName()
182183

183184
public function testExpectValidMethods()
184185
{
185-
$this->expectException(\Symfony\Component\Validator\Exception\ConstraintDefinitionException::class);
186+
$this->expectException(ConstraintDefinitionException::class);
186187
$object = new CallbackValidatorTest_Object();
187188

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

191192
public function testExpectValidCallbacks()
192193
{
193-
$this->expectException(\Symfony\Component\Validator\Exception\ConstraintDefinitionException::class);
194+
$this->expectException(ConstraintDefinitionException::class);
194195
$object = new CallbackValidatorTest_Object();
195196

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

Tests/Constraints/ChoiceValidatorTest.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313

1414
use Symfony\Component\Validator\Constraints\Choice;
1515
use Symfony\Component\Validator\Constraints\ChoiceValidator;
16+
use Symfony\Component\Validator\Exception\ConstraintDefinitionException;
17+
use Symfony\Component\Validator\Exception\UnexpectedValueException;
1618
use Symfony\Component\Validator\Test\ConstraintValidatorTestCase;
1719

1820
function choice_callback()
@@ -39,7 +41,7 @@ public function objectMethodCallback()
3941

4042
public function testExpectArrayIfMultipleIsTrue()
4143
{
42-
$this->expectException(\Symfony\Component\Validator\Exception\UnexpectedValueException::class);
44+
$this->expectException(UnexpectedValueException::class);
4345
$constraint = new Choice([
4446
'choices' => ['foo', 'bar'],
4547
'multiple' => true,
@@ -62,13 +64,13 @@ public function testNullIsValid()
6264

6365
public function testChoicesOrCallbackExpected()
6466
{
65-
$this->expectException(\Symfony\Component\Validator\Exception\ConstraintDefinitionException::class);
67+
$this->expectException(ConstraintDefinitionException::class);
6668
$this->validator->validate('foobar', new Choice());
6769
}
6870

6971
public function testValidCallbackExpected()
7072
{
71-
$this->expectException(\Symfony\Component\Validator\Exception\ConstraintDefinitionException::class);
73+
$this->expectException(ConstraintDefinitionException::class);
7274
$this->validator->validate('foobar', new Choice(['callback' => 'abcd']));
7375
}
7476

Tests/Constraints/CollectionTest.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use Symfony\Component\Validator\Constraints\Optional;
1818
use Symfony\Component\Validator\Constraints\Required;
1919
use Symfony\Component\Validator\Constraints\Valid;
20+
use Symfony\Component\Validator\Exception\ConstraintDefinitionException;
2021

2122
/**
2223
* @author Bernhard Schussek <[email protected]>
@@ -25,39 +26,39 @@ class CollectionTest extends TestCase
2526
{
2627
public function testRejectInvalidFieldsOption()
2728
{
28-
$this->expectException(\Symfony\Component\Validator\Exception\ConstraintDefinitionException::class);
29+
$this->expectException(ConstraintDefinitionException::class);
2930
new Collection([
3031
'fields' => 'foo',
3132
]);
3233
}
3334

3435
public function testRejectNonConstraints()
3536
{
36-
$this->expectException(\Symfony\Component\Validator\Exception\ConstraintDefinitionException::class);
37+
$this->expectException(ConstraintDefinitionException::class);
3738
new Collection([
3839
'foo' => 'bar',
3940
]);
4041
}
4142

4243
public function testRejectValidConstraint()
4344
{
44-
$this->expectException(\Symfony\Component\Validator\Exception\ConstraintDefinitionException::class);
45+
$this->expectException(ConstraintDefinitionException::class);
4546
new Collection([
4647
'foo' => new Valid(),
4748
]);
4849
}
4950

5051
public function testRejectValidConstraintWithinOptional()
5152
{
52-
$this->expectException(\Symfony\Component\Validator\Exception\ConstraintDefinitionException::class);
53+
$this->expectException(ConstraintDefinitionException::class);
5354
new Collection([
5455
'foo' => new Optional(new Valid()),
5556
]);
5657
}
5758

5859
public function testRejectValidConstraintWithinRequired()
5960
{
60-
$this->expectException(\Symfony\Component\Validator\Exception\ConstraintDefinitionException::class);
61+
$this->expectException(ConstraintDefinitionException::class);
6162
new Collection([
6263
'foo' => new Required(new Valid()),
6364
]);

Tests/Constraints/CollectionValidatorTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use Symfony\Component\Validator\Constraints\Optional;
1818
use Symfony\Component\Validator\Constraints\Range;
1919
use Symfony\Component\Validator\Constraints\Required;
20+
use Symfony\Component\Validator\Exception\UnexpectedValueException;
2021
use Symfony\Component\Validator\Test\ConstraintValidatorTestCase;
2122

2223
abstract class CollectionValidatorTest extends ConstraintValidatorTestCase
@@ -54,7 +55,7 @@ public function testFieldsAsDefaultOption()
5455

5556
public function testThrowsExceptionIfNotTraversable()
5657
{
57-
$this->expectException(\Symfony\Component\Validator\Exception\UnexpectedValueException::class);
58+
$this->expectException(UnexpectedValueException::class);
5859
$this->validator->validate('foobar', new Collection(['fields' => [
5960
'foo' => new Range(['min' => 4]),
6061
]]));

Tests/Constraints/CompositeTest.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use Symfony\Component\Validator\Constraints\NotBlank;
1717
use Symfony\Component\Validator\Constraints\NotNull;
1818
use Symfony\Component\Validator\Constraints\Valid;
19+
use Symfony\Component\Validator\Exception\ConstraintDefinitionException;
1920

2021
class ConcreteComposite extends Composite
2122
{
@@ -105,7 +106,7 @@ public function testExplicitNestedGroupsMustBeSubsetOfExplicitParentGroups()
105106

106107
public function testFailIfExplicitNestedGroupsNotSubsetOfExplicitParentGroups()
107108
{
108-
$this->expectException(\Symfony\Component\Validator\Exception\ConstraintDefinitionException::class);
109+
$this->expectException(ConstraintDefinitionException::class);
109110
new ConcreteComposite([
110111
'constraints' => [
111112
new NotNull(['groups' => ['Default', 'Foobar']]),
@@ -138,7 +139,7 @@ public function testSingleConstraintsAccepted()
138139

139140
public function testFailIfNoConstraint()
140141
{
141-
$this->expectException(\Symfony\Component\Validator\Exception\ConstraintDefinitionException::class);
142+
$this->expectException(ConstraintDefinitionException::class);
142143
new ConcreteComposite([
143144
new NotNull(['groups' => 'Default']),
144145
'NotBlank',
@@ -147,7 +148,7 @@ public function testFailIfNoConstraint()
147148

148149
public function testFailIfNoConstraintObject()
149150
{
150-
$this->expectException(\Symfony\Component\Validator\Exception\ConstraintDefinitionException::class);
151+
$this->expectException(ConstraintDefinitionException::class);
151152
new ConcreteComposite([
152153
new NotNull(['groups' => 'Default']),
153154
new \ArrayObject(),
@@ -156,7 +157,7 @@ public function testFailIfNoConstraintObject()
156157

157158
public function testValidCantBeNested()
158159
{
159-
$this->expectException(\Symfony\Component\Validator\Exception\ConstraintDefinitionException::class);
160+
$this->expectException(ConstraintDefinitionException::class);
160161
new ConcreteComposite([
161162
new Valid(),
162163
]);

0 commit comments

Comments
 (0)