Skip to content

Commit d9b75de

Browse files
dinamicdkarlovi
authored andcommitted
~ simplifying the AuthorizeController test
1 parent e0f0574 commit d9b75de

File tree

1 file changed

+8
-37
lines changed

1 file changed

+8
-37
lines changed

Tests/Controller/AuthorizeControllerTest.php

Lines changed: 8 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -151,10 +151,7 @@ public function setUp()
151151

152152
public function testAuthorizeActionWillThrowAccessDeniedException()
153153
{
154-
$token = $this->getMockBuilder(TokenInterface::class)
155-
->disableOriginalConstructor()
156-
->getMock()
157-
;
154+
$token = $this->createMock(TokenInterface::class);
158155

159156
$this->tokenStorage
160157
->expects($this->at(0))
@@ -176,10 +173,7 @@ public function testAuthorizeActionWillThrowAccessDeniedException()
176173

177174
public function testAuthorizeActionWillRenderTemplate()
178175
{
179-
$token = $this->getMockBuilder(TokenInterface::class)
180-
->disableOriginalConstructor()
181-
->getMock()
182-
;
176+
$token = $this->createMock(TokenInterface::class);
183177

184178
$this->tokenStorage
185179
->expects($this->at(0))
@@ -251,10 +245,7 @@ public function testAuthorizeActionWillRenderTemplate()
251245

252246
public function testAuthorizeActionWillFinishClientAuthorization()
253247
{
254-
$token = $this->getMockBuilder(TokenInterface::class)
255-
->disableOriginalConstructor()
256-
->getMock()
257-
;
248+
$token = $this->createMock(TokenInterface::class);
258249

259250
$this->tokenStorage
260251
->expects($this->at(0))
@@ -321,10 +312,7 @@ public function testAuthorizeActionWillFinishClientAuthorization()
321312

322313
public function testAuthorizeActionWillEnsureLogout()
323314
{
324-
$token = $this->getMockBuilder(TokenInterface::class)
325-
->disableOriginalConstructor()
326-
->getMock()
327-
;
315+
$token = $this->createMock(TokenInterface::class);
328316

329317
$this->tokenStorage
330318
->expects($this->at(0))
@@ -408,12 +396,9 @@ public function testAuthorizeActionWillEnsureLogout()
408396
$this->assertSame($response, $this->instance->authorizeAction($this->request));
409397
}
410398

411-
public function testAuthorizeActionWillProcessForm()
399+
public function testAuthorizeActionWillProcessAuthorizationForm()
412400
{
413-
$token = $this->getMockBuilder(TokenInterface::class)
414-
->disableOriginalConstructor()
415-
->getMock()
416-
;
401+
$token = $this->createMock(TokenInterface::class);
417402

418403
$this->tokenStorage
419404
->expects($this->once())
@@ -448,27 +433,18 @@ public function testAuthorizeActionWillProcessForm()
448433
$this->event
449434
->expects($this->once())
450435
->method('isAuthorizedClient')
451-
->with()
452436
->willReturn(false)
453437
;
454438

455439
$this->authorizeFormHandler
456440
->expects($this->once())
457441
->method('process')
458-
->with(
459-
$this->user,
460-
$this->authorizeFormHandler,
461-
$this->request
462-
)
463442
->willReturn(true)
464443
;
465444

466-
$this->markTestIncomplete('Not finished yet');
467-
468445
$this->authorizeFormHandler
469446
->expects($this->exactly(2))
470447
->method('isAccepted')
471-
->with()
472448
->willReturn(true)
473449
;
474450

@@ -486,14 +462,12 @@ public function testAuthorizeActionWillProcessForm()
486462
$this->form
487463
->expects($this->once())
488464
->method('getName')
489-
->with()
490465
->willReturn($formName)
491466
;
492467

493468
$this->request->query
494469
->expects($this->once())
495470
->method('all')
496-
->with()
497471
->willReturn([])
498472
;
499473

@@ -507,16 +481,15 @@ public function testAuthorizeActionWillProcessForm()
507481
$randomScope = 'scope' . \random_bytes(10);
508482

509483
$this->authorizeFormHandler
510-
->expects($this->at(3))
484+
->expects($this->once())
511485
->method('getScope')
512-
->with('scope', null)
513486
->willReturn($randomScope)
514487
;
515488

516489
$response = new Response();
517490

518491
$this->oAuth2Server
519-
->expects($this->at(4))
492+
->expects($this->once())
520493
->method('finishClientAuthorization')
521494
->with(
522495
true,
@@ -527,8 +500,6 @@ public function testAuthorizeActionWillProcessForm()
527500
->willReturn($response)
528501
;
529502

530-
var_dump($this->instance->authorizeAction($this->request));
531-
return;
532503
$this->assertSame($response, $this->instance->authorizeAction($this->request));
533504
}
534505
}

0 commit comments

Comments
 (0)