Completed
Branch proxy (a8ed88)
by leo
08:29
created

testCasValidateWithValidTicketButServiceMismatch()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 43
Code Lines 38

Duplication

Lines 7
Ratio 16.28 %

Importance

Changes 0
Metric Value
cc 1
eloc 38
nc 1
nop 0
dl 7
loc 43
rs 8.8571
c 0
b 0
f 0
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: leo108
5
 * Date: 2016/10/12
6
 * Time: 15:56
7
 */
8
9
namespace Leo108\CAS\Http\Controllers;
10
11
use Illuminate\Http\Request;
12
use Illuminate\Http\Response;
13
use Leo108\CAS\Contracts\TicketLocker;
14
use Leo108\CAS\Exceptions\CAS\CasException;
15
use Leo108\CAS\Models\Ticket;
16
use Leo108\CAS\Repositories\PGTicketRepository;
17
use Leo108\CAS\Repositories\TicketRepository;
18
use Leo108\CAS\Responses\JsonAuthenticationFailureResponse;
19
use Leo108\CAS\Responses\JsonAuthenticationSuccessResponse;
20
use Leo108\CAS\Responses\XmlAuthenticationFailureResponse;
21
use Leo108\CAS\Responses\XmlAuthenticationSuccessResponse;
22
use Leo108\CAS\Services\PGTCaller;
23
use Leo108\CAS\Services\TicketGenerator;
24
use SerializableModel;
25
use SimpleXMLElement;
26
use TestCase;
27
use Mockery;
28
use User;
29
30
function method_exists($obj, $method)
31
{
32
    return ValidateControllerTest::$functions->method_exists($obj, $method);
0 ignored issues
show
Bug introduced by
The method method_exists() does not seem to exist on object<Mockery\MockInterface>.

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...
33
}
34
35
class ValidateControllerTest extends TestCase
36
{
37
    public static $functions;
38
39
    public function setUp()
40
    {
41
        parent::setUp();
42
        self::$functions = Mockery::mock();
43
        app()->instance(TicketLocker::class, Mockery::mock(TicketLocker::class));
44
    }
45
46
    public function testV1ValidateActionWithInvalidRequest()
47
    {
48
        $request = Mockery::mock(Request::class)
49
            ->shouldReceive('get')
50
            ->withArgs(['ticket', ''])
51
            ->andReturnNull()
52
            ->shouldReceive('get')
53
            ->withArgs(['service', ''])
54
            ->andReturnNull()
55
            ->getMock();
56
        $resp    = app()->make(ValidateController::class)->v1ValidateAction($request);
57
        $this->assertInstanceOf(Response::class, $resp);
58
        $this->assertEquals('no', $resp->getOriginalContent());
59
    }
60
61 View Code Duplication
    public function testV1ValidateActionWithLockFailed()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
62
    {
63
        $request    = $this->getValidRequest();
64
        $controller = Mockery::mock(ValidateController::class)
65
            ->makePartial()
66
            ->shouldAllowMockingProtectedMethods()
67
            ->shouldReceive('lockTicket')
68
            ->andReturn(false)
69
            ->getMock();
70
        $resp       = $controller->v1ValidateAction($request);
71
        $this->assertInstanceOf(Response::class, $resp);
72
        $this->assertEquals('no', $resp->getOriginalContent());
73
    }
74
75
    public function testV1ValidateActionWithInvalidTicket()
76
    {
77
        $request          = $this->getValidRequest();
78
        $ticketRepository = Mockery::mock(TicketRepository::class)
79
            ->shouldReceive('getByTicket')
80
            ->andReturnNull()
81
            ->getMock();
82
        app()->instance(TicketRepository::class, $ticketRepository);
83
        $controller = $this->initController()
84
            ->makePartial()
85
            ->shouldAllowMockingProtectedMethods()
86
            ->shouldReceive('lockTicket')
87
            ->andReturn(true)
88
            ->shouldReceive('unlockTicket')
89
            ->getMock();
90
        $resp       = $controller->v1ValidateAction($request);
91
        $this->assertInstanceOf(Response::class, $resp);
92
        $this->assertEquals('no', $resp->getOriginalContent());
93
    }
94
95
    public function testV1ValidateActionWithValidTicketButServiceMismatch()
96
    {
97
        $request             = $this->getValidRequest();
98
        $ticket              = Mockery::mock();
99
        $ticket->service_url = 'http//google.com';
0 ignored issues
show
Bug introduced by
Accessing service_url on the interface Mockery\MockInterface suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
100
        $ticketRepository    = Mockery::mock(TicketRepository::class)
101
            ->shouldReceive('getByTicket')
102
            ->andReturn($ticket)
103
            ->getMock();
104
        app()->instance(TicketRepository::class, $ticketRepository);
105
        $controller = $this->initController()
106
            ->makePartial()
107
            ->shouldAllowMockingProtectedMethods()
108
            ->shouldReceive('lockTicket')
109
            ->andReturn(true)
110
            ->shouldReceive('unlockTicket')
111
            ->getMock();
112
        $resp       = $controller->v1ValidateAction($request);
113
        $this->assertInstanceOf(Response::class, $resp);
114
        $this->assertEquals('no', $resp->getOriginalContent());
115
    }
116
117
    public function testV1ValidateActionWithValidTicketAndService()
118
    {
119
        $request          = $this->getValidRequest();
120
        $ticket           = Mockery::mock(Ticket::class)
121
            ->shouldReceive('getAttribute')
122
            ->withArgs(['service_url'])
123
            ->andReturn('http://leo108.com')
124
            ->getMock();
125
        $ticketRepository = Mockery::mock(TicketRepository::class)
0 ignored issues
show
Bug introduced by
The method shouldReceive() does not seem to exist on object<Mockery\Expectation>.

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...
126
            ->shouldReceive('getByTicket')
127
            ->andReturn($ticket)
128
            ->shouldReceive('invalidTicket')
129
            ->getMock();
130
        app()->instance(TicketRepository::class, $ticketRepository);
131
        $controller = $this->initController()
132
            ->makePartial()
133
            ->shouldAllowMockingProtectedMethods()
134
            ->shouldReceive('lockTicket')
135
            ->andReturn(true)
136
            ->shouldReceive('unlockTicket')
137
            ->getMock();
138
        $resp       = $controller->v1ValidateAction($request);
139
        $this->assertInstanceOf(Response::class, $resp);
140
        $this->assertEquals('yes', $resp->getOriginalContent());
141
    }
142
143 View Code Duplication
    public function testV2ServiceValidateAction()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
144
    {
145
        $controller = Mockery::mock(ValidateController::class)
146
            ->makePartial()
147
            ->shouldAllowMockingProtectedMethods()
148
            ->shouldReceive('casValidate')
149
            ->andReturnUsing(
150
                function ($request, $returnAttr, $allowProxy) {
151
                    $this->assertFalse($returnAttr);
152
                    $this->assertFalse($allowProxy);
153
154
                    return 'casValidate called';
155
                }
156
            )
157
            ->once()
158
            ->getMock();
159
        $request    = Mockery::mock(Request::class);
160
        $this->assertEquals('casValidate called', $controller->v2ServiceValidateAction($request));
161
    }
162
163 View Code Duplication
    public function testV2ProxyValidateAction()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
164
    {
165
        $controller = Mockery::mock(ValidateController::class)
166
            ->makePartial()
167
            ->shouldAllowMockingProtectedMethods()
168
            ->shouldReceive('casValidate')
169
            ->andReturnUsing(
170
                function ($request, $returnAttr, $allowProxy) {
171
                    $this->assertFalse($returnAttr);
172
                    $this->assertTrue($allowProxy);
173
174
                    return 'casValidate called';
175
                }
176
            )
177
            ->once()
178
            ->getMock();
179
        $request    = Mockery::mock(Request::class);
180
        $this->assertEquals('casValidate called', $controller->v2ProxyValidateAction($request));
181
    }
182
183 View Code Duplication
    public function testV3ServiceValidateAction()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
184
    {
185
        $controller = Mockery::mock(ValidateController::class)
186
            ->makePartial()
187
            ->shouldAllowMockingProtectedMethods()
188
            ->shouldReceive('casValidate')
189
            ->andReturnUsing(
190
                function ($request, $returnAttr, $allowProxy) {
191
                    $this->assertTrue($returnAttr);
192
                    $this->assertFalse($allowProxy);
193
194
                    return 'casValidate called';
195
                }
196
            )
197
            ->once()
198
            ->getMock();
199
        $request    = Mockery::mock(Request::class);
200
        $this->assertEquals('casValidate called', $controller->v3ServiceValidateAction($request));
201
    }
202
203 View Code Duplication
    public function testV3ProxyValidateAction()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
204
    {
205
        $controller = Mockery::mock(ValidateController::class)
206
            ->makePartial()
207
            ->shouldAllowMockingProtectedMethods()
208
            ->shouldReceive('casValidate')
209
            ->andReturnUsing(
210
                function ($request, $returnAttr, $allowProxy) {
211
                    $this->assertTrue($returnAttr);
212
                    $this->assertTrue($allowProxy);
213
214
                    return 'casValidate called';
215
                }
216
            )
217
            ->once()
218
            ->getMock();
219
        $request    = Mockery::mock(Request::class);
220
        $this->assertEquals('casValidate called', $controller->v3ProxyValidateAction($request));
221
    }
222
223
    public function testProxyActionWithInvalidRequest()
224
    {
225
        $request    = Mockery::mock(Request::class)
0 ignored issues
show
Bug introduced by
The method shouldReceive() does not seem to exist on object<Mockery\Expectation>.

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...
226
            ->shouldReceive('get')
227
            ->with('pgt', '')
228
            ->andReturn('')
229
            ->once()
230
            ->shouldReceive('get')
231
            ->with('targetService', '')
232
            ->andReturn('')
233
            ->once()
234
            ->shouldReceive('get')
235
            ->with('format', 'XML')
236
            ->andReturn('XML')
237
            ->once()
238
            ->getMock();
239
        $controller = $this->initController()
240
            ->makePartial()
241
            ->shouldAllowMockingProtectedMethods()
242
            ->shouldReceive('proxyFailureResponse')
243
            ->andReturnUsing(
244 View Code Duplication
                function ($code, $desc, $format) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
245
                    $this->assertEquals(CasException::INVALID_REQUEST, $code);
246
                    $this->assertEquals('param pgt and targetService can not be empty', $desc);
247
                    $this->assertEquals('XML', $format);
248
249
                    return 'proxyFailureResponse called';
250
                }
251
            )
252
            ->once()
253
            ->getMock();
254
        $this->assertEquals('proxyFailureResponse called', $controller->proxyAction($request));
255
    }
