/
ApplicationTestCase.php
76 lines (62 loc) · 2 KB
/
ApplicationTestCase.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<?php
declare(strict_types=1);
namespace App\Tests\Application\Command;
use League\Tactician\CommandBus;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Event\PostResponseEvent;
use Symfony\Component\HttpKernel\KernelEvents;
abstract class ApplicationTestCase extends KernelTestCase
{
protected function ask($query)
{
return $this->queryBus->handle($query);
}
protected function handle($command): void
{
$this->commandBus->handle($command);
}
protected function service(string $serviceId)
{
return $this->container->get($serviceId);
}
protected function fireTerminateEvent(): void
{
/** @var EventDispatcherInterface $dispatcher */
$dispatcher = $this->service('event_dispatcher');
$dispatcher->dispatch(
KernelEvents::TERMINATE,
new PostResponseEvent(
static::$kernel,
Request::create('/'),
Response::create()
)
);
}
protected function setUp()
{
static::bootKernel();
$this->container = static::$kernel->getContainer();
/** @var CommandBus $commandBus */
$commandBus = $this->container->get('tactician.commandbus.command');
$this->commandBus = $commandBus;
/** @var CommandBus $queryBus */
$queryBus = $this->container->get('tactician.commandbus.query');
$this->queryBus = $queryBus;
}
protected function tearDown()
{
$this->container = null;
$this->commandBus = null;
$this->queryBus = null;
}
/** @var ContainerInterface|null */
private $container;
/** @var CommandBus|null */
private $commandBus;
/** @var CommandBus|null */
private $queryBus;
}