Failed Conditions
Push — issue#785 ( 99b5db...cc4eec )
by Guilherme
04:11
created

testGetDynamicFormDataWithStateAcronym()   B

Complexity

Conditions 3
Paths 1

Size

Total Lines 41
Code Lines 30

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 30
nc 1
nop 0
dl 0
loc 41
rs 8.8571
c 0
b 0
f 0
1
<?php
2
/**
3
 * This file is part of the login-cidadao project or it's bundles.
4
 *
5
 * (c) Guilherme Donato <guilhermednt on github>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace LoginCidadao\DynamicFormBundle\Tests\Service;
12
13
use Doctrine\ORM\EntityManagerInterface;
14
use FOS\UserBundle\Model\UserManagerInterface;
15
use LoginCidadao\CoreBundle\Entity\City;
16
use LoginCidadao\CoreBundle\Entity\CityRepository;
17
use LoginCidadao\CoreBundle\Entity\Country;
18
use LoginCidadao\CoreBundle\Entity\CountryRepository;
19
use LoginCidadao\CoreBundle\Entity\IdCard;
20
use LoginCidadao\CoreBundle\Entity\Person;
21
use LoginCidadao\CoreBundle\Entity\PersonAddress;
22
use LoginCidadao\CoreBundle\Entity\State;
23
use LoginCidadao\CoreBundle\Entity\StateRepository;
24
use LoginCidadao\CoreBundle\Model\LocationSelectData;
25
use LoginCidadao\CoreBundle\Model\PersonInterface;
26
use LoginCidadao\DynamicFormBundle\Form\DynamicFormBuilder;
27
use LoginCidadao\DynamicFormBundle\Model\DynamicFormData;
28
use LoginCidadao\DynamicFormBundle\Service\DynamicFormService;
29
use LoginCidadao\OAuthBundle\Entity\Client;
30
use LoginCidadao\TaskStackBundle\Service\TaskStackManagerInterface;
31
use PHPUnit\Framework\MockObject\MockObject;
32
use PHPUnit\Framework\TestCase;
33
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
34
use Symfony\Component\Form\FormInterface;
35
use Symfony\Component\HttpFoundation\Request;
36
use Symfony\Component\HttpFoundation\Response;
37
use Symfony\Component\Routing\RouterInterface;
38
39
class DynamicFormServiceTest extends TestCase
40
{
41
    public function testGetDynamicFormDataWithStateId()
42
    {
43
        $target = $this->createMock('LoginCidadao\TaskStackBundle\Model\TaskTargetInterface');
44
        $task = $this->getMockBuilder('LoginCidadao\OpenIDBundle\Task\CompleteUserInfoTask')
45
            ->disableOriginalConstructor()->getMock();
46
        $task->expects($this->once())->method('getTarget')->willReturn($target);
47
48
        $redirectUrl = 'https://example.com';
49
        $stackManager = $this->getTaskStackManager();
50
        $stackManager->expects($this->once())->method('getTargetUrl')->willReturn($redirectUrl);
51
        $stackManager->expects($this->once())->method('getNextTask')->willReturn($task);
52
53
        $state = new State();
54
        $stateRepo = $this->getLocationRepo('State');
55
        $stateRepo->expects($this->once())->method('find')->with(1)->willReturn($state);
56
57
        $em = $this->getEntityManager();
58
        $em->expects($this->once())->method('getRepository')->willReturn($stateRepo);
59
60
        $formService = $this->getFormService($em, null, null, $stackManager, null);
61
62
        $person = $this->getPerson();
63
        $request = $this->getRequest();
64
        $request->expects($this->exactly(2))->method('get')->willReturnCallback(
0 ignored issues
show
Bug introduced by
The method expects() does not exist on Symfony\Component\HttpFoundation\Request. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

64
        $request->/** @scrutinizer ignore-call */ 
65
                  expects($this->exactly(2))->method('get')->willReturnCallback(

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
65
            function ($key) {
66
                switch ($key) {
67
                    case 'id_card_state_id':
68
                        return 1;
69
                    case 'redirect_url':
70
                        return 'https://example.com';
71
                    default:
72
                        return null;
73
                }
74
            }
75
        );
76
        $scope = 'scope1 scope2';