256
257
    public function testCasValidateWithInvalidRequest()
258
    {
259
        $request = Mockery::mock(Request::class)
0 ignored issues
show
Bug introduced by
The method shouldReceive() does not seem to exist on object<Mockery\Expectation>.

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...
260
            ->shouldReceive('get')
261
            ->withArgs(['ticket', ''])
262
            ->andReturn('')
263
            ->once()
264
            ->shouldReceive('get')
265
            ->withArgs(['service', ''])
266
            ->andReturn('')
267
            ->once()
268
            ->shouldReceive('get')
269
            ->withArgs(['format', 'XML'])
270
            ->andReturn('JSON')
271
            ->once()
272
            ->getMock();
273
274
        $controller = $this->initController()
275
            ->makePartial()
276
            ->shouldAllowMockingProtectedMethods()
277
            ->shouldReceive('authFailureResponse')
278
            ->andReturnUsing(
279 View Code Duplication
                function ($code, $desc, $format) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
280
                    $this->assertEquals(CasException::INVALID_REQUEST, $code);
281
                    $this->assertEquals('param service and ticket can not be empty', $desc);
282
                    $this->assertEquals('JSON', $format);
283
284
                    return 'authFailureResponse called';
285
                }
286
            )
287
            ->once()
288
            ->getMock();
