Skip to content

Commit 0f7d8d8

Browse files
committed
fixed obsolete getMock() usage
1 parent a2ac356 commit 0f7d8d8

File tree

10 files changed

+43
-43
lines changed

10 files changed

+43
-43
lines changed

Tests/Extension/Core/EventListener/TrimListenerTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class TrimListenerTest extends \PHPUnit_Framework_TestCase
1919
public function testTrim()
2020
{
2121
$data = ' Foo! ';
22-
$form = $this->getMock('Symfony\Component\Form\Test\FormInterface');
22+
$form = $this->getMockBuilder('Symfony\Component\Form\Test\FormInterface')->getMock();
2323
$event = new FormEvent($form, $data);
2424

2525
$filter = new TrimListener();
@@ -31,7 +31,7 @@ public function testTrim()
3131
public function testTrimSkipNonStrings()
3232
{
3333
$data = 1234;
34-
$form = $this->getMock('Symfony\Component\Form\Test\FormInterface');
34+
$form = $this->getMockBuilder('Symfony\Component\Form\Test\FormInterface')->getMock();
3535
$event = new FormEvent($form, $data);
3636

3737
$filter = new TrimListener();

Tests/Extension/DependencyInjection/DependencyInjectionExtensionTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,17 @@ class DependencyInjectionExtensionTest extends \PHPUnit_Framework_TestCase
1818
{
1919
public function testGetTypeExtensions()
2020
{
21-
$container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface');
21+
$container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerInterface')->getMock();
2222

23-
$typeExtension1 = $this->getMock('Symfony\Component\Form\FormTypeExtensionInterface');
23+
$typeExtension1 = $this->getMockBuilder('Symfony\Component\Form\FormTypeExtensionInterface')->getMock();
2424
$typeExtension1->expects($this->any())
2525
->method('getExtendedType')
2626
->willReturn('test');
27-
$typeExtension2 = $this->getMock('Symfony\Component\Form\FormTypeExtensionInterface');
27+
$typeExtension2 = $this->getMockBuilder('Symfony\Component\Form\FormTypeExtensionInterface')->getMock();
2828
$typeExtension2->expects($this->any())
2929
->method('getExtendedType')
3030
->willReturn('test');
31-
$typeExtension3 = $this->getMock('Symfony\Component\Form\FormTypeExtensionInterface');
31+
$typeExtension3 = $this->getMockBuilder('Symfony\Component\Form\FormTypeExtensionInterface')->getMock();
3232
$typeExtension3->expects($this->any())
3333
->method('getExtendedType')
3434
->willReturn('other');
@@ -61,9 +61,9 @@ public function testGetTypeExtensions()
6161
*/
6262
public function testThrowExceptionForInvalidExtendedType()
6363
{
64-
$container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface');
64+
$container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerInterface')->getMock();
6565

66-
$typeExtension = $this->getMock('Symfony\Component\Form\FormTypeExtensionInterface');
66+
$typeExtension = $this->getMockBuilder('Symfony\Component\Form\FormTypeExtensionInterface')->getMock();
6767
$typeExtension->expects($this->any())
6868
->method('getExtendedType')
6969
->willReturn('unmatched');

Tests/Extension/Validator/Constraints/FormValidatorTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ public function testValidateConstraints()
109109

110110
public function testValidateIfParentWithCascadeValidation()
111111
{
112-
$object = $this->getMock('\stdClass');
112+
$object = $this->getMockBuilder('\stdClass')->getMock();
113113

114114
$parent = $this->getBuilder('parent', null, array('cascade_validation' => true))
115115
->setCompound(true)
@@ -131,7 +131,7 @@ public function testValidateIfParentWithCascadeValidation()
131131

132132
public function testValidateIfChildWithValidConstraint()
133133
{
134-
$object = $this->getMock('\stdClass');
134+
$object = $this->getMockBuilder('\stdClass')->getMock();
135135

136136
$parent = $this->getBuilder('parent')
137137
->setCompound(true)

Tests/Extension/Validator/EventListener/ValidationListenerTest.php

Lines changed: 7 additions & 7 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
@@ -183,7 +183,7 @@ public function testValidateWithEmptyViolationList()
183183
public function testValidatorInterfaceSinceSymfony25()
184184
{
185185
// Mock of ValidatorInterface since apiVersion 2.5
186-
$validator = $this->getMock('Symfony\Component\Validator\Validator\ValidatorInterface');
186+
$validator = $this->getMockBuilder('Symfony\Component\Validator\Validator\ValidatorInterface')->getMock();
187187

188188
$listener = new ValidationListener($validator, $this->violationMapper);
189189
$this->assertAttributeSame($validator, 'validator', $listener);
@@ -195,7 +195,7 @@ public function testValidatorInterfaceSinceSymfony25()
195195
public function testValidatorInterfaceUntilSymfony24()
196196
{
197197
// Mock of ValidatorInterface until apiVersion 2.4
198-
$validator = $this->getMock('Symfony\Component\Validator\ValidatorInterface');
198+
$validator = $this->getMockBuilder('Symfony\Component\Validator\ValidatorInterface')->getMock();
199199

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

Tests/Extension/Validator/Type/TypeTestCase.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ abstract class TypeTestCase extends BaseTypeTestCase
2020

2121
protected function setUp()
2222
{
23-
$this->validator = $this->getMock('Symfony\Component\Validator\Validator\ValidatorInterface');
23+
$this->validator = $this->getMockBuilder('Symfony\Component\Validator\Validator\ValidatorInterface')->getMock();
2424
$metadata = $this->getMockBuilder('Symfony\Component\Validator\Mapping\ClassMetadata')->disableOriginalConstructor()->getMock();
2525
$this->validator->expects($this->once())->method('getMetadataFor')->will($this->returnValue($metadata));
2626

Tests/Extension/Validator/ValidatorExtensionTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ public function test2Dot5ValidationApi()
5656
*/
5757
public function test2Dot4ValidationApi()
5858
{
59-
$factory = $this->getMock('Symfony\Component\Validator\Mapping\Factory\MetadataFactoryInterface');
60-
$validator = $this->getMock('Symfony\Component\Validator\ValidatorInterface');
59+
$factory = $this->getMockBuilder('Symfony\Component\Validator\Mapping\Factory\MetadataFactoryInterface')->getMock();
60+
$validator = $this->getMockBuilder('Symfony\Component\Validator\ValidatorInterface')->getMock();
6161
$metadata = $this->getMockBuilder('Symfony\Component\Validator\Mapping\ClassMetadata')
6262
->disableOriginalConstructor()
6363
->getMock();

Tests/Extension/Validator/ValidatorTypeGuesserTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ class ValidatorTypeGuesserTest extends \PHPUnit_Framework_TestCase
5151
protected function setUp()
5252
{
5353
$this->metadata = new ClassMetadata(self::TEST_CLASS);
54-
$this->metadataFactory = $this->getMock('Symfony\Component\Validator\Mapping\Factory\MetadataFactoryInterface');
54+
$this->metadataFactory = $this->getMockBuilder('Symfony\Component\Validator\Mapping\Factory\MetadataFactoryInterface')->getMock();
5555
$this->metadataFactory->expects($this->any())
5656
->method('getMetadataFor')
5757
->with(self::TEST_CLASS)

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 LegacyFooType();
3131
}
3232

Tests/FormRegistryTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,9 @@ class FormRegistryTest extends \PHPUnit_Framework_TestCase
6363

6464
protected function setUp()
6565
{
66-
$this->resolvedTypeFactory = $this->getMock('Symfony\Component\Form\ResolvedFormTypeFactory');
67-
$this->guesser1 = $this->getMock('Symfony\Component\Form\FormTypeGuesserInterface');
68-
$this->guesser2 = $this->getMock('Symfony\Component\Form\FormTypeGuesserInterface');
66+
$this->resolvedTypeFactory = $this->getMockBuilder('Symfony\Component\Form\ResolvedFormTypeFactory')->getMock();
67+
$this->guesser1 = $this->getMockBuilder('Symfony\Component\Form\FormTypeGuesserInterface')->getMock();
68+
$this->guesser2 = $this->getMockBuilder('Symfony\Component\Form\FormTypeGuesserInterface')->getMock();
6969
$this->extension1 = new TestExtension($this->guesser1);
7070
$this->extension2 = new TestExtension($this->guesser2);
7171
$this->registry = new FormRegistry(array(
@@ -305,7 +305,7 @@ public function testGetTypeGuesser()
305305
$this->assertEquals($expectedGuesser, $this->registry->getTypeGuesser());
306306

307307
$registry = new FormRegistry(
308-
array($this->getMock('Symfony\Component\Form\FormExtensionInterface')),
308+
array($this->getMockBuilder('Symfony\Component\Form\FormExtensionInterface')->getMock()),
309309
$this->resolvedTypeFactory
310310
);
311311

Tests/ResolvedFormTypeTest.php

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,9 @@ class ResolvedFormTypeTest extends \PHPUnit_Framework_TestCase
6969

7070
protected function setUp()
7171
{
72-
$this->dispatcher = $this->getMock('Symfony\Component\EventDispatcher\EventDispatcherInterface');
73-
$this->factory = $this->getMock('Symfony\Component\Form\FormFactoryInterface');
74-
$this->dataMapper = $this->getMock('Symfony\Component\Form\DataMapperInterface');
72+
$this->dispatcher = $this->getMockBuilder('Symfony\Component\EventDispatcher\EventDispatcherInterface')->getMock();
73+
$this->factory = $this->getMockBuilder('Symfony\Component\Form\FormFactoryInterface')->getMock();
74+
$this->dataMapper = $this->getMockBuilder('Symfony\Component\Form\DataMapperInterface')->getMock();
7575
$this->parentType = $this->getMockFormType();
7676
$this->type = $this->getMockFormType();
7777
$this->extension1 = $this->getMockFormTypeExtension();
@@ -127,7 +127,7 @@ public function testCreateBuilder()
127127
{
128128
$givenOptions = array('a' => 'a_custom', 'c' => 'c_custom');
129129
$resolvedOptions = array('a' => 'a_custom', 'b' => 'b_default', 'c' => 'c_custom', 'd' => 'd_default');
130-
$optionsResolver = $this->getMock('Symfony\Component\OptionsResolver\OptionsResolverInterface');
130+
$optionsResolver = $this->getMockBuilder('Symfony\Component\OptionsResolver\OptionsResolverInterface')->getMock();
131131

132132
$this->resolvedType = $this->getMockBuilder('Symfony\Component\Form\ResolvedFormType')
133133
->setConstructorArgs(array($this->type, array($this->extension1, $this->extension2), $this->parentResolvedType))
@@ -155,7 +155,7 @@ public function testCreateBuilderWithDataClassOption()
155155
{
156156
$givenOptions = array('data_class' => 'Foo');
157157
$resolvedOptions = array('data_class' => '\stdClass');
158-
$optionsResolver = $this->getMock('Symfony\Component\OptionsResolver\OptionsResolverInterface');
158+
$optionsResolver = $this->getMockBuilder('Symfony\Component\OptionsResolver\OptionsResolverInterface')->getMock();
159159

160160
$this->resolvedType = $this->getMockBuilder('Symfony\Component\Form\ResolvedFormType')
161161
->setConstructorArgs(array($this->type, array($this->extension1, $this->extension2), $this->parentResolvedType))
@@ -194,7 +194,7 @@ public function testBuildForm()
194194
};
195195

196196
$options = array('a' => 'Foo', 'b' => 'Bar');
197-
$builder = $this->getMock('Symfony\Component\Form\Test\FormBuilderInterface');
197+
$builder = $this->getMockBuilder('Symfony\Component\Form\Test\FormBuilderInterface')->getMock();
198198

199199
// First the form is built for the super type
200200
$this->parentType->expects($this->once())
@@ -224,7 +224,7 @@ public function testBuildForm()
224224

225225
public function testCreateView()
226226
{
227-
$form = $this->getMock('Symfony\Component\Form\Test\FormInterface');
227+
$form = $this->getMockBuilder('Symfony\Component\Form\Test\FormInterface')->getMock();
228228

229229
$view = $this->resolvedType->createView($form);
230230

@@ -234,8 +234,8 @@ public function testCreateView()
234234

235235
public function testCreateViewWithParent()
236236
{
237-
$form = $this->getMock('Symfony\Component\Form\Test\FormInterface');
238-
$parentView = $this->getMock('Symfony\Component\Form\FormView');
237+
$form = $this->getMockBuilder('Symfony\Component\Form\Test\FormInterface')->getMock();
238+
$parentView = $this->getMockBuilder('Symfony\Component\Form\FormView')->getMock();
239239

240240
$view = $this->resolvedType->createView($form, $parentView);
241241

@@ -246,8 +246,8 @@ public function testCreateViewWithParent()
246246
public function testBuildView()
247247
{
248248
$options = array('a' => '1', 'b' => '2');
249-
$form = $this->getMock('Symfony\Component\Form\Test\FormInterface');
250-
$view = $this->getMock('Symfony\Component\Form\FormView');
249+
$form = $this->getMockBuilder('Symfony\Component\Form\Test\FormInterface')->getMock();
250+
$view = $this->getMockBuilder('Symfony\Component\Form\FormView')->getMock();
251251

252252
$test = $this;
253253
$i = 0;
@@ -290,8 +290,8 @@ public function testBuildView()
290290
public function testFinishView()
291291
{
292292
$options = array('a' => '1', 'b' => '2');
293-
$form = $this->getMock('Symfony\Component\Form\Test\FormInterface');
294-
$view = $this->getMock('Symfony\Component\Form\FormView');
293+
$form = $this->getMockBuilder('Symfony\Component\Form\Test\FormInterface')->getMock();
294+
$view = $this->getMockBuilder('Symfony\Component\Form\FormView')->getMock();
295295

296296
$test = $this;
297297
$i = 0;
@@ -393,7 +393,7 @@ public function testGetBlockPrefix()
393393
public function testBlockPrefixDefaultsToNameIfSet()
394394
{
395395
// Type without getBlockPrefix() method
396-
$type = $this->getMock('Symfony\Component\Form\FormTypeInterface');
396+
$type = $this->getMockBuilder('Symfony\Component\Form\FormTypeInterface')->getMock();
397397

398398
$type->expects($this->once())
399399
->method('getName')
@@ -431,23 +431,23 @@ public function provideTypeClassBlockPrefixTuples()
431431
*/
432432
private function getMockFormType($typeClass = 'Symfony\Component\Form\AbstractType')
433433
{
434-
return $this->getMock($typeClass, array('getName', 'getBlockPrefix', 'configureOptions', 'finishView', 'buildView', 'buildForm'));
434+
return $this->getMockBuilder($typeClass)->setMethods(array('getName', 'getBlockPrefix', 'configureOptions', 'finishView', 'buildView', 'buildForm'))->getMock();
435435
}
436436

437437
/**
438438
* @return \PHPUnit_Framework_MockObject_MockObject
439439
*/
440440
private function getMockFormTypeExtension()
441441
{
442-
return $this->getMock('Symfony\Component\Form\AbstractTypeExtension', array('getExtendedType', 'configureOptions', 'finishView', 'buildView', 'buildForm'));
442+
return $this->getMockBuilder('Symfony\Component\Form\AbstractTypeExtension')->setMethods(array('getExtendedType', 'configureOptions', 'finishView', 'buildView', 'buildForm'))->getMock();
443443
}
444444

445445
/**
446446
* @return \PHPUnit_Framework_MockObject_MockObject
447447
*/
448448
private function getMockFormFactory()
449449
{
450-
return $this->getMock('Symfony\Component\Form\FormFactoryInterface');
450+
return $this->getMockBuilder('Symfony\Component\Form\FormFactoryInterface')->getMock();
451451
}
452452

453453
/**

0 commit comments

Comments
 (0)