77
78
        $data = $formService->getDynamicFormData($person, $request, $scope);
79
        $this->assertEquals($person, $data->getPerson());
80
        $this->assertEquals($scope, $data->getScope());
81
        $this->assertEquals($redirectUrl, $data->getRedirectUrl());
82
    }
83
84
    public function testGetDynamicFormDataWithoutState()
85
    {
86
        $target = $this->createMock('LoginCidadao\TaskStackBundle\Model\TaskTargetInterface');
87
        $task = $this->getMockBuilder('LoginCidadao\OpenIDBundle\Task\CompleteUserInfoTask')
88
            ->disableOriginalConstructor()->getMock();
89
        $task->expects($this->once())->method('getTarget')->willReturn($target);
90
91
        $redirectUrl = 'https://example.com';
92
        $stackManager = $this->getTaskStackManager();
93
        $stackManager->expects($this->once())->method('getTargetUrl')->willReturn($redirectUrl);
94
        $stackManager->expects($this->once())->method('getNextTask')->willReturn($task);
95
96
        $formService = $this->getFormService(null, null, null, $stackManager, null);
97
98
        $person = $this->getPerson();
99
        $request = $this->getRequest();
100
        $scope = 'scope1 scope2';
101
102
        $data = $formService->getDynamicFormData($person, $request, $scope);
103
        $this->assertEquals($person, $data->getPerson());
104
        $this->assertEquals($scope, $data->getScope());
105
        $this->assertEquals($redirectUrl, $data->getRedirectUrl());
106
    }
107
108
    public function testGetDynamicFormDataWithoutRedirectUrlNorEvent()
109
    {
110
        $formService = $this->getFormService();
111
112
        $person = $this->getPerson();
113
        $request = $this->getRequest();
114
        $request->expects($this->atLeastOnce())->method('get')->willReturn(null);
115
        $scope = 'scope1 scope2';
116
117
        $data = $formService->getDynamicFormData($person, $request, $scope);
118
        $this->assertEquals($person, $data->getPerson());
119
        $this->assertEquals($scope, $data->getScope());
120
        $this->assertEquals('lc_dashboard', $data->getRedirectUrl());
121
    }
122
123
    public function testGetDynamicFormDataWithStateAcronym()
124
    {
125
        $target = $this->createMock('LoginCidadao\TaskStackBundle\Model\TaskTargetInterface');
126
        $task = $this->getMockBuilder('LoginCidadao\OpenIDBundle\Task\CompleteUserInfoTask')
127
            ->disableOriginalConstructor()->getMock();
128
        $task->expects($this->once())->method('getTarget')->willReturn($target);
129
130
        $redirectUrl = 'https://example.com';
131
        $stackManager = $this->getTaskStackManager();
132
        $stackManager->expects($this->once())->method('getTargetUrl')->willReturn($redirectUrl);
133
        $stackManager->expects($this->once())->method('getNextTask')->willReturn($task);
134
135
        $state = new State();
136
        $stateRepo = $this->getLocationRepo('State');
137
        $stateRepo->expects($this->once())->method('findOneBy')->willReturn($state);
138
139
        $em = $this->getEntityManager();
140
        $em->expects($this->once())->method('getRepository')->willReturn($stateRepo);
141
142
        $formService = $this->getFormService($em, null, null, $stackManager, null);
143
144
        $person = $this->getPerson();
145
        $request = $this->getRequest();
146
        $request->expects($this->atLeastOnce())->method('get')->willReturnCallback(
147
            function ($key) {
148
                switch ($key) {
149
                    case 'id_card_state':
150
                        return 'RS';
151
                    case 'redirect_url':
152
                        return 'https://example.com';
153
                    default:
154
                        return null;
155
                }
156
            }
157
        );
158
        $scope = 'scope1 scope2';
159
160
        $data = $formService->getDynamicFormData($person, $request, $scope);
161
        $this->assertEquals($person, $data->getPerson());
162
        $this->assertEquals($scope, $data->getScope());
163
        $this->assertEquals($redirectUrl, $data->getRedirectUrl());
164
    }
165
166
    public function testProcessInvalidForm()