289
        $method     = self::getNonPublicMethod($controller, 'casValidate');
290
        $this->assertEquals('authFailureResponse called', $method->invokeArgs($controller, [$request, false, false]));
291
    }
292
293
    public function testCasValidateAndLockTicketFailed()
294
    {
295
        $request    = $this->getValidRequest();
296
        $controller = $this->initController()
297
            ->makePartial()
298
            ->shouldAllowMockingProtectedMethods()
299
            ->shouldReceive('lockTicket')
300
            ->andReturn(false)
301
            ->once()
302
            ->shouldReceive('authFailureResponse')
303
            ->andReturnUsing(
304 View Code Duplication
                function ($code, $desc, $format) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
305
                    $this->assertEquals(CasException::INTERNAL_ERROR, $code);
306
                    $this->assertEquals('try to lock ticket failed', $desc);
307
                    $this->assertEquals('JSON', $format);
308
309
                    return 'authFailureResponse called';
310
                }
311
            )
312
            ->once()
313
            ->getMock();
314
        $method     = self::getNonPublicMethod($controller, 'casValidate');
315
        $this->assertEquals('authFailureResponse called', $method->invokeArgs($controller, [$request, false, false]));
316
    }
317
318
    public function testCasValidateWithInvalidTicket()
319
    {
320
        $request          = $this->getValidRequest();
321
        $ticketRepository = Mockery::mock(TicketRepository::class)
322
            ->shouldReceive('getByTicket')
323
            ->andReturnNull()
324
            ->once()
325
            ->getMock();
326
        app()->instance(TicketRepository::class, $ticketRepository);
327
        $controller = $this->initController()
328
            ->makePartial()
329
            ->shouldAllowMockingProtectedMethods()
330
            ->shouldReceive('unlockTicket')
331
            ->once()
332
            ->shouldReceive('lockTicket')
333
            ->andReturn(true)
334
            ->once()
335
            ->shouldReceive('authFailureResponse')
336
            ->andReturnUsing(
337 View Code Duplication
                function ($code, $desc, $format) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
338
                    $this->assertEquals(CasException::INVALID_TICKET, $code);
339
                    $this->assertEquals('ticket is not valid', $desc);
340
                    $this->assertEquals('JSON', $format);
341
342
                    return 'authFailureResponse called';
343
                }
344
            )
345
            ->once()
346
            ->getMock();
347
        $method     = self::getNonPublicMethod($controller, 'casValidate');
348
        $this->assertEquals('authFailureResponse called', $method->invokeArgs($controller, [$request, false, false]));
349
    }
350
351
    public function testCasValidateWithValidTicketButServiceMismatch()
352
    {
353
        $request          = $this->getValidRequest();
354
        $ticket           = Mockery::mock(Ticket::class)
0 ignored issues
show
Bug introduced by
The method shouldReceive() does not seem to exist on object<Mockery\Expectation>.

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...
355
            ->shouldReceive('getAttribute')
356
            ->withArgs(['service_url'])
357
            ->andReturn('http://github.com')
358
            ->once()
359
            ->shouldReceive('isProxy')
360
            ->andReturn(false)
361
            ->once()
362
            ->getMock();
363
        $ticketRepository = Mockery::mock(TicketRepository::class)
0 ignored issues
show
Bug introduced by
The method shouldReceive() does not seem to exist on object<Mockery\Expectation>.

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...
364
            ->shouldReceive('invalidTicket')
365
            ->once()
366
            ->shouldReceive('getByTicket')
367
            ->andReturn($ticket)
368
            ->once()
369
            ->getMock();
370
        app()->instance(TicketRepository::class, $ticketRepository);
371
        $controller = $this->initController()
372
            ->makePartial()
373
            ->shouldAllowMockingProtectedMethods()
374
            ->shouldReceive('unlockTicket')
375
            ->once()
376
            ->shouldReceive('lockTicket')
377
            ->andReturn(true)
378
            ->once()
379
            ->shouldReceive('authFailureResponse')
380
            ->andReturnUsing(
381 View Code Duplication
                function ($code, $desc, $format) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
382
                    $this->assertEquals(CasException::INVALID_SERVICE, $code);
383
                    $this->assertEquals('service is not valid', $desc);
384
                    $this->assertEquals('JSON', $format);
385
386
                    return 'authFailureResponse called';
387
                }
388
            )
