CreatePlayerCommandTest   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
eloc 13
dl 0
loc 27
ccs 0
cts 15
cp 0
rs 10
c 0
b 0
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A testCreatePlayerWithRole() 0 13 1
A useRoleDataProvider() 0 5 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace App\Tests\Game\Features\Registration\Console;
6
7
use App\Game\Features\Player\Player\Player;
8
use App\Game\Features\Player\Player\Role;
9
use App\Game\Features\Registration\Console\CreatePlayerCommand;
10
use App\Game\Features\Registration\PlayerRegister;
11
use App\Game\Infrastructure\Repository\InMemory\InMemoryPlayerRepository;
12
use Generator;
13
use PHPUnit\Framework\TestCase;
0 ignored issues
show
Bug introduced by
The type PHPUnit\Framework\TestCase 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...
14
use Symfony\Component\Console\Input\ArrayInput;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\Console\Input\ArrayInput 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...
15
use Symfony\Component\Console\Output\NullOutput;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\Console\Output\NullOutput 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...
16
17
/**
18
 * @coversDefaultClass \App\Game\Features\Registration\Console\CreatePlayerCommand
19
 */
20
final class CreatePlayerCommandTest extends TestCase
21
{
22
    /**
23
     * @covers ::execute
24
     *
25
     * @dataProvider useRoleDataProvider
26
     */
27
    public function testCreatePlayerWithRole(array $roleOption, Role $role): void
28
    {
29
        $data = array_merge(['nickname' => 'test', 'password' => '1q2w3e4r'], $roleOption);
30
        $inMemoryPlayerRepository = new InMemoryPlayerRepository();
31
        $command = new CreatePlayerCommand(new PlayerRegister($inMemoryPlayerRepository));
32
        $command->run(new ArrayInput($data), new NullOutput());
33
34
        self::assertCount(1, $inMemoryPlayerRepository->players());
35
36
        $players = $inMemoryPlayerRepository->players();
37
        $player = array_shift($players);
38
        self::assertInstanceOf(Player::class, $player);
39
        self::assertTrue($player->role()->equals($role));
40
    }
41
42
    public function useRoleDataProvider(): Generator
43
    {
44
        yield 'Simple player by default role' => [[], new Role(Role::SIMPLE_PLAYER)];
45
        yield 'Simple player' => [['--role' => Role::SIMPLE_PLAYER], new Role(Role::SIMPLE_PLAYER)];
46
        yield 'Premium player' => [['--role' => Role::PREMIUM_PLAYER], new Role(Role::PREMIUM_PLAYER)];
47
    }
48
}
49