167
    {
168
        $form = $this->getForm();
169
        $form->expects($this->once())->method('isValid')->willReturn(false);
170
        $request = $this->getRequest();
171
172
        $formService = $this->getFormService();
173
        $formService->processForm($form, $request);
174
    }
175
176
    public function testProcessFormWithPersonForm()
177
    {
178
        $data = new DynamicFormData();
179
        $data
180
            ->setPerson(new Person())
181
            ->setPlaceOfBirth(new LocationSelectData())
182
            ->setAddress(new PersonAddress())
183
            ->setIdCard(new IdCard())
184
            ->setRedirectUrl('https://example.com');
185
186
        $form = $this->getForm();
187
        $form->expects($this->once())->method('isValid')->willReturn(true);
188
        $form->expects($this->once())->method('getData')->willReturn($data);
189
        $form->expects($this->exactly(2))->method('has')->with('person')->willReturn(true);
190
        $form->expects($this->once())->method('get')->with('person')->willReturn($form);
191
        $request = $this->getRequest();
192
193
        $task = $this->getMockBuilder('LoginCidadao\OpenIDBundle\Task\CompleteUserInfoTask')
194
            ->disableOriginalConstructor()->getMock();
195
        $stackManager = $this->getTaskStackManager();
196
        $stackManager->expects($this->once())->method('getCurrentTask')->willReturn($task);
197
        $stackManager->expects($this->once())->method('processRequest')->willReturnCallback(
198
            function ($request, $response) {
199
                return $response;
200
            }
201
        );
202
203
        $formService = $this->getFormService(null, null, null, $stackManager);
204
        $formService->processForm($form, $request);
205
    }
206
207
    public function testProcessFormWithoutPersonForm()
208
    {
209
        $data = new DynamicFormData();
210
        $data
211
            ->setPerson(new Person())
212
            ->setAddress(new PersonAddress())
213
            ->setRedirectUrl('https://example.com');
214
215
        $form = $this->getForm();
216
        $form->expects($this->once())->method('isValid')->willReturn(true);
217
        $form->expects($this->once())->method('getData')->willReturn($data);
218
        $form->expects($this->exactly(2))->method('has')->with('person')->willReturn(false);
219
        $form->expects($this->never())->method('get')->with('person')->willReturn(null);
220
        $request = $this->getRequest();
221
222
        $task = $this->getMockBuilder('LoginCidadao\OpenIDBundle\Task\CompleteUserInfoTask')
223
            ->disableOriginalConstructor()->getMock();
224
        $stackManager = $this->getTaskStackManager();
225
        $stackManager->expects($this->once())->method('getCurrentTask')->willReturn($task);
226
        $stackManager->expects($this->once())->method('processRequest')->willReturnCallback(
227
            function ($request, $response) {
228
                return $response;
229
            }
230
        );
231
232
        $formService = $this->getFormService(null, null, null, $stackManager);
233
        $formService->processForm($form, $request);
234
    }
235
236
    public function testBuildForm()
237
    {
238
        $data = new DynamicFormData();
239
        $data->setPerson($this->getPerson());
240
241
        $form = $this->getForm();
242
        $form->expects($this->exactly(2))->method('add')->willReturn($form);
243
244
        $scopes = ['scope1', 'scope2'];
245
246
        $formService = $this->getFormService();
247
        $result = $formService->buildForm($form, $data, $scopes);
248
249
        $this->assertEquals($form, $result);
250
    }
251
252
    public function testGetClient()
253
    {
254
        $client = new Client();
255
        $client->setId(1)
256
            ->setRandomId('abc');
257
258
        $repo = $this->getMockBuilder('LoginCidadao\OAuthBundle\Entity\ClientRepository')
259
            ->disableOriginalConstructor()->getMock();
260
        $repo->expects($this->once())->method('findOneBy')->with(
261
            ['id' => $client->getId(), 'randomId' => $client->getRandomId()]
262
        )->willReturn($client);
263
264
        $em = $this->getEntityManager();
265
        $em->expects($this->once())->method('getRepository')->willReturn($repo);
266
267
        $clientId = $client->getPublicId();
268
        $formService = $this->getFormService($em);
269
        $result = $formService->getClient($clientId);
270
271
        $this->assertEquals($client, $result);
272
    }
273
274
    public function testGetClientBadId()
