HandlerWrapperTest   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 5
dl 0
loc 30
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A willFindAnnotatedMethods() 0 14 1
A handlerMustHaveMethods() 0 5 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\Infrastructure\Bus;
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\CommandHandler\RobotPlacer;
18
19
class HandlerWrapperTest extends TestCase
20
{
21
    /**
22
     * @test
23
     */
24
    public function willFindAnnotatedMethods()
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
        $wrapper = new HandlerWrapper($robotPlacer);
32
33
        $command = new PlaceRobot([0, 1], 'N');
34
        $callable = $wrapper->getCallable($command);
35
36
        self::assertTrue(is_callable($callable));
37
    }
38
39
    /**
40
     * @test
41
     * @expectedException \Assert\AssertionFailedException
42
     */
43
    public static function handlerMustHaveMethods()
44
    {
45
        $badHandler = new \stdClass();
46
        new HandlerWrapper($badHandler);
47
    }
48
}
49