389
            ->once()
390
            ->getMock();
391
        $method     = self::getNonPublicMethod($controller, 'casValidate');
392
        $this->assertEquals('authFailureResponse called', $method->invokeArgs($controller, [$request, false, false]));
393
    }
394
395
    public function testCasValidateWithValidProxyTicketButNotAllowProxy()
396
    {
397
        $request          = $this->getValidRequest();
398
        $ticket           = Mockery::mock(Ticket::class)
399
            ->shouldReceive('isProxy')
400
            ->andReturn(true)
401
            ->once()
402
            ->getMock();
403
        $ticketRepository = Mockery::mock(TicketRepository::class)
0 ignored issues
show
Bug introduced by
The method shouldReceive() does not seem to exist on object<Mockery\Expectation>.

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...
404
            ->shouldReceive('invalidTicket')
405
            ->once()
406
            ->shouldReceive('getByTicket')
407
            ->andReturn($ticket)
408
            ->once()
409
            ->getMock();
410
        app()->instance(TicketRepository::class, $ticketRepository);
411
        $controller = $this->initController()
412
            ->makePartial()
413
            ->shouldAllowMockingProtectedMethods()
414
            ->shouldReceive('unlockTicket')
415
            ->once()
416
            ->shouldReceive('lockTicket')
417
            ->andReturn(true)
418
            ->once()
419
            ->shouldReceive('authFailureResponse')
420
            ->andReturnUsing(
421 View Code Duplication
                function ($code, $desc, $format) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
422
                    $this->assertEquals(CasException::INVALID_TICKET, $code);
423
                    $this->assertEquals('ticket is not valid', $desc);
424
                    $this->assertEquals('JSON', $format);
425
426
                    return 'authFailureResponse called';
427
                }
428
            )
429
            ->once()
430
            ->getMock();
431
        $method     = self::getNonPublicMethod($controller, 'casValidate');
432
        $this->assertEquals('authFailureResponse called', $method->invokeArgs($controller, [$request, false, false]));
433
    }
434
435
    public function testCasValidateWithValidProxyTicketAndAllowProxy()
436
    {
437
        $proxies          = ['http://proxy1.com', 'http://proxy2.com'];
438
        $request          = $this->getValidRequest('');
439
        $user             = Mockery::mock(User::class)
440
            ->shouldReceive('getName')
441
            ->andReturn('test_user')
442
            ->once()
443
            ->getMock();
444
        $ticket           = Mockery::mock(Ticket::class)
0 ignored issues
show
Bug introduced by
The method shouldReceive() does not seem to exist on object<Mockery\Expectation>.

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...
445
            ->shouldReceive('isProxy')
446
            ->andReturn(true)
447
            ->once()
448
            ->shouldReceive('getAttribute')
449
            ->with('proxies')
450
            ->andReturn($proxies)
451
            ->once()
452
            ->shouldReceive('getAttribute')
453
            ->withArgs(['service_url'])
454
            ->andReturn('http://leo108.com')
455
            ->once()
456
            ->shouldReceive('getAttribute')
457
            ->withArgs(['user'])
458
            ->andReturn($user)
459
            ->times(2)
460
            ->getMock();
461
        $ticketRepository = Mockery::mock(TicketRepository::class)
0 ignored issues
show
Bug introduced by
The method shouldReceive() does not seem to exist on object<Mockery\Expectation>.

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...
462
            ->shouldReceive('invalidTicket')
463
            ->once()
464
            ->shouldReceive('getByTicket')
465
            ->andReturn($ticket)
466
            ->once()
467
            ->getMock();
468
        app()->instance(TicketRepository::class, $ticketRepository);
469
        $controller = $this->initController()
470
            ->makePartial()
471
            ->shouldAllowMockingProtectedMethods()
472
            ->shouldReceive('lockTicket')
473
            ->andReturn(true)
474
            ->once()
475
            ->shouldReceive('unlockTicket')
476
            ->once()
477
            ->shouldReceive('authSuccessResponse')
478
            ->andReturnUsing(
479
                function ($name, $format, $attributes, $proxiesParam, $iou) use ($proxies) {
480
                    $this->assertEquals('test_user', $name);
481
                    $this->assertEmpty($attributes);
482
                    $this->assertEquals('JSON', $format);
483
                    $this->assertEquals($proxies, $proxiesParam);
484
                    $this->assertNull($iou);
485
486
                    return 'authSuccessResponse called';
487
                }
488
            )
489
            ->once()
490
            ->getMock();
491
        $method     = self::getNonPublicMethod($controller, 'casValidate');
492
        $this->assertEquals('authSuccessResponse called', $method->invokeArgs($controller, [$request, false, true]));
493
    }
494
495
    public function testCasValidateWithValidTicketAndServiceAndNoPgt()