275
    {
276
        $this->expectException('\InvalidArgumentException');
277
        $this->expectExceptionMessage('Invalid client_id.');
278
279
        $clientId = 'invalid';
280
        $formService = $this->getFormService();
281
        $formService->getClient($clientId);
282
    }
283
284
    public function testGetClientNotFound()
285
    {
286
        $this->expectException('Symfony\Component\HttpKernel\Exception\NotFoundHttpException');
287
        $this->expectExceptionMessage('Client not found');
288
289
        $repo = $this->getMockBuilder('LoginCidadao\OAuthBundle\Entity\ClientRepository')
290
            ->disableOriginalConstructor()->getMock();
291
        $repo->expects($this->once())->method('findOneBy')->willReturn(null);
292
293
        $em = $this->getEntityManager();
294
        $em->expects($this->once())->method('getRepository')->willReturn($repo);
295
296
        $clientId = '1_abc';
297
        $formService = $this->getFormService($em);
298
        $formService->getClient($clientId);
299
    }
300
301
    public function testGetLocationDataFromRequestCity()
302
    {
303
        $country = new Country(1);
304
        $state = new State(1);
305
        $state->setCountry($country);
306
        $city = new City();
307
        $city->setId(1)
308
            ->setState($state);
309
310
        $repos = [
311
            'City' => $this->getLocationRepo('City'),
312
            'State' => $this->getLocationRepo('State'),
313
            'Country' => $this->getLocationRepo('Country'),
314
        ];
315
        $repos['City']->expects($this->once())->method('find')->with($city->getId())->willReturn($city);
316
317
        $em = $this->getEntityManager();
318
        $em->expects($this->exactly(3))->method('getRepository')->willReturnCallback(
319
            function ($entity) use (&$repos) {
320
                $parts = explode(':', $entity);
321
322
                return $repos[$parts[1]];
323
            }
324
        );
325
326
        $request = $this->getRequest();
327
        $request->expects($this->exactly(3))->method('get')->willReturn(1);
328
329
        $formService = $this->getFormService($em);
330
        $data = $formService->getLocationDataFromRequest($request);
331
332
        $this->assertEquals($country, $data->getPlaceOfBirth()->getCountry());
333
        $this->assertEquals($state, $data->getPlaceOfBirth()->getState());
334
        $this->assertEquals($city, $data->getPlaceOfBirth()->getCity());
335
    }
336
337
    public function testGetLocationDataFromRequestState()
338
    {
339
        $country = new Country(1);
340
        $state = new State(1);
341
        $state->setCountry($country);
342
343
        $repos = [
344
            'City' => $this->getLocationRepo('City'),
345
            'State' => $this->getLocationRepo('State'),
346
            'Country' => $this->getLocationRepo('Country'),
347
        ];
348
        $repos['State']->expects($this->once())->method('find')->with($state->getId())->willReturn($state);
349
350
        $em = $this->getEntityManager();
351
        $em->expects($this->exactly(3))->method('getRepository')->willReturnCallback(
352
            function ($entity) use (&$repos) {
353
                $parts = explode(':', $entity);
354
355
                return $repos[$parts[1]];
356
            }
357
        );
358
359
        $request = $this->getRequest();
360
        $request->expects($this->exactly(3))->method('get')->willReturn(1);
361
362
        $formService = $this->getFormService($em);
363
        $data = $formService->getLocationDataFromRequest($request);
364
365
        $this->assertEquals($country, $data->getPlaceOfBirth()->getCountry());
366
        $this->assertEquals($state, $data->getPlaceOfBirth()->getState());
367
        $this->assertNull($data->getPlaceOfBirth()->getCity());
368
    }
369
370
    public function testGetLocationDataFromRequestCountry()
