Failed Conditions
Push — ng ( f9780e...ccd5de )
by Florent
11:07
created

ScopePolicyDefaultRuleTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 4
dl 0
loc 57
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A theParameterMustBeAString() 0 9 1
A theParameterContainsForbiddenCharacters() 0 9 1
A theParameterIsValid() 0 11 1
A getCallable() 0 6 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\Scope\Tests;
15
16
use OAuth2Framework\Component\Server\Core\Client\ClientId;
17
use OAuth2Framework\Component\Server\Core\DataBag\DataBag;
18
use OAuth2Framework\Component\Server\Scope\Rule\ScopePolicyDefaultRule;
19
use PHPUnit\Framework\TestCase;
20
21
/**
22
 * @group Rule
23
 */
24
final class ScopePolicyDefaultRuleTest extends TestCase
25
{
26
    /**
27
     * @test
28
     * @expectedException \InvalidArgumentException
29
     * @expectedExceptionMessage The "default_scope" parameter must be a string.
30
     */
31
    public function theParameterMustBeAString()
32
    {
33
        $clientId = ClientId::create('CLIENT_ID');
34
        $commandParameters = DataBag::create([
35
            'default_scope' => ['foo'],
36
        ]);
37
        $rule = new ScopePolicyDefaultRule();
38
        $rule->handle($clientId, $commandParameters, DataBag::create([]), $this->getCallable());
39
    }
40
41
    /**
42
     * @test
43
     * @expectedException \InvalidArgumentException
44
     * @expectedExceptionMessage Invalid characters found in the "default_scope" parameter.
45
     */
46
    public function theParameterContainsForbiddenCharacters()
47
    {
48
        $clientId = ClientId::create('CLIENT_ID');
49
        $commandParameters = DataBag::create([
50
            'default_scope' => 'coffee, café',
51
        ]);
52
        $rule = new ScopePolicyDefaultRule();
53
        $rule->handle($clientId, $commandParameters, DataBag::create([]), $this->getCallable());
54
    }
55
56
    /**
57
     * @test
58
     */
59
    public function theParameterIsValid()
60
    {
61
        $clientId = ClientId::create('CLIENT_ID');
62
        $commandParameters = DataBag::create([
63
            'default_scope' => 'coffee cream',
64
        ]);
65
        $rule = new ScopePolicyDefaultRule();
66
        $validatedParameters = $rule->handle($clientId, $commandParameters, DataBag::create([]), $this->getCallable());
67
        self::assertTrue($validatedParameters->has('default_scope'));
68
        self::assertEquals('coffee cream', $validatedParameters->get('default_scope'));
69
    }
70
71
    /**
72
     * @return callable
73
     */
74
    private function getCallable(): callable
75
    {
76
        return function (ClientId $clientId, DataBag $commandParameters, DataBag $validatedParameters): DataBag {
77
            return $validatedParameters;
78
        };
79
    }
80
}
81