Completed
Push — master ( 7d6afc...af3c22 )
by Douglas
02:06
created

toyrobotTest::testToyrobotApp()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 11
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 6
nc 1
nop 0
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
use PHPUnit\Framework\TestCase;
11
use Psr\Log\LoggerInterface;
12
use org\bovigo\vfs\vfsStream;
13
use Symfony\Component\Console\Application;
14
use Symfony\Component\Console\Tester\ApplicationTester;
15
use Reith\ToyRobot\Domain\Space\Table;
16
// Persistence
17
use Reith\ToyRobot\Infrastructure\Persistence\FileRobotStore;
18
use Reith\ToyRobot\Infrastructure\Persistence\RobotRepository;
19
// Console tasks
20
use Reith\ToyRobot\Console\Place;
21
use Reith\ToyRobot\Console\BusHelper;
22
// Buses
23
use Reith\ToyRobot\Infrastructure\Bus\CommandBus;
24
// Command and query handlers
25
use Reith\ToyRobot\CommandHandler\RobotPlacer;
26
27
class toyrobotTest extends TestCase
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
28
{
29
    private $testApp;
30
31
    protected function setUp()
32
    {
33
        $basePath = vfsStream::setup('basePath');
0 ignored issues
show
Unused Code introduced by
$basePath 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...
34
35
        $store = FileRobotStore::getStore(vfsStream::url('basePath'));
36
37
        // Pass to the repository
38
        $repository = new RobotRepository($store);
39
        $table = Table::create(5);
40
41
        $mockLogger = self::createMock(LoggerInterface::class);
42
43
        // Create the command and query handlers
44
        $robotPlacer = new RobotPlacer($table, $repository, $mockLogger);
0 ignored issues
show
Documentation introduced by
$mockLogger is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Psr\Log\LoggerInterface>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
45
46
        // Now the buses
47
        $commandBus = (new CommandBus())
48
            ->registerHandler($robotPlacer)
49
        ;
50
51
        // Set up the console
52
        $application = new Application();
53
        $application->setAutoExit(false);
54
        $application->add(new Place());
55
56
        $busHelper = (new BusHelper())
57
            ->setCommandBus($commandBus)
58
        ;
59
        $application->getHelperSet()->set($busHelper);
60
61
        $this->testApp = new ApplicationTester($application);
62
    }
63
64
    public function testToyrobotApp()
65
    {
66
        $this->testApp->run([]);
67
68
        self::assertContains(
69
            'Place the robot on the table',
70
            $this->testApp->getDisplay()
71
        );
72
73
        self::assertSame(0, $this->testApp->getStatusCode());
74
    }
75
76
    public function testPlaceRobot()
77
    {
78
        $this->testApp->run(['place']);
79
80
        self::assertSame(0, $this->testApp->getStatusCode());
81
    }
82
}
83