Failed Conditions
Push — ng ( 7370de...a36c25 )
by Florent
19:12
created

NoneAuthenticationMethodTest   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 70
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 7

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 7
dl 0
loc 70
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A genericCalls() 0 7 1
A theClientIdCannotBeFoundInTheRequest() 0 10 1
A theClientIdHasBeenFoundInTheRequest() 0 10 1
A theClientIsAuthenticated() 0 13 1
A theClientConfigurationCanBeChecked() 0 8 1
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\Server\TokenEndpoint\Tests;
15
16
use OAuth2Framework\Component\Server\Core\Client\Client;
17
use OAuth2Framework\Component\Server\Core\Client\ClientId;
18
use OAuth2Framework\Component\Server\Core\DataBag\DataBag;
19
use OAuth2Framework\Component\Server\Core\UserAccount\UserAccountId;
20
use OAuth2Framework\Component\Server\TokenEndpoint\AuthenticationMethod\None;
21
use PHPUnit\Framework\TestCase;
22
use Psr\Http\Message\ServerRequestInterface;
23
24
/**
25
 * @group TokenEndpoint
26
 * @group AuthenticationMethod
27
 */
28
final class NoneAuthenticationMethodTest extends TestCase
29
{
30
    /**
31
     * @test
32
     */
33
    public function genericCalls()
34
    {
35
        $method = new None();
36
37
        self::assertEquals([], $method->getSchemesParameters());
38
        self::assertEquals(['none'], $method->getSupportedAuthenticationMethods());
39
    }
40
41
    /**
42
     * @test
43
     */
44
    public function theClientIdCannotBeFoundInTheRequest()
45
    {
46
        $method = new None();
47
        $request = $this->prophesize(ServerRequestInterface::class);
48
        $request->getParsedBody()->willReturn([]);
49
50
        $clientId = $method->findClientId($request->reveal(), $credentials);
51
        self::assertNull($clientId);
52
        self::assertNull($credentials);
53
    }
54
55
    /**
56
     * @test
57
     */
58
    public function theClientIdHasBeenFoundInTheRequest()
59
    {
60
        $method = new None();
61
        $request = $this->prophesize(ServerRequestInterface::class);
62
        $request->getParsedBody()->willReturn(['client_id' => 'CLIENT_ID']);
63
64
        $clientId = $method->findClientId($request->reveal(), $credentials);
65
        self::assertInstanceOf(ClientId::class, $clientId);
66
        self::assertNull($credentials);
67
    }
68
69
    /**
70
     * @test
71
     */
72
    public function theClientIsAuthenticated()
73
    {
74
        $method = new None();
75
        $request = $this->prophesize(ServerRequestInterface::class);
76
        $client = Client::createEmpty();
77
        $client = $client->create(
78
            ClientId::create('CLIENT_ID'),
79
            DataBag::create([]),
80
            UserAccountId::create('USER_ACCOUNT_ID')
81
        );
82
83
        self::assertTrue($method->isClientAuthenticated($client, null, $request->reveal()));
84
    }
85
86
    /**
87
     * @test
88
     */
89
    public function theClientConfigurationCanBeChecked()
90
    {
91
        $method = new None();
92
        $parameters = DataBag::create([]);
93
        $validatedParameters = DataBag::create([]);
94
95
        self::assertSame($validatedParameters, $method->checkClientConfiguration($parameters, $validatedParameters));
96
    }
97
}
98