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); |
|
|
|
|
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()); |
|
|
|
|
52
|
|
|
} |
53
|
|
|
} |
54
|
|
|
|
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: