Failed Conditions
Push — master ( 1bae70...6a9de1 )
by Florent
40:14
created

AuthorizationRequestTest::basicCalls()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 54

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 54
rs 9.0036
c 0
b 0
f 0
cc 1
nc 1
nop 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * The MIT License (MIT)
7
 *
8
 * Copyright (c) 2014-2018 Spomky-Labs
9
 *
10
 * This software may be modified and distributed under the terms
11
 * of the MIT license.  See the LICENSE file for details.
12
 */
13
14
namespace OAuth2Framework\Component\AuthorizationEndpoint\Tests\AuthorizationRequest;
15
16
use OAuth2Framework\Component\AuthorizationEndpoint\AuthorizationRequest\AuthorizationRequest;
17
use OAuth2Framework\Component\AuthorizationEndpoint\ResponseMode\ResponseMode;
18
use OAuth2Framework\Component\AuthorizationEndpoint\ResponseType\ResponseType;
19
use OAuth2Framework\Component\Core\Client\Client;
20
use OAuth2Framework\Component\Core\DataBag\DataBag;
21
use OAuth2Framework\Component\Core\ResourceServer\ResourceServer;
22
use OAuth2Framework\Component\Core\TokenType\TokenType;
23
use OAuth2Framework\Component\Core\UserAccount\UserAccount;
24
use PHPUnit\Framework\TestCase;
25
26
/**
27
 * @group AuthorizationEndpoint
28
 * @group AuthorizationRequest
29
 */
30
final class AuthorizationRequestTest extends TestCase
31
{
32
    /**
33
     * @test
34
     */
35
    public function basicCalls()
36
    {
37
        $client = $this->prophesize(Client::class);
38
        $tokenType = $this->prophesize(TokenType::class);
39
        $responseType = $this->prophesize(ResponseType::class);
40
        $responseMode = $this->prophesize(ResponseMode::class);
41
        $userAccount = $this->prophesize(UserAccount::class);
42
        $resourceServer = $this->prophesize(ResourceServer::class);
43
        $params = [
44
            'prompt' => 'consent login select_account',
45
            'ui_locales' => 'fr en',
46
            'scope' => 'scope1 scope2',
47
        ];
48
        $authorizationRequest = new AuthorizationRequest($client->reveal(), $params);
49
50
        $authorizationRequest->setTokenType($tokenType->reveal());
51
        $authorizationRequest->setResponseType($responseType->reveal());
52
        $authorizationRequest->setResponseMode($responseMode->reveal());
53
        $authorizationRequest->setRedirectUri('https://localhost');
54
        $authorizationRequest->setUserAccount($userAccount->reveal());
55
        $authorizationRequest->setResponseParameter('foo', 'bar');
56
        $authorizationRequest->setResponseHeader('X-FOO', 'bar');
57
        $authorizationRequest->setResourceServer($resourceServer->reveal());
58
        $authorizationRequest->setConsentScreenOption('foo', 'bar');
59
60
        static::assertEquals($params, $authorizationRequest->getQueryParams());
61
        static::assertFalse($authorizationRequest->hasQueryParam('client_id'));
62
        static::assertTrue($authorizationRequest->hasQueryParam('prompt'));
63
        static::assertEquals('consent login select_account', $authorizationRequest->getQueryParam('prompt'));
64
        static::assertInstanceOf(Client::class, $authorizationRequest->getClient());
65
        static::assertInstanceOf(TokenType::class, $authorizationRequest->getTokenType());
66
        static::assertInstanceOf(ResponseType::class, $authorizationRequest->getResponseType());
67
        static::assertInstanceOf(ResponseMode::class, $authorizationRequest->getResponseMode());
68
        static::assertEquals('https://localhost', $authorizationRequest->getRedirectUri());
69
        static::assertInstanceOf(UserAccount::class, $authorizationRequest->getUserAccount());
70
        static::assertEquals(['foo' => 'bar'], $authorizationRequest->getResponseParameters());
71
        static::assertFalse($authorizationRequest->hasResponseParameter('bar'));
72
        static::assertTrue($authorizationRequest->hasResponseParameter('foo'));
73
        static::assertEquals('bar', $authorizationRequest->getResponseParameter('foo'));
74
        static::assertEquals(['X-FOO' => 'bar'], $authorizationRequest->getResponseHeaders());
75
        static::assertFalse($authorizationRequest->hasPrompt('none'));
76
        static::assertTrue($authorizationRequest->hasPrompt('login'));
77
        static::assertEquals(['consent', 'login', 'select_account'], $authorizationRequest->getPrompt());
78
        static::assertTrue($authorizationRequest->hasUiLocales());
79
        static::assertEquals(['fr', 'en'], $authorizationRequest->getUiLocales());
80
        $authorizationRequest->allow();
81
        static::assertTrue($authorizationRequest->isAuthorized());
82
        $authorizationRequest->deny();
83
        static::assertFalse($authorizationRequest->isAuthorized());
84
        static::assertInstanceOf(ResourceServer::class, $authorizationRequest->getResourceServer());
85
        static::assertTrue($authorizationRequest->hasScope());
86
        static::assertEquals('scope1 scope2', $authorizationRequest->getScope());
87
        static::assertInstanceOf(DataBag::class, $authorizationRequest->getMetadata());
88
    }
89
}
90