371
    {
372
        $country = new Country(1);
373
374
        $repos = [
375
            'City' => $this->getLocationRepo('City'),
376
            'State' => $this->getLocationRepo('State'),
377
            'Country' => $this->getLocationRepo('Country'),
378
        ];
379
        $repos['Country']->expects($this->once())->method('find')->with($country->getId())->willReturn($country);
380
381
        $em = $this->getEntityManager();
382
        $em->expects($this->exactly(3))->method('getRepository')->willReturnCallback(
383
            function ($entity) use (&$repos) {
384
                $parts = explode(':', $entity);
385
386
                return $repos[$parts[1]];
387
            }
388
        );
389
390
        $request = $this->getRequest();
391
        $request->expects($this->exactly(3))->method('get')->willReturn(1);
392
393
        $formService = $this->getFormService($em);
394
        $data = $formService->getLocationDataFromRequest($request);
395
396
        $this->assertEquals($country, $data->getPlaceOfBirth()->getCountry());
397
        $this->assertNull($data->getPlaceOfBirth()->getState());
398
        $this->assertNull($data->getPlaceOfBirth()->getCity());
399
    }
400
401
    public function testGetLocationDataFromRequestNoIds()
402
    {
403
        $request = $this->getRequest();
404
        $request->expects($this->exactly(3))->method('get')->willReturn(null);
405
406
        $formService = $this->getFormService();
407
        $data = $formService->getLocationDataFromRequest($request);
408
409
        $this->assertNull($data->getPlaceOfBirth()->getCountry());
410
        $this->assertNull($data->getPlaceOfBirth()->getState());
411
        $this->assertNull($data->getPlaceOfBirth()->getCity());
412
    }
413
414
    public function testSkipCurrent()
415
    {
416
        $request = $this->getRequest();
417
        /** @var MockObject|Response $defaultResponse */
418
        $defaultResponse = $this->createMock('Symfony\Component\HttpFoundation\Response');
419
420
        $task = $this->getMockBuilder('LoginCidadao\OpenIDBundle\Task\CompleteUserInfoTask')
421
            ->disableOriginalConstructor()->getMock();
422
        $stackManager = $this->getTaskStackManager();
423
        $stackManager->expects($this->once())->method('getCurrentTask')->willReturn($task);
424
        $stackManager->expects($this->once())->method('setTaskSkipped')->with($task);
425
        $stackManager->expects($this->once())->method('processRequest')->with($request, $defaultResponse)->willReturn(
426
            $defaultResponse
427
        );
428
429
        $formService = $this->getFormService(null, null, null, $stackManager);
430
        $response = $formService->skipCurrent($request, $defaultResponse);
431
432
        $this->assertEquals($defaultResponse, $response);
433
    }
434
435
    public function testGetSkipUrl()
436
    {
437
        $data = new DynamicFormData();
438
        $data->setRedirectUrl('https://example.com');
439
440
        $task = $this->getMockBuilder('LoginCidadao\OpenIDBundle\Task\CompleteUserInfoTask')
441
            ->disableOriginalConstructor()->getMock();
442
        $stackManager = $this->getTaskStackManager();
443
        $stackManager->expects($this->once())->method('getCurrentTask')->willReturn($task);
444
445
        $formService = $this->getFormService(null, null, null, $stackManager);
446
        $url = $formService->getSkipUrl($data);
447
448
        $this->assertEquals('dynamic_form_skip', $url);
449
    }
450
451
    public function testGetSkipUrlNoTask()
452
    {
453
        $data = new DynamicFormData();
454
        $data->setRedirectUrl('https://example.com');
455
456
        $stackManager = $this->getTaskStackManager();
457
        $stackManager->expects($this->once())->method('getCurrentTask')->willReturn(null);
458
459
        $formService = $this->getFormService(null, null, null, $stackManager);
460
        $url = $formService->getSkipUrl($data);
461
462
        $this->assertEquals($data->getRedirectUrl(), $url);
463
    }
464
465
    /**
466
     * @param null $em
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $em is correct as it would always require null to be passed?
Loading history...
467
     * @param null $dispatcher
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $dispatcher is correct as it would always require null to be passed?
Loading history...
468
     * @param null $userManager
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $userManager is correct as it would always require null to be passed?
Loading history...
469
     * @param null $taskStackManager
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $taskStackManager is correct as it would always require null to be passed?
Loading history...
470
     * @param null $dynamicFormBuilder
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $dynamicFormBuilder is correct as it would always require null to be passed?
Loading history...
471
     * @param null $router
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $router is correct as it would always require null to be passed?
Loading history...
472
     * @return DynamicFormService
473
     */
