Completed
Push — master ( bce2bd...fc52ee )
by Douglas
01:38
created

PlaceTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 66
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 8

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 8
dl 0
loc 66
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
B testValidInstructions() 0 31 1
A testInvalidInstructions() 0 14 1
A getInvalidInstructions() 0 11 1
1
<?php
2
/**
3
 * (c) 2018 Douglas Reith.
4
 *
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 */
8
declare(strict_types=1);
9
10
namespace Reith\ToyRobot\Console;
11
12
use PHPUnit\Framework\TestCase;
13
use Symfony\Component\Console\Application;
14
use Symfony\Component\Console\Tester\CommandTester;
15
use Reith\ToyRobot\Infrastructure\Bus\CommandBus;
16
17
class PlaceTest extends TestCase
18
{
19
    public static function testValidInstructions()
20
    {
21
        $application = new Application();
22
        $application->add(new Place());
23
        $command = $application->find('place');
24
        $commandTester = new CommandTester($command);
25
        $busHelper = new BusHelper(new CommandBus([]), new CommandBus([]));
26
        $application->getHelperSet()->set($busHelper);
27
28
        $result = $commandTester->execute([
29
            'command' => $command->getName(),
30
            'X,Y,F' => null,
31
        ]);
32
33
        // Successful exit
34
        self::assertEquals(0, $result);
35
36
        $result = $commandTester->execute([
37
            'command' => $command->getName(),
38
            'X,Y,F' => '0,1',
39
        ]);
40
41
        self::assertEquals(0, $result);
42
43
        $result = $commandTester->execute([
44
            'command' => $command->getName(),
45
            'X,Y,F' => '3,2,S',
46
        ]);
47
48
        self::assertEquals(0, $result);
49
    }
50
51
    /**
52
     * @param string $invalidInstruction
53
     * @dataProvider getInvalidInstructions
54
     * @expectedException \RuntimeException
55
     */
56
    public static function testInvalidInstructions(string $invalidInstruction)
57
    {
58
        $application = new Application();
59
        $application->add(new Place());
60
        $command = $application->find('place');
61
        $commandTester = new CommandTester($command);
62
        $busHelper = new BusHelper(new CommandBus([]), new CommandBus([]));
63
        $application->getHelperSet()->set($busHelper);
64
65
        $result = $commandTester->execute([
0 ignored issues
show
Unused Code introduced by
$result is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
66
            'command' => $command->getName(),
67
            'X,Y,F' => $invalidInstruction,
68
        ]);
69
    }
70
71
    public static function getInvalidInstructions(): array
72
    {
73
        return [
74
            ['5,1'], // out of bounds
75
            ['bar'], // nonsense
76
            ['3,2,T'], // not a direction
77
            ['3,2,South'], // direction is a single letter
78
            ['2, 2'], // spaces are not allowed
79
            ['E,1,1'], // wrong order
80
        ];
81
    }
82
}
83