Skip to content

Commit 0d8b0fc

Browse files
committed
fixed obsolete getMock() usage
1 parent b65a386 commit 0d8b0fc

File tree

4 files changed

+43
-51
lines changed

4 files changed

+43
-51
lines changed

Tests/Controller/ControllerTest.php

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,12 @@ public function testForward()
3333
$requestStack = new RequestStack();
3434
$requestStack->push($request);
3535

36-
$kernel = $this->getMock('Symfony\Component\HttpKernel\HttpKernelInterface');
36+
$kernel = $this->getMockBuilder('Symfony\Component\HttpKernel\HttpKernelInterface')->getMock();
3737
$kernel->expects($this->once())->method('handle')->will($this->returnCallback(function (Request $request) {
3838
return new Response($request->getRequestFormat().'--'.$request->getLocale());
3939
}));
4040

41-
$container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface');
41+
$container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerInterface')->getMock();
4242
$container->expects($this->at(0))->method('get')->will($this->returnValue($requestStack));
4343
$container->expects($this->at(1))->method('get')->will($this->returnValue($kernel));
4444

@@ -84,7 +84,7 @@ public function testGetUserWithEmptyTokenStorage()
8484
*/
8585
public function testGetUserWithEmptyContainer()
8686
{
87-
$container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface');
87+
$container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerInterface')->getMock();
8888
$container
8989
->expects($this->once())
9090
->method('has')
@@ -104,13 +104,13 @@ public function testGetUserWithEmptyContainer()
104104
*/
105105
private function getContainerWithTokenStorage($token = null)
106106
{
107-
$tokenStorage = $this->getMock('Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorage');
107+
$tokenStorage = $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorage')->getMock();
108108
$tokenStorage
109109
->expects($this->once())
110110
->method('getToken')
111111
->will($this->returnValue($token));
112112

113-
$container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface');
113+
$container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerInterface')->getMock();
114114
$container
115115
->expects($this->once())
116116
->method('has')
@@ -128,10 +128,10 @@ private function getContainerWithTokenStorage($token = null)
128128

129129
public function testIsGranted()
130130
{
131-
$authorizationChecker = $this->getMock('Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface');
131+
$authorizationChecker = $this->getMockBuilder('Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface')->getMock();
132132
$authorizationChecker->expects($this->once())->method('isGranted')->willReturn(true);
133133

134-
$container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface');
134+
$container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerInterface')->getMock();
135135
$container->expects($this->at(0))->method('has')->will($this->returnValue(true));
136136
$container->expects($this->at(1))->method('get')->will($this->returnValue($authorizationChecker));
137137

@@ -146,10 +146,10 @@ public function testIsGranted()
146146
*/
147147
public function testdenyAccessUnlessGranted()
148148
{
149-
$authorizationChecker = $this->getMock('Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface');
149+
$authorizationChecker = $this->getMockBuilder('Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface')->getMock();
150150
$authorizationChecker->expects($this->once())->method('isGranted')->willReturn(false);
151151

152-
$container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface');
152+
$container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerInterface')->getMock();
153153
$container->expects($this->at(0))->method('has')->will($this->returnValue(true));
154154
$container->expects($this->at(1))->method('get')->will($this->returnValue($authorizationChecker));
155155

@@ -164,7 +164,7 @@ public function testRenderViewTwig()
164164
$twig = $this->getMockBuilder('\Twig_Environment')->disableOriginalConstructor()->getMock();
165165
$twig->expects($this->once())->method('render')->willReturn('bar');
166166

167-
$container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface');
167+
$container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerInterface')->getMock();
168168
$container->expects($this->at(0))->method('has')->will($this->returnValue(false));
169169
$container->expects($this->at(1))->method('has')->will($this->returnValue(true));
170170
$container->expects($this->at(2))->method('get')->will($this->returnValue($twig));
@@ -180,7 +180,7 @@ public function testRenderTwig()
180180
$twig = $this->getMockBuilder('\Twig_Environment')->disableOriginalConstructor()->getMock();
181181
$twig->expects($this->once())->method('render')->willReturn('bar');
182182

183-
$container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface');
183+
$container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerInterface')->getMock();
184184
$container->expects($this->at(0))->method('has')->will($this->returnValue(false));
185185
$container->expects($this->at(1))->method('has')->will($this->returnValue(true));
186186
$container->expects($this->at(2))->method('get')->will($this->returnValue($twig));
@@ -195,7 +195,7 @@ public function testStreamTwig()
195195
{
196196
$twig = $this->getMockBuilder('\Twig_Environment')->disableOriginalConstructor()->getMock();
197197

198-
$container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface');
198+
$container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerInterface')->getMock();
199199
$container->expects($this->at(0))->method('has')->will($this->returnValue(false));
200200
$container->expects($this->at(1))->method('has')->will($this->returnValue(true));
201201
$container->expects($this->at(2))->method('get')->will($this->returnValue($twig));
@@ -208,10 +208,10 @@ public function testStreamTwig()
208208

209209
public function testRedirectToRoute()
210210
{
211-
$router = $this->getMock('Symfony\Component\Routing\RouterInterface');
211+
$router = $this->getMockBuilder('Symfony\Component\Routing\RouterInterface')->getMock();
212212
$router->expects($this->once())->method('generate')->willReturn('/foo');
213213

214-
$container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface');
214+
$container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerInterface')->getMock();
215215
$container->expects($this->at(0))->method('get')->will($this->returnValue($router));
216216

217217
$controller = new TestController();
@@ -226,10 +226,10 @@ public function testRedirectToRoute()
226226
public function testAddFlash()
227227
{
228228
$flashBag = new FlashBag();
229-
$session = $this->getMock('Symfony\Component\HttpFoundation\Session\Session');
229+
$session = $this->getMockBuilder('Symfony\Component\HttpFoundation\Session\Session')->getMock();
230230
$session->expects($this->once())->method('getFlashBag')->willReturn($flashBag);
231231

232-
$container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface');
232+
$container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerInterface')->getMock();
233233
$container->expects($this->at(0))->method('has')->will($this->returnValue(true));
234234
$container->expects($this->at(1))->method('get')->will($this->returnValue($session));
235235

@@ -249,10 +249,10 @@ public function testCreateAccessDeniedException()
249249

250250
public function testIsCsrfTokenValid()
251251
{
252-
$tokenManager = $this->getMock('Symfony\Component\Security\Csrf\CsrfTokenManagerInterface');
252+
$tokenManager = $this->getMockBuilder('Symfony\Component\Security\Csrf\CsrfTokenManagerInterface')->getMock();
253253
$tokenManager->expects($this->once())->method('isTokenValid')->willReturn(true);
254254

255-
$container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface');
255+
$container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerInterface')->getMock();
256256
$container->expects($this->at(0))->method('has')->will($this->returnValue(true));
257257
$container->expects($this->at(1))->method('get')->will($this->returnValue($tokenManager));
258258

@@ -264,10 +264,10 @@ public function testIsCsrfTokenValid()
264264

265265
public function testGenerateUrl()
266266
{
267-
$router = $this->getMock('Symfony\Component\Routing\RouterInterface');
267+
$router = $this->getMockBuilder('Symfony\Component\Routing\RouterInterface')->getMock();
268268
$router->expects($this->once())->method('generate')->willReturn('/foo');
269269

270-
$container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface');
270+
$container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerInterface')->getMock();
271271
$container->expects($this->at(0))->method('get')->will($this->returnValue($router));
272272

273273
$controller = new Controller();
@@ -288,10 +288,10 @@ public function testRedirect()
288288

289289
public function testRenderViewTemplating()
290290
{
291-
$templating = $this->getMock('Symfony\Bundle\FrameworkBundle\Templating\EngineInterface');
291+
$templating = $this->getMockBuilder('Symfony\Bundle\FrameworkBundle\Templating\EngineInterface')->getMock();
292292
$templating->expects($this->once())->method('render')->willReturn('bar');
293293

294-
$container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface');
294+
$container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerInterface')->getMock();
295295
$container->expects($this->at(0))->method('has')->willReturn(true);
296296
$container->expects($this->at(1))->method('get')->will($this->returnValue($templating));
297297

@@ -303,10 +303,10 @@ public function testRenderViewTemplating()
303303

304304
public function testRenderTemplating()
305305
{
306-
$templating = $this->getMock('Symfony\Bundle\FrameworkBundle\Templating\EngineInterface');
306+
$templating = $this->getMockBuilder('Symfony\Bundle\FrameworkBundle\Templating\EngineInterface')->getMock();
307307
$templating->expects($this->once())->method('renderResponse')->willReturn(new Response('bar'));
308308

309-
$container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface');
309+
$container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerInterface')->getMock();
310310
$container->expects($this->at(0))->method('has')->willReturn(true);
311311
$container->expects($this->at(1))->method('get')->will($this->returnValue($templating));
312312

@@ -318,9 +318,9 @@ public function testRenderTemplating()
318318

319319
public function testStreamTemplating()
320320
{
321-
$templating = $this->getMock('Symfony\Component\Routing\RouterInterface');
321+
$templating = $this->getMockBuilder('Symfony\Component\Routing\RouterInterface')->getMock();
322322

323-
$container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface');
323+
$container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerInterface')->getMock();
324324
$container->expects($this->at(0))->method('has')->willReturn(true);
325325
$container->expects($this->at(1))->method('get')->will($this->returnValue($templating));
326326

@@ -339,12 +339,12 @@ public function testCreateNotFoundException()
339339

340340
public function testCreateForm()
341341
{
342-
$form = $this->getMock('Symfony\Component\Form\FormInterface');
342+
$form = $this->getMockBuilder('Symfony\Component\Form\FormInterface')->getMock();
343343

344-
$formFactory = $this->getMock('Symfony\Component\Form\FormFactoryInterface');
344+
$formFactory = $this->getMockBuilder('Symfony\Component\Form\FormFactoryInterface')->getMock();
345345
$formFactory->expects($this->once())->method('create')->willReturn($form);
346346

347-
$container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface');
347+
$container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerInterface')->getMock();
348348
$container->expects($this->at(0))->method('get')->will($this->returnValue($formFactory));
349349

350350
$controller = new Controller();
@@ -355,12 +355,12 @@ public function testCreateForm()
355355

356356
public function testCreateFormBuilder()
357357
{
358-
$formBuilder = $this->getMock('Symfony\Component\Form\FormBuilderInterface');
358+
$formBuilder = $this->getMockBuilder('Symfony\Component\Form\FormBuilderInterface')->getMock();
359359

360-
$formFactory = $this->getMock('Symfony\Component\Form\FormFactoryInterface');
360+
$formFactory = $this->getMockBuilder('Symfony\Component\Form\FormFactoryInterface')->getMock();
361361
$formFactory->expects($this->once())->method('createBuilder')->willReturn($formBuilder);
362362

363-
$container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface');
363+
$container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerInterface')->getMock();
364364
$container->expects($this->at(0))->method('get')->will($this->returnValue($formFactory));
365365

366366
$controller = new Controller();
@@ -371,9 +371,9 @@ public function testCreateFormBuilder()
371371

372372
public function testGetDoctrine()
373373
{
374-
$doctrine = $this->getMock('Doctrine\Common\Persistence\ManagerRegistry');
374+
$doctrine = $this->getMockBuilder('Doctrine\Common\Persistence\ManagerRegistry')->getMock();
375375

376-
$container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface');
376+
$container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerInterface')->getMock();
377377
$container->expects($this->at(0))->method('has')->will($this->returnValue(true));
378378
$container->expects($this->at(1))->method('get')->will($this->returnValue($doctrine));
379379

Tests/DependencyInjection/Compiler/ConfigCachePassTest.php

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,8 @@ public function testThatCheckersAreProcessedInPriorityOrder()
2424
'checker_3' => array(),
2525
);
2626

27-
$definition = $this->getMock('Symfony\Component\DependencyInjection\Definition');
28-
$container = $this->getMock(
29-
'Symfony\Component\DependencyInjection\ContainerBuilder',
30-
array('findTaggedServiceIds', 'getDefinition', 'hasDefinition')
31-
);
27+
$definition = $this->getMockBuilder('Symfony\Component\DependencyInjection\Definition')->getMock();
28+
$container = $this->getMock('Symfony\Component\DependencyInjection\ContainerBuilder')->setMethods(array('findTaggedServiceIds', 'getDefinition', 'hasDefinition'))->getMock();
3229

3330
$container->expects($this->atLeastOnce())
3431
->method('findTaggedServiceIds')
@@ -52,11 +49,8 @@ public function testThatCheckersAreProcessedInPriorityOrder()
5249

5350
public function testThatCheckersCanBeMissing()
5451
{
55-
$definition = $this->getMock('Symfony\Component\DependencyInjection\Definition');
56-
$container = $this->getMock(
57-
'Symfony\Component\DependencyInjection\ContainerBuilder',
58-
array('findTaggedServiceIds')
59-
);
52+
$definition = $this->getMockBuilder('Symfony\Component\DependencyInjection\Definition')->getMock();
53+
$container = $this->getMock('Symfony\Component\DependencyInjection\ContainerBuilder')->setMethods(array('findTaggedServiceIds'))->getMock();
6054

6155
$container->expects($this->atLeastOnce())
6256
->method('findTaggedServiceIds')

Tests/DependencyInjection/Compiler/PropertyInfoPassTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public function testServicesAreOrderedAccordingToPriority()
3030
new Reference('n3'),
3131
);
3232

33-
$container = $this->getMock('Symfony\Component\DependencyInjection\ContainerBuilder', array('findTaggedServiceIds'));
33+
$container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerBuilder')->setMethods(array('findTaggedServiceIds'))->getMock();
3434

3535
$container->expects($this->any())
3636
->method('findTaggedServiceIds')
@@ -51,7 +51,7 @@ public function testServicesAreOrderedAccordingToPriority()
5151

5252
public function testReturningEmptyArrayWhenNoService()
5353
{
54-
$container = $this->getMock('Symfony\Component\DependencyInjection\ContainerBuilder', array('findTaggedServiceIds'));
54+
$container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerBuilder')->setMethods(array('findTaggedServiceIds'))->getMock();
5555

5656
$container->expects($this->any())
5757
->method('findTaggedServiceIds')

Tests/DependencyInjection/Compiler/UnusedTagsPassTest.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,17 @@ public function testProcess()
1919
{
2020
$pass = new UnusedTagsPass();
2121

22-
$formatter = $this->getMock('Symfony\Component\DependencyInjection\Compiler\LoggingFormatter');
22+
$formatter = $this->getMockBuilder('Symfony\Component\DependencyInjection\Compiler\LoggingFormatter')->getMock();
2323
$formatter
2424
->expects($this->at(0))
2525
->method('format')
2626
->with($pass, 'Tag "kenrel.event_subscriber" was defined on service(s) "foo", "bar", but was never used. Did you mean "kernel.event_subscriber"?')
2727
;
2828

29-
$compiler = $this->getMock('Symfony\Component\DependencyInjection\Compiler\Compiler');
29+
$compiler = $this->getMockBuilder('Symfony\Component\DependencyInjection\Compiler\Compiler')->getMock();
3030
$compiler->expects($this->once())->method('getLoggingFormatter')->will($this->returnValue($formatter));
3131

32-
$container = $this->getMock('Symfony\Component\DependencyInjection\ContainerBuilder',
33-
array('findTaggedServiceIds', 'getCompiler', 'findUnusedTags', 'findTags')
34-
);
32+
$container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerBuilder')->setMethods(array('findTaggedServiceIds', 'getCompiler', 'findUnusedTags', 'findTags'))->getMock();
3533
$container->expects($this->once())->method('getCompiler')->will($this->returnValue($compiler));
3634
$container->expects($this->once())
3735
->method('findTags')

0 commit comments

Comments
 (0)