RobotPlacerTest   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Importance

Changes 0
Metric Value
wmc 1
lcom 1
cbo 6
dl 0
loc 35
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A willHandlePlaceRobot() 0 29 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\CommandHandler;
11
12
use PHPUnit\Framework\TestCase;
13
use Psr\Log\LoggerInterface;
14
use Reith\ToyRobot\Messaging\Command\PlaceRobot;
15
use Reith\ToyRobot\Domain\Space\Table;
16
use Reith\ToyRobot\Domain\Robot\RobotRepositoryInterface;
17
use Reith\ToyRobot\Domain\Robot\Robot;
18
19
class RobotPlacerTest extends TestCase
20
{
21
    /**
22
     * @test
23
     */
24
    public function willHandlePlaceRobot()
25
    {
26
        $table = Table::create(10);
27
        $mockRepo = self::createMock(RobotRepositoryInterface::class);
28
        $mockLogger = self::createMock(LoggerInterface::class);
29
        $robotPlacer = new RobotPlacer($table, $mockRepo, $mockLogger);
0 ignored issues
show
Documentation introduced by
$mockRepo is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Reith\ToyRobot\Do...botRepositoryInterface>.

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...
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...
30
31
        self::assertInstanceOf(RobotPlacer::class, $robotPlacer);
32
33
        $command = new PlaceRobot([1, 4], 'W');
34
35
        $localRobot = null;
36
37
        $mockRepo->expects($this->once())
38
            ->method('save')
39
            ->with(
40
                $this->callback(function (Robot $robot) use (&$localRobot) {
41
                    $localRobot = $robot;
42
43
                    return true;
44
                })
45
            );
46
47
        $robotPlacer->handlePlaceRobot($command);
48
49
        self::assertInstanceOf(Robot::class, $localRobot);
50
51
        self::assertSame('1,4,W', $localRobot->getReportAsString());
0 ignored issues
show
Bug introduced by
The method getReportAsString cannot be called on $localRobot (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
52
    }
53
}
54