496
    {
497
        $request          = $this->getValidRequest('');
498
        $user             = Mockery::mock(User::class)
499
            ->shouldReceive('getName')
500
            ->andReturn('test_user')
501
            ->once()
502
            ->getMock();
503
        $ticket           = Mockery::mock(Ticket::class)
0 ignored issues
show
Bug introduced by
The method shouldReceive() does not seem to exist on object<Mockery\Expectation>.

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...
504
            ->shouldReceive('isProxy')
505
            ->andReturn(false)
506
            ->times(2)
507
            ->shouldReceive('getAttribute')
508
            ->withArgs(['service_url'])
509
            ->andReturn('http://leo108.com')
510
            ->once()
511
            ->shouldReceive('getAttribute')
512
            ->withArgs(['user'])
513
            ->andReturn($user)
514
            ->times(2)
515
            ->getMock();
516
        $ticketRepository = Mockery::mock(TicketRepository::class)
0 ignored issues
show
Bug introduced by
The method shouldReceive() does not seem to exist on object<Mockery\Expectation>.

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...
517
            ->shouldReceive('getByTicket')
518
            ->andReturn($ticket)
519
            ->once()
520
            ->shouldReceive('invalidTicket')
521
            ->once()
522
            ->getMock();
523
        app()->instance(TicketRepository::class, $ticketRepository);
524
        $controller = $this->initController()
525
            ->makePartial()
526
            ->shouldAllowMockingProtectedMethods()
527
            ->shouldReceive('lockTicket')
528
            ->andReturn(true)
529
            ->once()
530
            ->shouldReceive('unlockTicket')
531
            ->once()
532
            ->shouldReceive('authSuccessResponse')
533
            ->andReturnUsing(
534
                function ($name, $format, $attributes, $proxies, $iou) {
535
                    $this->assertEquals('test_user', $name);
536
                    $this->assertEmpty($attributes);
537
                    $this->assertEquals('JSON', $format);
538
                    $this->assertEmpty($proxies);
539
                    $this->assertNull($iou);
540
541
                    return 'authSuccessResponse called';
542
                }
543
            )
544
            ->once()
545
            ->getMock();
546
547
        $method = self::getNonPublicMethod($controller, 'casValidate');
548
        $this->assertEquals('authSuccessResponse called', $method->invokeArgs($controller, [$request, false, false]));
549
    }
550
551
    public function testCasValidateWithValidTicketAndServiceAndPgtButApplyPGTFailed()
552
    {
553
        $request          = $this->getValidRequest('http://app1.com/pgtCallback');
554
        $user             = Mockery::mock(User::class)
555
            ->shouldReceive('getName')
556
            ->andReturn('test_user')
557
            ->once()
558
            ->getMock();
559
        $ticket           = Mockery::mock(Ticket::class)
0 ignored issues
show
Bug introduced by
The method shouldReceive() does not seem to exist on object<Mockery\Expectation>.

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...
560
            ->shouldReceive('isProxy')
561
            ->andReturn(false)
562
            ->times(2)
563
            ->shouldReceive('getAttribute')
564
            ->withArgs(['service_url'])
565
            ->andReturn('http://leo108.com')
566
            ->once()
567
            ->shouldReceive('getAttribute')
568
            ->withArgs(['user'])
569
            ->andReturn($user)
570
            ->times(2)
571
            ->getMock();
572
        $ticketRepository = Mockery::mock(TicketRepository::class)
0 ignored issues
show
Bug introduced by
The method shouldReceive() does not seem to exist on object<Mockery\Expectation>.

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...
573
            ->shouldReceive('getByTicket')
574
            ->andReturn($ticket)
575
            ->once()
576
            ->shouldReceive('invalidTicket')
577
            ->once()
578
            ->getMock();
579
        app()->instance(TicketRepository::class, $ticketRepository);
580
        $pgTicketRepository = Mockery::mock(PGTicketRepository::class)
581
            ->shouldReceive('applyTicket')
582
            ->andThrow(new CasException(CasException::INTERNAL_ERROR))
583
            ->once()
584
            ->getMock();
585
        app()->instance(PGTicketRepository::class, $pgTicketRepository);
586
        $controller = $this->initController()
587
            ->makePartial()
588
            ->shouldAllowMockingProtectedMethods()
589
            ->shouldReceive('lockTicket')
590
            ->andReturn(true)
591
            ->once()
592
            ->shouldReceive('unlockTicket')
593
            ->once()
594
            ->shouldReceive('authSuccessResponse')
595
            ->andReturnUsing(
596
                function ($name, $format, $attributes, $proxies, $iou) {
597
                    $this->assertEquals('test_user', $name);
598
                    $this->assertEmpty($attributes);
599
                    $this->assertEquals('JSON', $format);
600
                    $this->assertEmpty($proxies);
601
                    $this->assertNull($iou);
602
603
                    return 'authSuccessResponse called';
604
                }
605
            )
606
            ->once()
607
            ->getMock();
608
609
        $method = self::getNonPublicMethod($controller, 'casValidate');
610
        $this->assertEquals('authSuccessResponse called', $method->invokeArgs($controller, [$request, false, false]));
611
    }
612
613 View Code Duplication
    public function testCasValidateWithValidTicketAndServiceAndPgtButCallPgtUrlFailed()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
