1
|
|
|
<?php |
2
|
|
|
declare(strict_types=1); |
3
|
|
|
|
4
|
|
|
namespace ApiClients\Tools\ResourceTestUtilities; |
5
|
|
|
|
6
|
|
|
use ApiClients\Foundation\Hydrator\Factory; |
7
|
|
|
use ApiClients\Foundation\Hydrator\Options; |
8
|
|
|
use ApiClients\Tools\CommandBus\CommandBus; |
9
|
|
|
use ApiClients\Tools\CommandBus\CommandBusInterface; |
10
|
|
|
use ApiClients\Tools\TestUtilities\TestCase as BaseTestCase; |
11
|
|
|
use League\Tactician\Handler\CommandHandlerMiddleware; |
12
|
|
|
use League\Tactician\Handler\CommandNameExtractor\ClassNameExtractor; |
13
|
|
|
use League\Tactician\Handler\Locator\InMemoryLocator; |
14
|
|
|
use League\Tactician\Handler\MethodNameInflector\HandleInflector; |
15
|
|
|
use React\EventLoop\Factory as LoopFactory; |
16
|
|
|
use React\EventLoop\LoopInterface; |
17
|
|
|
|
18
|
|
|
abstract class TestCase extends BaseTestCase |
19
|
|
|
{ |
20
|
|
|
public function hydrate($class, $json, $namespace, $namespaceSuffix) |
21
|
|
|
{ |
22
|
|
|
$loop = LoopFactory::create(); |
23
|
|
|
$commandBus = $this->createCommandBus($loop); |
24
|
|
|
|
25
|
|
|
return Factory::create($loop, $commandBus, [ |
26
|
|
|
Options::NAMESPACE => $namespace, |
27
|
|
|
Options::NAMESPACE_SUFFIX => $namespaceSuffix, |
28
|
|
|
Options::RESOURCE_CACHE_DIR => $this->getTmpDir(), |
29
|
|
|
Options::RESOURCE_NAMESPACE => $this->getRandomNameSpace(), |
30
|
|
|
])->hydrateFQCN($class, $json); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
protected function createCommandBus(LoopInterface $loop, array $map = []): CommandBusInterface |
34
|
|
|
{ |
35
|
|
|
$commandHandlerMiddleware = new CommandHandlerMiddleware( |
36
|
|
|
new ClassNameExtractor(), |
37
|
|
|
new InMemoryLocator($map), |
38
|
|
|
new HandleInflector() |
39
|
|
|
); |
40
|
|
|
|
41
|
|
|
return new CommandBus( |
42
|
|
|
$loop, |
43
|
|
|
$commandHandlerMiddleware |
44
|
|
|
); |
45
|
|
|
} |
46
|
|
|
} |
47
|
|
|
|