1
|
|
|
<?php declare(strict_types = 1); |
2
|
|
|
|
3
|
|
|
namespace TomCizek\SymfonyProoph\Tests\AsynchronousMessages; |
4
|
|
|
|
5
|
|
|
use TomCizek\SymfonyProoph\Tests\AsynchronousMessages\FakeImplementations\TestAsynchronousMessageProducerBridge; |
6
|
|
|
use TomCizek\SymfonyProoph\Tests\EventSourcing\FakeImplementations\MemoryTestRepository; |
7
|
|
|
use TomCizek\SymfonyProoph\Tests\EventSourcing\FakeImplementations\TestAggregateRoot; |
8
|
|
|
|
9
|
|
|
class AsynchronousMessagesExampleIntegrationTest extends AbstractAsynchronousMessagesTestCase |
10
|
|
|
{ |
11
|
|
|
const FIXTURE_CONFIG_FILE = 'FullTestConfig.yml'; |
12
|
|
|
const TEST_PRODUCER_ROUTE_KEY = 'producerRouteKey'; |
13
|
|
|
|
14
|
|
|
public function testInvoke_WithTestConfig_BySavingNewAggregateToRepostory_ShouldPublishExpectedMessageToExpectedProducerRouteKey( |
15
|
|
|
) |
16
|
|
|
{ |
17
|
|
|
$this->givenContainerWithLoadedBundlesWithGivenConfig(self::FIXTURE_CONFIG_FILE); |
18
|
|
|
|
19
|
|
|
$repository = $this->givenTestRepository(); |
20
|
|
|
$aggregate = $this->givenTestAggregate(); |
21
|
|
|
|
22
|
|
|
$this->whenAggregateSaved($repository, $aggregate); |
23
|
|
|
|
24
|
|
|
$this->thenShouldPublishExpectedMessageToExpectedProducerRouteKey(self::TEST_PRODUCER_ROUTE_KEY); |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
private function givenTestRepository(): MemoryTestRepository |
28
|
|
|
{ |
29
|
|
|
/** @var MemoryTestRepository $repository */ |
30
|
|
|
$repository = $this->container->get(MemoryTestRepository::class); |
31
|
|
|
|
32
|
|
|
return $repository; |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
private function givenTestAggregate(): TestAggregateRoot |
36
|
|
|
{ |
37
|
|
|
return TestAggregateRoot::create(); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
private function whenAggregateSaved(MemoryTestRepository $repository, TestAggregateRoot $aggregate): void |
41
|
|
|
{ |
42
|
|
|
$repository->save($aggregate); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
protected function getPublishedEventsFromTestBridge(): array |
46
|
|
|
{ |
47
|
|
|
/** @var TestAsynchronousMessageProducerBridge $testProducerBridge */ |
48
|
|
|
$testProducerBridge = $this->container->get(TestAsynchronousMessageProducerBridge::class); |
49
|
|
|
|
50
|
|
|
return $testProducerBridge->getPublished(); |
51
|
|
|
} |
52
|
|
|
} |
53
|
|
|
|