614
    {
615
        $request          = $this->getValidRequest('http://app1.com/pgtCallback');
616
        $user             = Mockery::mock(User::class)
617
            ->shouldReceive('getName')
618
            ->andReturn('test_user')
619
            ->once()
620
            ->getMock();
621
        $ticket           = Mockery::mock(Ticket::class)
0 ignored issues
show
Bug introduced by
The method shouldReceive() does not seem to exist on object<Mockery\Expectation>.

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...
622
            ->shouldReceive('isProxy')
623
            ->andReturn(false)
624
            ->times(2)
625
            ->shouldReceive('getAttribute')
626
            ->withArgs(['service_url'])
627
            ->andReturn('http://leo108.com')
628
            ->once()
629
            ->shouldReceive('getAttribute')
630
            ->withArgs(['user'])
631
            ->andReturn($user)
632
            ->times(2)
633
            ->getMock();
634
        $ticketRepository = Mockery::mock(TicketRepository::class)
0 ignored issues
show
Bug introduced by
The method shouldReceive() does not seem to exist on object<Mockery\Expectation>.

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...
635
            ->shouldReceive('getByTicket')
636
            ->andReturn($ticket)
637
            ->once()
638
            ->shouldReceive('invalidTicket')
639
            ->once()
640
            ->getMock();
641
        app()->instance(TicketRepository::class, $ticketRepository);
642
        $pgTicketRepository = Mockery::mock(PGTicketRepository::class)
643
            ->shouldReceive('applyTicket')
644
            ->andReturn('some string')
645
            ->once()
646
            ->getMock();
647
        app()->instance(PGTicketRepository::class, $pgTicketRepository);
648
        $ticketGenerator = Mockery::mock(TicketGenerator::class)
649
            ->shouldReceive('generateOne')
650
            ->andReturn('pgtiou string')
651
            ->once()
652
            ->getMock();
653
        app()->instance(TicketGenerator::class, $ticketGenerator);
654
        $pgtCaller = Mockery::mock(PGTCaller::class)
655
            ->shouldReceive('call')
656
            ->andReturn(false)
657
            ->once()
658
            ->getMock();
659
        app()->instance(PGTCaller::class, $pgtCaller);
660
        $controller = $this->initController()
661
            ->makePartial()
662
            ->shouldAllowMockingProtectedMethods()
663
            ->shouldReceive('lockTicket')
664
            ->andReturn(true)
665
            ->once()
666
            ->shouldReceive('unlockTicket')
667
            ->once()
668
            ->shouldReceive('authSuccessResponse')
669
            ->andReturnUsing(
670
                function ($name, $format, $attributes, $proxies, $iou) {
671
                    $this->assertEquals('test_user', $name);
672
                    $this->assertEmpty($attributes);
673
                    $this->assertEquals('JSON', $format);
674
                    $this->assertEmpty($proxies);
675
                    $this->assertNull($iou);
676
677
                    return 'authSuccessResponse called';
678
                }
679
            )
680
            ->once()
681
            ->getMock();
682
683
        $method = self::getNonPublicMethod($controller, 'casValidate');
684
        $this->assertEquals('authSuccessResponse called', $method->invokeArgs($controller, [$request, false, false]));
685
    }
686
687 View Code Duplication
    public function testCasValidateWithValidTicketAndServiceAndPgtButCallPgtUrlSuccess()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
688
    {
689
        $request          = $this->getValidRequest('http://app1.com/pgtCallback');
690
        $user             = Mockery::mock(User::class)
691
            ->shouldReceive('getName')
692
            ->andReturn('test_user')
693
            ->once()
694
            ->getMock();
695
        $ticket           = Mockery::mock(Ticket::class)
0 ignored issues
show
Bug introduced by
The method shouldReceive() does not seem to exist on object<Mockery\Expectation>.

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...
696
            ->shouldReceive('isProxy')
697
            ->andReturn(false)
698
            ->times(2)
699
            ->shouldReceive('getAttribute')
700
            ->withArgs(['service_url'])
701
            ->andReturn('http://leo108.com')
702
            ->once()
703
            ->shouldReceive('getAttribute')
704
            ->withArgs(['user'])
705
            ->andReturn($user)
706
            ->times(2)
707
            ->getMock();
708
        $ticketRepository = Mockery::mock(TicketRepository::class)
0 ignored issues
show
Bug introduced by
The method shouldReceive() does not seem to exist on object<Mockery\Expectation>.

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...
709
            ->shouldReceive('getByTicket')
710
            ->andReturn($ticket)
711
            ->once()
712
            ->shouldReceive('invalidTicket')
713
            ->once()
714
            ->getMock();
715
        app()->instance(TicketRepository::class, $ticketRepository);
716
        $pgTicketRepository = Mockery::mock(PGTicketRepository::class)
717
            ->shouldReceive('applyTicket')
718
            ->andReturn('some string')
719
            ->once()
720
            ->getMock();
721
        app()->instance(PGTicketRepository::class, $pgTicketRepository);
722
        $ticketGenerator = Mockery::mock(TicketGenerator::class)
723
            ->shouldReceive('generateOne')
724
            ->andReturn('pgtiou string')
725
            ->once()
726
            ->getMock();
727
        app()->instance(TicketGenerator::class, $ticketGenerator);
728
        $pgtCaller = Mockery::mock(PGTCaller::class)
729
            ->shouldReceive('call')
730
            ->andReturn(true)
731
            ->once()
732
            ->getMock();
733
        app()->instance(PGTCaller::class, $pgtCaller);
734
        $controller = $this->initController()
735
            ->makePartial()
736
            ->shouldAllowMockingProtectedMethods()
737
            ->shouldReceive('lockTicket')
738
            ->andReturn(true)
739
            ->once()
740
            ->shouldReceive('unlockTicket')
741
            ->once()
742
            ->shouldReceive('authSuccessResponse')
743
            ->andReturnUsing(
744
                function ($name, $format, $attributes, $proxies, $iou) {
745
                    $this->assertEquals('test_user', $name);
746
                    $this->assertEmpty($attributes);
747
                    $this->assertEquals('JSON', $format);
748
                    $this->assertEmpty($proxies);
749
                    $this->assertEquals('pgtiou string', $iou);
750
751
                    return 'authSuccessResponse called';
752
                }
753
            )
754
            ->once()
755
            ->getMock();
756
757
        $method = self::getNonPublicMethod($controller, 'casValidate');
758
        $this->assertEquals('authSuccessResponse called', $method->invokeArgs($controller, [$request, false, false]));
759
    }
