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\ClientRegistrationEndpoint\Tests\Rule; |
15
|
|
|
|
16
|
|
|
use OAuth2Framework\Component\Server\Core\Client\ClientId; |
17
|
|
|
use OAuth2Framework\Component\Server\ClientRegistrationEndpoint\Rule; |
18
|
|
|
use OAuth2Framework\Component\Server\Core\DataBag\DataBag; |
19
|
|
|
use PHPUnit\Framework\TestCase; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @group Rule |
23
|
|
|
*/ |
24
|
|
|
final class ClientIdIssuedAtRuleTest extends TestCase |
25
|
|
|
{ |
26
|
|
|
/** |
27
|
|
|
* @test |
28
|
|
|
*/ |
29
|
|
|
public function testClientIdIssuedAtRuleSetAsDefault() |
30
|
|
|
{ |
31
|
|
|
$clientId = ClientId::create('CLIENT_ID'); |
32
|
|
|
$commandParameters = DataBag::create([]); |
33
|
|
|
$rule = new Rule\ClientIdIssuedAtRule(); |
34
|
|
|
$validatedParameters = $rule->handle($clientId, $commandParameters, DataBag::create([]), $this->getCallable()); |
35
|
|
|
|
36
|
|
|
self::assertTrue($validatedParameters->has('client_id_issued_at')); |
37
|
|
|
self::assertInternalType('integer', $validatedParameters->get('client_id_issued_at')); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @test |
42
|
|
|
*/ |
43
|
|
|
public function testClientIdIssuedAtRuleDefineInParameters() |
44
|
|
|
{ |
45
|
|
|
$clientId = ClientId::create('CLIENT_ID'); |
46
|
|
|
$commandParameters = DataBag::create([ |
47
|
|
|
'client_id_issued_at' => time() - 1000, |
48
|
|
|
]); |
49
|
|
|
$rule = new Rule\ClientIdIssuedAtRule(); |
50
|
|
|
$validatedParameters = $rule->handle($clientId, $commandParameters, DataBag::create([]), $this->getCallable()); |
51
|
|
|
|
52
|
|
|
self::assertTrue($validatedParameters->has('client_id_issued_at')); |
53
|
|
|
self::assertInternalType('integer', $validatedParameters->get('client_id_issued_at')); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* @return callable |
58
|
|
|
*/ |
59
|
|
|
private function getCallable(): callable |
60
|
|
|
{ |
61
|
|
|
return function (ClientId $clientId, DataBag $commandParameters, DataBag $validatedParameters): DataBag { |
62
|
|
|
return $validatedParameters; |
63
|
|
|
}; |
64
|
|
|
} |
65
|
|
|
} |
66
|
|
|
|