Failed Conditions
Push — ng ( 935f22...b3431d )
by Florent
04:01
created

ScopeRuleTest::getCallable()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 0
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\ScopeRule;
19
use PHPUnit\Framework\TestCase;
20
21
/**
22
 * @group Rule
23
 */
24
final class ScopeRuleTest extends TestCase
25
{
26
    /**
27
     * @test
28
     * @expectedException \InvalidArgumentException
29
     * @expectedExceptionMessage The "scope" parameter must be a string.
30
     */
31
    public function theParameterMustBeAString()
32
    {
33
        $clientId = ClientId::create('CLIENT_ID');
34
        $commandParameters = DataBag::create([
35
            'scope' => ['foo'],
36
        ]);
37
        $rule = new ScopeRule();
38
        $rule->handle($clientId, $commandParameters, DataBag::create([]), $this->getCallable());
39
    }
40
41
    /**
42
     * @test
43
     * @expectedException \InvalidArgumentException
44
     * @expectedExceptionMessage Invalid characters found in the "scope" parameter.
45
     */
46
    public function theParameterContainsForbiddenCharacters()
47
    {
48
        $clientId = ClientId::create('CLIENT_ID');
49
        $commandParameters = DataBag::create([
50
            'scope' => 'coffee, café',
51
        ]);
52
        $rule = new ScopeRule();
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
            'scope' => 'coffee cream',
64
        ]);
65
        $rule = new ScopeRule();
66
        $validatedParameters = $rule->handle($clientId, $commandParameters, DataBag::create([]), $this->getCallable());
67
        self::assertTrue($validatedParameters->has('scope'));
68
        self::assertEquals('coffee cream', $validatedParameters->get('scope'));
69
    }
70
71
72
    /**
73
     * @return callable
74
     */
75
    private function getCallable(): callable
76
    {
77
        return function (ClientId $clientId, DataBag $commandParameters, DataBag $validatedParameters): DataBag {
78
            return $validatedParameters;
79
        };
80
    }
81
}
82