760
761 View Code Duplication
    public function testCasValidateWithValidProxyTicketAndServiceAndPgtButCallPgtUrlSuccess()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
762
    {
763
        $request          = $this->getValidRequest('http://app1.com/pgtCallback');
764
        $user             = Mockery::mock(User::class)
765
            ->shouldReceive('getName')
766
            ->andReturn('test_user')
767
            ->once()
768
            ->getMock();
769
        $ticket           = Mockery::mock(Ticket::class)
0 ignored issues
show
Bug introduced by
The method shouldReceive() does not seem to exist on object<Mockery\Expectation>.

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...
770
            ->shouldReceive('isProxy')
771
            ->andReturn(false)
772
            ->times(2)
773
            ->shouldReceive('getAttribute')
774
            ->withArgs(['service_url'])
775
            ->andReturn('http://leo108.com')
776
            ->once()
777
            ->shouldReceive('getAttribute')
778
            ->withArgs(['user'])
779
            ->andReturn($user)
780
            ->times(2)
781
            ->getMock();
782
        $ticketRepository = Mockery::mock(TicketRepository::class)
0 ignored issues
show
Bug introduced by
The method shouldReceive() does not seem to exist on object<Mockery\Expectation>.

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...
783
            ->shouldReceive('getByTicket')
784
            ->andReturn($ticket)
785
            ->once()
786
            ->shouldReceive('invalidTicket')
787
            ->once()
788
            ->getMock();
789
        app()->instance(TicketRepository::class, $ticketRepository);
790
        $pgTicketRepository = Mockery::mock(PGTicketRepository::class)
791
            ->shouldReceive('applyTicket')
792
            ->andReturn('some string')
793
            ->once()
794
            ->getMock();
795
        app()->instance(PGTicketRepository::class, $pgTicketRepository);
796
        $ticketGenerator = Mockery::mock(TicketGenerator::class)
797
            ->shouldReceive('generateOne')
798
            ->andReturn('pgtiou string')
799
            ->once()
800
            ->getMock();
801
        app()->instance(TicketGenerator::class, $ticketGenerator);
802
        $pgtCaller = Mockery::mock(PGTCaller::class)
803
            ->shouldReceive('call')
804
            ->andReturn(true)
805
            ->once()
806
            ->getMock();
807
        app()->instance(PGTCaller::class, $pgtCaller);
808
        $controller = $this->initController()
809
            ->makePartial()
810
            ->shouldAllowMockingProtectedMethods()
811
            ->shouldReceive('lockTicket')
812
            ->andReturn(true)
813
            ->once()
814
            ->shouldReceive('unlockTicket')
815
            ->once()
816
            ->shouldReceive('authSuccessResponse')
817
            ->andReturnUsing(
818
                function ($name, $format, $attributes, $proxies, $iou) {
819
                    $this->assertEquals('test_user', $name);
820
                    $this->assertEmpty($attributes);
821
                    $this->assertEquals('JSON', $format);
822
                    $this->assertEmpty($proxies);
823
                    $this->assertEquals('pgtiou string', $iou);
824
825
                    return 'authSuccessResponse called';
826
                }
827
            )
828
            ->once()
829
            ->getMock();
830
831
        $method = self::getNonPublicMethod($controller, 'casValidate');
832
        $this->assertEquals('authSuccessResponse called', $method->invokeArgs($controller, [$request, false, false]));
833
    }
834
835 View Code Duplication
    public function testLockTicket()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
836
    {
837
        $locker = Mockery::mock(TicketLocker::class)
838
            ->shouldReceive('acquireLock')
839
            ->andReturn('acquireLock called')
840
            ->once()
841
            ->getMock();
842
        app()->instance(TicketLocker::class, $locker);
843
        $controller = $this->initController()
844
            ->makePartial();
845
        $method     = self::getNonPublicMethod($controller, 'lockTicket');
846
        $this->assertEquals('acquireLock called', $method->invokeArgs($controller, ['str', 30]));
847
    }
848
849 View Code Duplication
    public function testUnlockTicket()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
