1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace App\Tests\Game\Features\Answers\Authentication; |
6
|
|
|
|
7
|
|
|
use App\Game\Features\Answers\Authentication\PlayerFromTokenExtractor; |
8
|
|
|
use App\Game\Features\Answers\Authentication\PlayerNotFoundInTokenStorageException; |
9
|
|
|
use App\Game\Features\Answers\Player\PlayerDto; |
10
|
|
|
use App\Game\Features\Player\Player\PlayerId; |
11
|
|
|
use App\Tests\Game\GameTestCase; |
12
|
|
|
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface; |
|
|
|
|
13
|
|
|
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface; |
|
|
|
|
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* @coversDefaultClass \App\Game\Features\Answers\Authentication\PlayerFromTokenExtractor |
17
|
|
|
*/ |
18
|
|
|
final class PlayerFromTokenExtractorTest extends GameTestCase |
19
|
|
|
{ |
20
|
|
|
/** |
21
|
|
|
* @covers ::player |
22
|
|
|
*/ |
23
|
|
|
public function testExtractPlayerFromTokenStorage(): void |
24
|
|
|
{ |
25
|
|
|
$player = $this->createPlayer(new PlayerId()); |
26
|
|
|
|
27
|
|
|
$playerArray['id'] = (string) $player->playerId(); |
|
|
|
|
28
|
|
|
$playerArray['nickname'] = $player->nickname(); |
29
|
|
|
$playerArray['level'] = $player->level(); |
30
|
|
|
$playerArray['role'] = $player->role()->getValue(); |
31
|
|
|
|
32
|
|
|
$tokenMock = $this->createMock(TokenInterface::class); |
33
|
|
|
$tokenMock->method('getUser')->willReturn(json_encode($playerArray, JSON_THROW_ON_ERROR)); |
34
|
|
|
|
35
|
|
|
$tokenStorageMock = $this->createMock(TokenStorageInterface::class); |
36
|
|
|
$tokenStorageMock->method('getToken')->willReturn($tokenMock); |
37
|
|
|
|
38
|
|
|
$playerFromTokenExtractor = new PlayerFromTokenExtractor($tokenStorageMock); |
39
|
|
|
|
40
|
|
|
self::assertInstanceOf(PlayerDto::class, $playerFromTokenExtractor->player()); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @covers ::player |
45
|
|
|
*/ |
46
|
|
|
public function testRaiseExceptionWhenTokenIsNull(): void |
47
|
|
|
{ |
48
|
|
|
$this->expectException(PlayerNotFoundInTokenStorageException::class); |
49
|
|
|
|
50
|
|
|
$tokenStorageMock = $this->createMock(TokenStorageInterface::class); |
51
|
|
|
$tokenStorageMock->method('getToken')->willReturn(null); |
52
|
|
|
|
53
|
|
|
$playerFromTokenExtractor = new PlayerFromTokenExtractor($tokenStorageMock); |
54
|
|
|
$playerFromTokenExtractor->player(); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @covers ::player |
59
|
|
|
*/ |
60
|
|
|
public function testRaiseExceptionWhenPlayerIsNotDecoded(): void |
61
|
|
|
{ |
62
|
|
|
$this->expectException(PlayerNotFoundInTokenStorageException::class); |
63
|
|
|
|
64
|
|
|
$tokenMock = $this->createMock(TokenInterface::class); |
65
|
|
|
$tokenMock->method('getUser')->willReturn('', JSON_THROW_ON_ERROR); |
66
|
|
|
|
67
|
|
|
$tokenStorageMock = $this->createMock(TokenStorageInterface::class); |
68
|
|
|
$tokenStorageMock->method('getToken')->willReturn($tokenMock); |
69
|
|
|
|
70
|
|
|
$playerFromTokenExtractor = new PlayerFromTokenExtractor($tokenStorageMock); |
71
|
|
|
$playerFromTokenExtractor->player(); |
72
|
|
|
} |
73
|
|
|
} |
74
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths