|
12 | 12 | use Patchlevel\EventSourcing\Aggregate\CustomId; |
13 | 13 | use Patchlevel\EventSourcing\Clock\FrozenClock; |
14 | 14 | use Patchlevel\EventSourcing\Clock\SystemClock; |
| 15 | +use Patchlevel\EventSourcing\CommandBus\CommandBus; |
15 | 16 | use Patchlevel\EventSourcing\CommandBus\Handler\CreateAggregateHandler; |
16 | 17 | use Patchlevel\EventSourcing\Console\Command\DatabaseCreateCommand; |
17 | 18 | use Patchlevel\EventSourcing\Console\Command\DatabaseDropCommand; |
|
70 | 71 | use Patchlevel\EventSourcing\Subscription\Store\SubscriptionStore; |
71 | 72 | use Patchlevel\EventSourcing\Subscription\Subscriber\MetadataSubscriberAccessorRepository; |
72 | 73 | use Patchlevel\EventSourcingBundle\Command\StoreMigrateCommand; |
| 74 | +use Patchlevel\EventSourcingBundle\CommandBus\SymfonyCommandBus; |
73 | 75 | use Patchlevel\EventSourcingBundle\DependencyInjection\PatchlevelEventSourcingExtension; |
74 | 76 | use Patchlevel\EventSourcingBundle\EventBus\SymfonyEventBus; |
75 | 77 | use Patchlevel\EventSourcingBundle\PatchlevelEventSourcingBundle; |
@@ -547,6 +549,69 @@ public function testCommandHandler(): void |
547 | 549 | self::assertEquals('command.bus', $tag['bus']); |
548 | 550 | } |
549 | 551 |
|
| 552 | + public function testCommandBusAndLegacyConfigurationNotAllowed(): void |
| 553 | + { |
| 554 | + $container = new ContainerBuilder(); |
| 555 | + |
| 556 | + $this->expectException(InvalidArgumentException::class); |
| 557 | + $this->expectExceptionMessage('Remove legacy aggregate_handlers configuration when using command_bus'); |
| 558 | + |
| 559 | + $this->compileContainer( |
| 560 | + $container, |
| 561 | + [ |
| 562 | + 'patchlevel_event_sourcing' => [ |
| 563 | + 'connection' => [ |
| 564 | + 'service' => 'doctrine.dbal.eventstore_connection', |
| 565 | + ], |
| 566 | + 'aggregates' => [__DIR__ . '/../Fixtures'], |
| 567 | + 'aggregate_handlers' => [ |
| 568 | + 'bus' => 'command.bus', |
| 569 | + ], |
| 570 | + 'command_bus' => [ |
| 571 | + 'service' => 'command.bus', |
| 572 | + ], |
| 573 | + ], |
| 574 | + ] |
| 575 | + ); |
| 576 | + } |
| 577 | + |
| 578 | + public function testCommandBus(): void |
| 579 | + { |
| 580 | + $container = new ContainerBuilder(); |
| 581 | + |
| 582 | + $this->compileContainer( |
| 583 | + $container, |
| 584 | + [ |
| 585 | + 'patchlevel_event_sourcing' => [ |
| 586 | + 'connection' => [ |
| 587 | + 'service' => 'doctrine.dbal.eventstore_connection', |
| 588 | + ], |
| 589 | + 'aggregates' => [__DIR__ . '/../Fixtures'], |
| 590 | + 'command_bus' => [ |
| 591 | + 'service' => 'command.bus', |
| 592 | + ], |
| 593 | + ], |
| 594 | + ] |
| 595 | + ); |
| 596 | + |
| 597 | + $handler = $container->get('event_sourcing.handler.profile.create'); |
| 598 | + |
| 599 | + self::assertInstanceOf(CreateAggregateHandler::class, $handler); |
| 600 | + |
| 601 | + $handler(new CreateProfile(CustomId::fromString('1'))); |
| 602 | + |
| 603 | + $definition = $container->getDefinition('event_sourcing.handler.profile.create'); |
| 604 | + $tags = $definition->getTag('messenger.message_handler'); |
| 605 | + |
| 606 | + self::assertCount(1, $tags); |
| 607 | + |
| 608 | + $tag = $tags[0]; |
| 609 | + |
| 610 | + self::assertEquals(CreateProfile::class, $tag['handles']); |
| 611 | + self::assertEquals('command.bus', $tag['bus']); |
| 612 | + self::assertInstanceOf(SymfonyCommandBus::class, $container->get(CommandBus::class)); |
| 613 | + } |
| 614 | + |
550 | 615 | public function testSnapshotStore(): void |
551 | 616 | { |
552 | 617 | $container = new ContainerBuilder(); |
@@ -1222,6 +1287,7 @@ private function compileContainer(ContainerBuilder $container, array $config): v |
1222 | 1287 |
|
1223 | 1288 | $container->set('doctrine.dbal.eventstore_connection', $this->prophesize(Connection::class)->reveal()); |
1224 | 1289 | $container->set('event.bus', $this->prophesize(MessageBusInterface::class)->reveal()); |
| 1290 | + $container->set('command.bus', $this->prophesize(MessageBusInterface::class)->reveal()); |
1225 | 1291 | $container->set('cache.default', $this->prophesize(CacheItemPoolInterface::class)->reveal()); |
1226 | 1292 | $container->set('event_dispatcher', $this->prophesize(EventDispatcherInterface::class)->reveal()); |
1227 | 1293 | $container->set('services_resetter', $this->prophesize(ServicesResetter::class)->reveal()); |
|
0 commit comments