850
    {
851
        $locker = Mockery::mock(TicketLocker::class)
852
            ->shouldReceive('releaseLock')
853
            ->andReturn('releaseLock called')
854
            ->once()
855
            ->getMock();
856
        app()->instance(TicketLocker::class, $locker);
857
        $controller = $this->initController()
858
            ->makePartial();
859
        $method     = self::getNonPublicMethod($controller, 'unlockTicket');
860
        $this->assertEquals('releaseLock called', $method->invokeArgs($controller, ['str', 30]));
861
    }
862
863
    public function testAuthSuccessResponse()
864
    {
865
        $controller = Mockery::mock(ValidateController::class)
866
            ->makePartial();
867
        $method     = self::getNonPublicMethod($controller, 'authSuccessResponse');
868
869
        $name       = 'test_name';
870
        $attributes = [
871
            'real_name' => 'real_name',
872
        ];
873
        $proxies    = ['http://proxy1.com'];
874
        $pgt        = 'ticket';
875
        $jsonResp   = Mockery::mock(JsonAuthenticationSuccessResponse::class)
0 ignored issues
show
Bug introduced by
The method shouldReceive() does not seem to exist on object<Mockery\Expectation>.

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...
876
            ->shouldReceive('setUser')
877
            ->with($name)
878
            ->once()
879
            ->shouldReceive('setAttributes')
880
            ->with($attributes)
881
            ->once()
882
            ->shouldReceive('setProxies')
883
            ->with($proxies)
884
            ->once()
885
            ->shouldReceive('toResponse')
886
            ->once()
887
            ->getMock();
888
        app()->instance(JsonAuthenticationSuccessResponse::class, $jsonResp);
889
        $method->invokeArgs($controller, ['test_name', 'JSON', $attributes, $proxies, []]);
890
891
        $xmlResp = Mockery::mock(XmlAuthenticationSuccessResponse::class)
0 ignored issues
show
Bug introduced by
The method shouldReceive() does not seem to exist on object<Mockery\Expectation>.

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...
892
            ->shouldReceive('setUser')
893
            ->with($name)
894
            ->once()
895
            ->shouldReceive('setAttributes')
896
            ->with($attributes)
897
            ->once()
898
            ->shouldReceive('setProxies')
899
            ->with($proxies)
900
            ->once()
901
            ->shouldReceive('setProxyGrantingTicket')
902
            ->with($pgt)
903
            ->once()
904
            ->shouldReceive('toResponse')
905
            ->once()
906
            ->getMock();
907
        app()->instance(XmlAuthenticationSuccessResponse::class, $xmlResp);
908
        $method->invokeArgs($controller, ['test_name', 'XML', $attributes, $proxies, $pgt]);
909
    }
910
911
    public function testAuthFailureResponse()
912
    {
913
        $controller = Mockery::mock(ValidateController::class)
914
            ->makePartial();
915
        $method     = self::getNonPublicMethod($controller, 'authFailureResponse');
916
        $code       = 'code';
917
        $desc       = 'desc';
918
        $jsonResp   = Mockery::mock(JsonAuthenticationFailureResponse::class)
0 ignored issues
show
Bug introduced by
The method shouldReceive() does not seem to exist on object<Mockery\Expectation>.

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...
919
            ->shouldReceive('setFailure')
920
            ->withArgs([$code, $desc])
921
            ->once()
922
            ->shouldReceive('toResponse')
923
            ->once()
924
            ->getMock();
925
        app()->instance(JsonAuthenticationFailureResponse::class, $jsonResp);
926
        $method->invokeArgs($controller, [$code, $desc, 'JSON']);
927
928
        $xmlResp = Mockery::mock(XmlAuthenticationFailureResponse::class)
0 ignored issues
show
Bug introduced by
The method shouldReceive() does not seem to exist on object<Mockery\Expectation>.

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...
929
            ->shouldReceive('setFailure')
930
            ->withArgs([$code, $desc])
931
            ->once()
932
            ->shouldReceive('toResponse')
933
            ->once()
934
            ->getMock();
935
        app()->instance(XmlAuthenticationFailureResponse::class, $xmlResp);
936
        $method->invokeArgs($controller, [$code, $desc, 'XML']);
937
    }
938
939
    protected function getValidRequest($pgt = null)
940
    {
941
        $mock = Mockery::mock(Request::class)
942
            ->shouldReceive('get')
943
            ->withArgs(['ticket', ''])
944
            ->andReturn('ticket')
945
            ->shouldReceive('get')
946
            ->withArgs(['service', ''])
947
            ->andReturn('http://leo108.com')
948
            ->shouldReceive('get')
949
            ->withArgs(['format', 'XML'])
950
            ->andReturn('JSON');
951
        if (!is_null($pgt)) {
952
            $mock->shouldReceive('get')
953
                ->withArgs(['pgtUrl', ''])
954
                ->andReturn($pgt);
955
        }
956
957
        return $mock->getMock();
958
    }
959
960
    /**
961
     * @return Mockery\MockInterface
962
     */
963
    protected function initController()
964
    {
965
        return Mockery::mock(
966
            ValidateController::class,
967
            [
968
                app(TicketLocker::class),
969
                app(TicketRepository::class),
970
                app(PGTicketRepository::class),
971
                app(TicketGenerator::class),
972
                app(PGTCaller::class),
973
            ]
974
        );
975
    }
976
}
977