|
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 |
|
|
|
|
|
|
28
|
|
|
{ |
|
29
|
|
|
private $testApp; |
|
30
|
|
|
|
|
31
|
|
|
protected function setUp() |
|
32
|
|
|
{ |
|
33
|
|
|
$basePath = vfsStream::setup('basePath'); |
|
|
|
|
|
|
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); |
|
|
|
|
|
|
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
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.