Skip to content

Commit 3e75e4c

Browse files
committed
fixed obsolete getMock() usage
1 parent 6915f82 commit 3e75e4c

File tree

8 files changed

+65
-68
lines changed

8 files changed

+65
-68
lines changed

Tests/ChoiceList/Factory/DefaultChoiceListFactoryTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ function ($object) { return $object->value; }
193193

194194
public function testCreateFromLoader()
195195
{
196-
$loader = $this->getMock('Symfony\Component\Form\ChoiceList\Loader\ChoiceLoaderInterface');
196+
$loader = $this->getMockBuilder('Symfony\Component\Form\ChoiceList\Loader\ChoiceLoaderInterface')->getMock();
197197

198198
$list = $this->factory->createListFromLoader($loader);
199199

@@ -202,7 +202,7 @@ public function testCreateFromLoader()
202202

203203
public function testCreateFromLoaderWithValues()
204204
{
205-
$loader = $this->getMock('Symfony\Component\Form\ChoiceList\Loader\ChoiceLoaderInterface');
205+
$loader = $this->getMockBuilder('Symfony\Component\Form\ChoiceList\Loader\ChoiceLoaderInterface')->getMock();
206206

207207
$value = function () {};
208208
$list = $this->factory->createListFromLoader($loader, $value);

Tests/ChoiceList/Factory/PropertyAccessDecoratorTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ public function testCreateFromLoaderPropertyPath()
9797
*/
9898
public function testCreateFromLoaderPropertyPathWithCallableString()
9999
{
100-
$loader = $this->getMock('Symfony\Component\Form\ChoiceList\Loader\ChoiceLoaderInterface');
100+
$loader = $this->getMockBuilder('Symfony\Component\Form\ChoiceList\Loader\ChoiceLoaderInterface')->getMock();
101101

102102
$this->decoratedFactory->expects($this->once())
103103
->method('createListFromLoader')
@@ -173,7 +173,7 @@ public function testCreateViewPreferredChoicesAsPropertyPath()
173173
*/
174174
public function testCreateViewPreferredChoicesAsPropertyPathWithCallableString()
175175
{
176-
$list = $this->getMock('Symfony\Component\Form\ChoiceList\ChoiceListInterface');
176+
$list = $this->getMockBuilder('Symfony\Component\Form\ChoiceList\ChoiceListInterface')->getMock();
177177

178178
$this->decoratedFactory->expects($this->once())
179179
->method('createView')
@@ -244,7 +244,7 @@ public function testCreateViewLabelsAsPropertyPath()
244244
*/
245245
public function testCreateViewLabelsAsPropertyPathWithCallableString()
246246
{
247-
$list = $this->getMock('Symfony\Component\Form\ChoiceList\ChoiceListInterface');
247+
$list = $this->getMockBuilder('Symfony\Component\Form\ChoiceList\ChoiceListInterface')->getMock();
248248

249249
$this->decoratedFactory->expects($this->once())
250250
->method('createView')
@@ -300,7 +300,7 @@ public function testCreateViewIndicesAsPropertyPath()
300300
*/
301301
public function testCreateViewIndicesAsPropertyPathWithCallableString()
302302
{
303-
$list = $this->getMock('Symfony\Component\Form\ChoiceList\ChoiceListInterface');
303+
$list = $this->getMockBuilder('Symfony\Component\Form\ChoiceList\ChoiceListInterface')->getMock();
304304

305305
$this->decoratedFactory->expects($this->once())
306306
->method('createView')
@@ -359,7 +359,7 @@ public function testCreateViewGroupsAsPropertyPath()
359359
*/
360360
public function testCreateViewGroupsAsPropertyPathWithCallableString()
361361
{
362-
$list = $this->getMock('Symfony\Component\Form\ChoiceList\ChoiceListInterface');
362+
$list = $this->getMockBuilder('Symfony\Component\Form\ChoiceList\ChoiceListInterface')->getMock();
363363

364364
$this->decoratedFactory->expects($this->once())
365365
->method('createView')
@@ -442,7 +442,7 @@ public function testCreateViewAttrAsPropertyPath()
442442
*/
443443
public function testCreateViewAttrAsPropertyPathWithCallableString()
444444
{
445-
$list = $this->getMock('Symfony\Component\Form\ChoiceList\ChoiceListInterface');
445+
$list = $this->getMockBuilder('Symfony\Component\Form\ChoiceList\ChoiceListInterface')->getMock();
446446

447447
$this->decoratedFactory->expects($this->once())
448448
->method('createView')

Tests/ChoiceList/LazyChoiceListTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ class LazyChoiceListTest extends \PHPUnit_Framework_TestCase
3838

3939
protected function setUp()
4040
{
41-
$this->loadedList = $this->getMock('Symfony\Component\Form\ChoiceList\ChoiceListInterface');
42-
$this->loader = $this->getMock('Symfony\Component\Form\ChoiceList\Loader\ChoiceLoaderInterface');
41+
$this->loadedList = $this->getMockBuilder('Symfony\Component\Form\ChoiceList\ChoiceListInterface')->getMock();
42+
$this->loader = $this->getMockBuilder('Symfony\Component\Form\ChoiceList\Loader\ChoiceLoaderInterface')->getMock();
4343
$this->value = function () {};
4444
$this->list = new LazyChoiceList($this->loader, $this->value);
4545
}

Tests/Extension/Validator/Constraints/FormValidatorTest.php

Lines changed: 31 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,9 @@ class FormValidatorTest extends AbstractConstraintValidatorTest
4545

4646
protected function setUp()
4747
{
48-
$this->dispatcher = $this->getMock('Symfony\Component\EventDispatcher\EventDispatcherInterface');
49-
$this->factory = $this->getMock('Symfony\Component\Form\FormFactoryInterface');
50-
$this->serverParams = $this->getMock(
51-
'Symfony\Component\Form\Extension\Validator\Util\ServerParams',
52-
array('getNormalizedIniPostMaxSize', 'getContentLength')
53-
);
48+
$this->dispatcher = $this->getMockBuilder('Symfony\Component\EventDispatcher\EventDispatcherInterface')->getMock();
49+
$this->factory = $this->getMockBuilder('Symfony\Component\Form\FormFactoryInterface')->getMock();
50+
$this->serverParams = $this->getMockBuilder('Symfony\Component\Form\Extension\Validator\Util\ServerParams')->setMethods(array('getNormalizedIniPostMaxSize', 'getContentLength'))->getMock();
5451

5552
parent::setUp();
5653
}
@@ -62,7 +59,7 @@ protected function createValidator()
6259

6360
public function testValidate()
6461
{
65-
$object = $this->getMock('\stdClass');
62+
$object = $this->getMockBuilder('\stdClass')->getMock();
6663
$options = array('validation_groups' => array('group1', 'group2'));
6764
$form = $this->getBuilder('name', '\stdClass', $options)
6865
->setData($object)
@@ -78,7 +75,7 @@ public function testValidate()
7875

7976
public function testValidateConstraints()
8077
{
81-
$object = $this->getMock('\stdClass');
78+
$object = $this->getMockBuilder('\stdClass')->getMock();
8279
$constraint1 = new NotNull(array('groups' => array('group1', 'group2')));
8380
$constraint2 = new NotBlank(array('groups' => 'group2'));
8481

@@ -105,7 +102,7 @@ public function testValidateConstraints()
105102

106103
public function testValidateChildIfValidConstraint()
107104
{
108-
$object = $this->getMock('\stdClass');
105+
$object = $this->getMockBuilder('\stdClass')->getMock();
109106

110107
$parent = $this->getBuilder('parent')
111108
->setCompound(true)
@@ -129,7 +126,7 @@ public function testValidateChildIfValidConstraint()
129126

130127
public function testDontValidateIfParentWithoutValidConstraint()
131128
{
132-
$object = $this->getMock('\stdClass');
129+
$object = $this->getMockBuilder('\stdClass')->getMock();
133130

134131
$parent = $this->getBuilder('parent', null)
135132
->setCompound(true)
@@ -163,7 +160,7 @@ public function testMissingConstraintIndex()
163160

164161
public function testValidateConstraintsOptionEvenIfNoValidConstraint()
165162
{
166-
$object = $this->getMock('\stdClass');
163+
$object = $this->getMockBuilder('\stdClass')->getMock();
167164
$constraint1 = new NotNull(array('groups' => array('group1', 'group2')));
168165
$constraint2 = new NotBlank(array('groups' => 'group2'));
169166

@@ -190,7 +187,7 @@ public function testValidateConstraintsOptionEvenIfNoValidConstraint()
190187

191188
public function testDontValidateIfNoValidationGroups()
192189
{
193-
$object = $this->getMock('\stdClass');
190+
$object = $this->getMockBuilder('\stdClass')->getMock();
194191

195192
$form = $this->getBuilder('name', '\stdClass', array(
196193
'validation_groups' => array(),
@@ -209,9 +206,9 @@ public function testDontValidateIfNoValidationGroups()
209206

210207
public function testDontValidateConstraintsIfNoValidationGroups()
211208
{
212-
$object = $this->getMock('\stdClass');
213-
$constraint1 = $this->getMock('Symfony\Component\Validator\Constraint');
214-
$constraint2 = $this->getMock('Symfony\Component\Validator\Constraint');
209+
$object = $this->getMockBuilder('\stdClass')->getMock();
210+
$constraint1 = $this->getMockBuilder('Symfony\Component\Validator\Constraint')->getMock();
211+
$constraint2 = $this->getMockBuilder('Symfony\Component\Validator\Constraint')->getMock();
215212

216213
$options = array(
217214
'validation_groups' => array(),
@@ -233,7 +230,7 @@ public function testDontValidateConstraintsIfNoValidationGroups()
233230

234231
public function testDontValidateIfNotSynchronized()
235232
{
236-
$object = $this->getMock('\stdClass');
233+
$object = $this->getMockBuilder('\stdClass')->getMock();
237234

238235
$form = $this->getBuilder('name', '\stdClass', array(
239236
'invalid_message' => 'invalid_message_key',
@@ -267,7 +264,7 @@ function () { throw new TransformationFailedException(); }
267264

268265
public function testAddInvalidErrorEvenIfNoValidationGroups()
269266
{
270-
$object = $this->getMock('\stdClass');
267+
$object = $this->getMockBuilder('\stdClass')->getMock();
271268

272269
$form = $this->getBuilder('name', '\stdClass', array(
273270
'invalid_message' => 'invalid_message_key',
@@ -302,9 +299,9 @@ function () { throw new TransformationFailedException(); }
302299

303300
public function testDontValidateConstraintsIfNotSynchronized()
304301
{
305-
$object = $this->getMock('\stdClass');
306-
$constraint1 = $this->getMock('Symfony\Component\Validator\Constraint');
307-
$constraint2 = $this->getMock('Symfony\Component\Validator\Constraint');
302+
$object = $this->getMockBuilder('\stdClass')->getMock();
303+
$constraint1 = $this->getMockBuilder('Symfony\Component\Validator\Constraint')->getMock();
304+
$constraint2 = $this->getMockBuilder('Symfony\Component\Validator\Constraint')->getMock();
308305

309306
$options = array(
310307
'invalid_message' => 'invalid_message_key',
@@ -337,7 +334,7 @@ function () { throw new TransformationFailedException(); }
337334
// https://github.com/symfony/symfony/issues/4359
338335
public function testDontMarkInvalidIfAnyChildIsNotSynchronized()
339336
{
340-
$object = $this->getMock('\stdClass');
337+
$object = $this->getMockBuilder('\stdClass')->getMock();
341338

342339
$failingTransformer = new CallbackTransformer(
343340
function ($data) { return $data; },
@@ -367,7 +364,7 @@ function () { throw new TransformationFailedException(); }
367364

368365
public function testHandleCallbackValidationGroups()
369366
{
370-
$object = $this->getMock('\stdClass');
367+
$object = $this->getMockBuilder('\stdClass')->getMock();
371368
$options = array('validation_groups' => array($this, 'getValidationGroups'));
372369
$form = $this->getBuilder('name', '\stdClass', $options)
373370
->setData($object)
@@ -383,7 +380,7 @@ public function testHandleCallbackValidationGroups()
383380

384381
public function testDontExecuteFunctionNames()
385382
{
386-
$object = $this->getMock('\stdClass');
383+
$object = $this->getMockBuilder('\stdClass')->getMock();
387384
$options = array('validation_groups' => 'header');
388385
$form = $this->getBuilder('name', '\stdClass', $options)
389386
->setData($object)
@@ -398,7 +395,7 @@ public function testDontExecuteFunctionNames()
398395

399396
public function testHandleClosureValidationGroups()
400397
{
401-
$object = $this->getMock('\stdClass');
398+
$object = $this->getMockBuilder('\stdClass')->getMock();
402399
$options = array('validation_groups' => function (FormInterface $form) {
403400
return array('group1', 'group2');
404401
});
@@ -416,7 +413,7 @@ public function testHandleClosureValidationGroups()
416413

417414
public function testUseValidationGroupOfClickedButton()
418415
{
419-
$object = $this->getMock('\stdClass');
416+
$object = $this->getMockBuilder('\stdClass')->getMock();
420417

421418
$parent = $this->getBuilder('parent')
422419
->setCompound(true)
@@ -443,7 +440,7 @@ public function testUseValidationGroupOfClickedButton()
443440

444441
public function testDontUseValidationGroupOfUnclickedButton()
445442
{
446-
$object = $this->getMock('\stdClass');
443+
$object = $this->getMockBuilder('\stdClass')->getMock();
447444

448445
$parent = $this->getBuilder('parent')
449446
->setCompound(true)
@@ -470,7 +467,7 @@ public function testDontUseValidationGroupOfUnclickedButton()
470467

471468
public function testUseInheritedValidationGroup()
472469
{
473-
$object = $this->getMock('\stdClass');
470+
$object = $this->getMockBuilder('\stdClass')->getMock();
474471

475472
$parentOptions = array('validation_groups' => 'group');
476473
$parent = $this->getBuilder('parent', null, $parentOptions)
@@ -492,7 +489,7 @@ public function testUseInheritedValidationGroup()
492489

493490
public function testUseInheritedCallbackValidationGroup()
494491
{
495-
$object = $this->getMock('\stdClass');
492+
$object = $this->getMockBuilder('\stdClass')->getMock();
496493

497494
$parentOptions = array('validation_groups' => array($this, 'getValidationGroups'));
498495
$parent = $this->getBuilder('parent', null, $parentOptions)
@@ -514,7 +511,7 @@ public function testUseInheritedCallbackValidationGroup()
514511

515512
public function testUseInheritedClosureValidationGroup()
516513
{
517-
$object = $this->getMock('\stdClass');
514+
$object = $this->getMockBuilder('\stdClass')->getMock();
518515

519516
$parentOptions = array(
520517
'validation_groups' => function (FormInterface $form) {
@@ -540,7 +537,7 @@ public function testUseInheritedClosureValidationGroup()
540537

541538
public function testAppendPropertyPath()
542539
{
543-
$object = $this->getMock('\stdClass');
540+
$object = $this->getMockBuilder('\stdClass')->getMock();
544541
$form = $this->getBuilder('name', '\stdClass')
545542
->setData($object)
546543
->getForm();
@@ -618,9 +615,9 @@ public function getValidationGroups(FormInterface $form)
618615

619616
private function getMockExecutionContext()
620617
{
621-
$context = $this->getMock('Symfony\Component\Validator\Context\ExecutionContextInterface');
622-
$validator = $this->getMock('Symfony\Component\Validator\Validator\ValidatorInterface');
623-
$contextualValidator = $this->getMock('Symfony\Component\Validator\Validator\ContextualValidatorInterface');
618+
$context = $this->getMockBuilder('Symfony\Component\Validator\Context\ExecutionContextInterface')->getMock();
619+
$validator = $this->getMockBuilder('Symfony\Component\Validator\Validator\ValidatorInterface')->getMock();
620+
$contextualValidator = $this->getMockBuilder('Symfony\Component\Validator\Validator\ContextualValidatorInterface')->getMock();
624621

625622
$validator->expects($this->any())
626623
->method('inContext')
@@ -668,6 +665,6 @@ private function getSubmitButton($name = 'name', array $options = array())
668665
*/
669666
private function getDataMapper()
670667
{
671-
return $this->getMock('Symfony\Component\Form\DataMapperInterface');
668+
return $this->getMockBuilder('Symfony\Component\Form\DataMapperInterface')->getMock();
672669
}
673670
}

Tests/Extension/Validator/EventListener/ValidationListenerTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,10 @@ class ValidationListenerTest extends \PHPUnit_Framework_TestCase
5454

5555
protected function setUp()
5656
{
57-
$this->dispatcher = $this->getMock('Symfony\Component\EventDispatcher\EventDispatcherInterface');
58-
$this->factory = $this->getMock('Symfony\Component\Form\FormFactoryInterface');
59-
$this->validator = $this->getMock('Symfony\Component\Validator\Validator\ValidatorInterface');
60-
$this->violationMapper = $this->getMock('Symfony\Component\Form\Extension\Validator\ViolationMapper\ViolationMapperInterface');
57+
$this->dispatcher = $this->getMockBuilder('Symfony\Component\EventDispatcher\EventDispatcherInterface')->getMock();
58+
$this->factory = $this->getMockBuilder('Symfony\Component\Form\FormFactoryInterface')->getMock();
59+
$this->validator = $this->getMockBuilder('Symfony\Component\Validator\Validator\ValidatorInterface')->getMock();
60+
$this->violationMapper = $this->getMockBuilder('Symfony\Component\Form\Extension\Validator\ViolationMapper\ViolationMapperInterface')->getMock();
6161
$this->listener = new ValidationListener($this->validator, $this->violationMapper);
6262
$this->message = 'Message';
6363
$this->messageTemplate = 'Message template';
@@ -87,7 +87,7 @@ private function getForm($name = 'name', $propertyPath = null, $dataClass = null
8787

8888
private function getMockForm()
8989
{
90-
return $this->getMock('Symfony\Component\Form\Test\FormInterface');
90+
return $this->getMockBuilder('Symfony\Component\Form\Test\FormInterface')->getMock();
9191
}
9292

9393
// More specific mapping tests can be found in ViolationMapperTest
@@ -161,7 +161,7 @@ public function testValidateWithEmptyViolationList()
161161

162162
public function testValidatorInterface()
163163
{
164-
$validator = $this->getMock('Symfony\Component\Validator\Validator\ValidatorInterface');
164+
$validator = $this->getMockBuilder('Symfony\Component\Validator\Validator\ValidatorInterface')->getMock();
165165

166166
$listener = new ValidationListener($validator, $this->violationMapper);
167167
$this->assertAttributeSame($validator, 'validator', $listener);

Tests/Extension/Validator/Type/FormTypeValidatorExtensionTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public function testValidConstraint()
4747

4848
public function testValidatorInterface()
4949
{
50-
$validator = $this->getMock('Symfony\Component\Validator\Validator\ValidatorInterface');
50+
$validator = $this->getMockBuilder('Symfony\Component\Validator\Validator\ValidatorInterface')->getMock();
5151

5252
$formTypeValidatorExtension = new FormTypeValidatorExtension($validator);
5353
$this->assertAttributeSame($validator, 'validator', $formTypeValidatorExtension);

Tests/FormFactoryBuilderTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ protected function setUp()
2626
$this->registry = $factory->getProperty('registry');
2727
$this->registry->setAccessible(true);
2828

29-
$this->guesser = $this->getMock('Symfony\Component\Form\FormTypeGuesserInterface');
29+
$this->guesser = $this->getMockBuilder('Symfony\Component\Form\FormTypeGuesserInterface')->getMock();
3030
$this->type = new FooType();
3131
}
3232

0 commit comments

Comments
 (0)