Failed Conditions
Push — ng ( 870bee...532144 )
by Florent
04:07
created

iCanCreateAnAccessTokenUsingTheCommandHandler()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 26
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 26
rs 8.8571
c 0
b 0
f 0
cc 1
eloc 16
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\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');
0 ignored issues
show
Comprehensibility Naming introduced by
The variable name $accessTokenRepository exceeds the maximum configured length of 20.

Very long variable names usually make code harder to read. It is therefore recommended not to make variable names too verbose.

Loading history...
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