GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Passed
Branch master (f137da)
by Dmitri
01:44
created

TokenUserProviderTest   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 72
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 72
rs 10
c 0
b 0
f 0
wmc 6
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Damax\Bundle\ApiAuthBundle\Tests\Security\ApiKey;
6
7
use Damax\Bundle\ApiAuthBundle\Security\ApiKey\InvalidApiKeyException;
8
use Damax\Bundle\ApiAuthBundle\Security\ApiKey\TokenUserProvider;
9
use Damax\Bundle\ApiAuthBundle\Security\ApiUser;
10
use PHPUnit\Framework\TestCase;
11
use Symfony\Component\Security\Core\Exception\UnsupportedUserException;
12
use Symfony\Component\Security\Core\User\User as SecurityUser;
13
14
class TokenUserProviderTest extends TestCase
15
{
16
    /**
17
     * @var TokenUserProvider
18
     */
19
    private $userProvider;
20
21
    protected function setUp()
22
    {
23
        $this->userProvider = new TokenUserProvider(['foo' => 'ABC', 'bar' => 'XYZ']);
24
    }
25
26
    /**
27
     * @test
28
     */
29
    public function it_supports_class()
30
    {
31
        $this->assertTrue($this->userProvider->supportsClass(ApiUser::class));
32
        $this->assertFalse($this->userProvider->supportsClass(SecurityUser::class));
33
    }
34
35
    /**
36
     * @test
37
     */
38
    public function it_loads_user()
39
    {
40
        $user = $this->userProvider->loadUserByUsername('foo');
41
42
        $this->assertInstanceOf(ApiUser::class, $user);
43
        $this->assertEquals('foo', $user->getUsername());
44
45
        $user = $this->userProvider->loadUserByUsername('bar');
46
47
        $this->assertInstanceOf(ApiUser::class, $user);
48
        $this->assertEquals('bar', $user->getUsername());
49
    }
50
51
    /**
52
     * @test
53
     */
54
    public function it_loads_user_by_api_key()
55
    {
56
        $user = $this->userProvider->loadUserByApiKey('ABC');
57
58
        $this->assertInstanceOf(ApiUser::class, $user);
59
        $this->assertEquals('foo', $user->getUsername());
60
61
        $user = $this->userProvider->loadUserByApiKey('XYZ');
62
63
        $this->assertInstanceOf(ApiUser::class, $user);
64
        $this->assertEquals('bar', $user->getUsername());
65
    }
66
67
    /**
68
     * @test
69
     */
70
    public function it_throws_exception_when_loading_user_with_unregistered_api_key()
71
    {
72
        $this->expectException(InvalidApiKeyException::class);
73
74
        $this->userProvider->loadUserByApiKey('123');
75
    }
76
77
    /**
78
     * @test
79
     */
80
    public function it_throws_exception_on_refreshing_user()
81
    {
82
        $this->expectException(UnsupportedUserException::class);
83
        $this->expectExceptionMessage('Provider "Damax\Bundle\ApiAuthBundle\Security\ApiKey\TokenUserProvider" must be configured as stateless.');
84
85
        $this->userProvider->refreshUser(new ApiUser('foo'));
86
    }
87
}
88