Passed
Push — master ( 35eebd...7b8a1a )
by Roman
16:45
created

testIncreaseLevelWneAllAnswersIsCorrect()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 22
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 15
nc 1
nop 0
dl 0
loc 22
ccs 0
cts 16
cp 0
crap 2
rs 9.7666
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace App\Tests\Game\Features\Answers;
6
7
use App\Game\Features\Answers\Answers;
8
use App\Game\Features\Answers\AnswersValidator;
9
use App\Game\Features\Answers\Authentication\PlayerFromTokenExtractor;
10
use App\Game\Features\Answers\CrosswordPuzzleSolvedEvent;
11
use App\Game\Features\Answers\Player\PlayerId as AnswersPlayerId;
12
use App\Game\Features\Player\Player\PlayerId as PlayerPlayerId;
13
use App\Game\Features\Player\Player\Role;
14
use App\Game\Infrastructure\Encoder\Base64Encoder;
15
use App\Game\Infrastructure\Repository\InMemory\InMemoryPlayerRepository;
16
use App\Tests\Game\GameTestCase;
17
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\Securi...e\TokenStorageInterface was not found. Maybe you did not declare it correctly or list all dependencies?

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:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
18
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\Securi...on\Token\TokenInterface was not found. Maybe you did not declare it correctly or list all dependencies?

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:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
19
20
/**
21
 * @coversDefaultClass \App\Game\Features\Answers\Answers
22
 */
23
final class AnswersTest extends GameTestCase
24
{
25
    /**
26
     * @covers ::__invoke
27
     */
28
    public function testIncreaseLevelWneAllAnswersIsCorrect(): void
29
    {
30
        $playerId = new PlayerPlayerId();
31
        $repository = new InMemoryPlayerRepository($this->createPlayer($playerId));
32
        $answers = new Answers(
33
            new AnswersValidator(new Base64Encoder()),
34
            $this->createPlayerFromTokenExtractor($playerId),
35
            $this->messageBusMockWithConsecutive(
36
                self::once(),
37
                new CrosswordPuzzleSolvedEvent(new AnswersPlayerId($playerId->id()), 4)
38
            )
39
        );
40
41
        $encoder = new Base64Encoder();
42
        $answers->__invoke([
43
            ['index' => 0, 'letter' => $encoder->encode('t'), 'value' => 't'],
44
            ['index' => 1, 'letter' => $encoder->encode('e'), 'value' => 'e'],
45
            ['index' => 2, 'letter' => $encoder->encode('s'), 'value' => 's'],
46
            ['index' => 3, 'letter' => $encoder->encode('t'), 'value' => 't'],
47
        ]);
48
49
        $repository->findPlayerById($playerId->id());
50
    }
51
52
    private function createPlayerFromTokenExtractor(PlayerPlayerId $playerId): PlayerFromTokenExtractor
53
    {
54
        $player['id'] = (string) $playerId;
0 ignored issues
show
Comprehensibility Best Practice introduced by
$player was never initialized. Although not strictly required by PHP, it is generally a good practice to add $player = array(); before regardless.
Loading history...
55
        $player['nickname'] = 'test';
56
        $player['level'] = 3;
57
        $player['role'] = (new Role(Role::SIMPLE_PLAYER))->getValue();
58
59
        $tokenMock = $this->createMock(TokenInterface::class);
60
        $tokenMock->method('getUser')->willReturn(json_encode($player, JSON_THROW_ON_ERROR));
61
62
        $tokenStorageMock = $this->createMock(TokenStorageInterface::class);
63
        $tokenStorageMock->method('getToken')->willReturn($tokenMock);
64
65
        return new PlayerFromTokenExtractor($tokenStorageMock);
66
    }
67
}
68