|
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\Bundle\Tests\Functional\Core\AccessToken; |
|
15
|
|
|
|
|
16
|
|
|
use OAuth2Framework\Component\Core\AccessToken\AccessToken; |
|
17
|
|
|
use OAuth2Framework\Component\Core\AccessToken\AccessTokenId; |
|
18
|
|
|
use OAuth2Framework\Component\Core\AccessToken\AccessTokenRepository; |
|
19
|
|
|
use OAuth2Framework\Component\Core\AccessToken\Command; |
|
20
|
|
|
use OAuth2Framework\Component\Core\Client\ClientId; |
|
21
|
|
|
use OAuth2Framework\Component\Core\DataBag\DataBag; |
|
22
|
|
|
use OAuth2Framework\Component\Core\ResourceServer\ResourceServerId; |
|
23
|
|
|
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* @group Bundle |
|
27
|
|
|
* @group Functional |
|
28
|
|
|
* @group Core |
|
29
|
|
|
*/ |
|
30
|
|
|
class CommandTest extends WebTestCase |
|
31
|
|
|
{ |
|
32
|
|
|
/** |
|
33
|
|
|
* {@inheritdoc} |
|
34
|
|
|
*/ |
|
35
|
|
|
protected function setUp() |
|
36
|
|
|
{ |
|
37
|
|
|
if (!interface_exists(AccessTokenRepository::class)) { |
|
38
|
|
|
$this->markTestSkipped('The component "oauth-framework/core" is not installed.'); |
|
39
|
|
|
} |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* @test |
|
44
|
|
|
*/ |
|
45
|
|
|
public function theCreateAccessTokenCommandHandlerIsAvailable() |
|
46
|
|
|
{ |
|
47
|
|
|
$client = static::createClient(); |
|
48
|
|
|
$container = $client->getContainer(); |
|
49
|
|
|
self::assertTrue($container->has(Command\CreateAccessTokenCommandHandler::class)); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* @test |
|
54
|
|
|
* @depends theCreateAccessTokenCommandHandlerIsAvailable |
|
55
|
|
|
*/ |
|
56
|
|
|
public function iCanCreateAnAccessTokenUsingTheCommandHandler() |
|
57
|
|
|
{ |
|
58
|
|
|
$client = static::createClient(); |
|
59
|
|
|
$container = $client->getContainer(); |
|
60
|
|
|
|
|
61
|
|
|
/** @var Command\CreateAccessTokenCommandHandler $handler */ |
|
62
|
|
|
$handler = $container->get(Command\CreateAccessTokenCommandHandler::class); |
|
63
|
|
|
|
|
64
|
|
|
$command = Command\CreateAccessTokenCommand::create( |
|
65
|
|
|
AccessTokenId::create('ACCESS_TOKEN_CREATED_USING_A_COMMAND'), |
|
66
|
|
|
ClientId::create('CLIENT_ID'), |
|
67
|
|
|
ClientId::create('CLIENT_ID'), |
|
68
|
|
|
new \DateTimeImmutable('now +1 hour'), |
|
69
|
|
|
DataBag::create([]), |
|
70
|
|
|
DataBag::create([]), |
|
71
|
|
|
ResourceServerId::create('RESOURCE_SERVER_ID') |
|
72
|
|
|
); |
|
73
|
|
|
$handler->handle($command); |
|
74
|
|
|
|
|
75
|
|
|
/** @var AccessTokenRepository $accessTokenRepository */ |
|
76
|
|
|
$accessTokenRepository = $container->get('MyAccessTokenRepository'); |
|
|
|
|
|
|
77
|
|
|
|
|
78
|
|
|
$accessToken = $accessTokenRepository->find(AccessTokenId::create('ACCESS_TOKEN_CREATED_USING_A_COMMAND')); |
|
79
|
|
|
|
|
80
|
|
|
self::assertInstanceOf(AccessToken::class, $accessToken); |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
/** |
|
84
|
|
|
* @test |
|
85
|
|
|
*/ |
|
86
|
|
|
public function theRevokeAccessTokenCommandHandlerIsAvailable() |
|
87
|
|
|
{ |
|
88
|
|
|
$client = static::createClient(); |
|
89
|
|
|
$container = $client->getContainer(); |
|
90
|
|
|
self::assertTrue($container->has(Command\RevokeAccessTokenCommandHandler::class)); |
|
91
|
|
|
} |
|
92
|
|
|
} |
|
93
|
|
|
|
Very long variable names usually make code harder to read. It is therefore recommended not to make variable names too verbose.