474
    private function getFormService(
475
        $em = null,
476
        $dispatcher = null,
477
        $userManager = null,
478
        $taskStackManager = null,
479
        $dynamicFormBuilder = null,
480
        $router = null
481
    ): DynamicFormService {
482
        if (!$em) {
483
            $em = $this->getEntityManager();
484
        }
485
        if (!$dispatcher) {
486
            /** @var MockObject|EventDispatcherInterface $dispatcher */
487
            $dispatcher = $this->createMock('Symfony\Component\EventDispatcher\EventDispatcherInterface');
488
        }
489
        if (!$userManager) {
490
            /** @var MockObject|UserManagerInterface $userManager */
491
            $userManager = $this->createMock('FOS\UserBundle\Model\UserManagerInterface');
492
        }
493
        if (!$taskStackManager) {
494
            $taskStackManager = $this->getTaskStackManager();
495
        }
496
        if (!$dynamicFormBuilder) {
497
            /** @var MockObject|DynamicFormBuilder $dynamicFormBuilder */
498
            $dynamicFormBuilder = $this->getMockBuilder('LoginCidadao\DynamicFormBundle\Form\DynamicFormBuilder')
499
                ->disableOriginalConstructor()
500
                ->getMock();
501
        }
502
        if (!$router) {
503
            /** @var MockObject|RouterInterface $router */
504
            $router = $this->createMock('Symfony\Component\Routing\RouterInterface');
505
            $router->expects($this->any())->method('generate')->willReturnCallback(
0 ignored issues
show
Bug introduced by
The method expects() does not exist on Symfony\Component\Routing\RouterInterface. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

505
            $router->/** @scrutinizer ignore-call */ 
506
                     expects($this->any())->method('generate')->willReturnCallback(

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
506
                function ($name) {
507
                    return $name;
508
                }
509
            );
510
        }
511
512
        $formService = new DynamicFormService(
513
            $em,
514
            $dispatcher,
515
            $userManager,
516
            $taskStackManager,
517
            $dynamicFormBuilder,
518
            $router
519
        );
520
521
        return $formService;
522
    }
523
524
    /**
525
     * @return \PHPUnit\Framework\MockObject\MockObject|TaskStackManagerInterface
526
     */
527
    private function getTaskStackManager()
528
    {
529
        return $this->createMock('LoginCidadao\TaskStackBundle\Service\TaskStackManagerInterface');
530
    }
531
532
    /**
533
     * @return \PHPUnit\Framework\MockObject\MockObject|PersonInterface
534
     */
535
    private function getPerson()
536
    {
537
        return $this->createMock('LoginCidadao\CoreBundle\Model\PersonInterface');
538
    }
539
540
    /**
541
     * @return \PHPUnit\Framework\MockObject\MockObject|EntityManagerInterface
542
     */
543
    private function getEntityManager()
544
    {
545
        return $this->createMock('Doctrine\ORM\EntityManagerInterface');
546
    }
547
548
    /**
549
     * @param $class
550
     * @return null|\PHPUnit\Framework\MockObject\MockObject|CountryRepository|StateRepository|CityRepository
551
     */
552
    private function getLocationRepo($class)
553
    {
554
        switch ($class) {
555
            case 'Country':
556
                return $this->getMockBuilder('LoginCidadao\CoreBundle\Entity\CountryRepository')
557
                    ->disableOriginalConstructor()->getMock();
558
            case 'State':
559
                return $this->getMockBuilder('LoginCidadao\CoreBundle\Entity\StateRepository')
560
                    ->disableOriginalConstructor()->getMock();
561
            case 'City':
562
                return $this->getMockBuilder('LoginCidadao\CoreBundle\Entity\CityRepository')
563
                    ->disableOriginalConstructor()->getMock();
564
            default:
565
                return null;
566
        }
567
    }
568
569
    /**
570
     * @return MockObject|Request
571
     */
572
    private function getRequest()
573
    {
574
        /** @var MockObject|Request $request */
575
        $request = $this->getMockBuilder(Request::class)
576
            ->disableOriginalConstructor()
577
            ->getMock();
578
579
        return $request;
580
    }
581
582
    /**
583
     * @return MockObject|FormInterface
584
     */
585
    private function getForm()
586
    {
587
        return $this->createMock(FormInterface::class);
588
    }
589
}
590