protected function setUp() { $this->object = new Setup(); $this->object->setGate(new Gate()); $this->object->setCommandHandlerLoader(new ClassMapCommandHandlerLoader()); $this->object->setEventListenerLoader(new ClassMapEventListenerLoader()); $this->object->setQueryHandlerLoader(new ClassMapQueryHandlerLoader()); }
public function testInitialize() { $monitor = new MockCommandMonitor(); $configuration = array('default_bus' => 'test-coverage-mock-bus', 'adapters' => array('Malocher\\Cqrs\\Adapter\\ArrayMapAdapter' => array('buses' => array('Malocher\\CqrsTest\\Coverage\\Mock\\Bus\\MockBus' => array('Malocher\\CqrsTest\\Coverage\\Mock\\Command\\MockCommand' => array('alias' => 'Malocher\\CqrsTest\\Coverage\\Mock\\Command\\MockCommandHandler', 'method' => 'handleCommand')), 'Malocher\\CqrsTest\\Coverage\\Mock\\Bus\\MockAnotherBus' => array('Malocher\\CqrsTest\\Coverage\\Mock\\Event\\MockEvent' => array('alias' => 'Malocher\\CqrsTest\\Coverage\\Mock\\Event\\MockEventHandler', 'method' => 'handleEvent')), 'Malocher\\Cqrs\\Bus\\SystemBus' => array('Malocher\\Cqrs\\Command\\InvokeCommandCommand' => $monitor, 'Malocher\\Cqrs\\Event\\CommandInvokedEvent' => $monitor))))); $this->setup->setGate(new Gate()); $this->setup->setCommandHandlerLoader(new ClassMapCommandHandlerLoader()); $this->setup->setEventListenerLoader(new ClassMapEventListenerLoader()); $this->setup->setQueryHandlerLoader(new ClassMapQueryHandlerLoader()); $this->setup->initialize($configuration); $this->assertInstanceOf('Malocher\\Cqrs\\Gate', $this->setup->getGate()); $this->assertInstanceOf('Malocher\\Cqrs\\Command\\CommandHandlerLoaderInterface', $this->setup->getCommandHandlerLoader()); $this->assertInstanceOf('Malocher\\Cqrs\\Event\\EventListenerLoaderInterface', $this->setup->getEventListenerLoader()); $this->assertInstanceOf('Malocher\\Cqrs\\Bus\\BusInterface', $this->setup->getGate()->getBus('test-coverage-mock-bus')); $this->assertInstanceOf('Malocher\\Cqrs\\Bus\\SystemBus', $this->setup->getGate()->getSystemBus()); $mockCommand = new MockCommand(); $this->setup->getGate()->getBus('test-coverage-mock-bus')->invokeCommand($mockCommand); $this->assertTrue($mockCommand->isEdited()); $invokeCommandCommand = $monitor->getInvokeCommandCommands()[0]; $commandInvokedEvent = $monitor->getCommandInvokedEvents()[0]; $this->assertEquals('Malocher\\CqrsTest\\Coverage\\Mock\\Command\\MockCommand', $invokeCommandCommand->getMessageClass()); $this->assertEquals('Malocher\\CqrsTest\\Coverage\\Mock\\Command\\MockCommand', $commandInvokedEvent->getMessageClass()); //test setup multiple buses $mockEvent = new MockEvent(); $this->setup->getGate()->getBus('test-coverage-mock-another-bus')->publishEvent($mockEvent); $this->assertTrue($mockEvent->isEdited()); //Test setup the default bus corectly $this->assertInstanceOf('Malocher\\Cqrs\\Bus\\BusInterface', $this->setup->getGate()->getBus()); }
/** * */ public function __construct() { $setup = new Setup(); $setup->setGate(new Gate()); $setup->setCommandHandlerLoader(new ClassMapCommandHandlerLoader()); $setup->setEventListenerLoader(new ClassMapEventListenerLoader()); $setup->setQueryHandlerLoader(new ClassMapQueryHandlerLoader()); // iteration 5 $configuration = ['adapters' => ['Malocher\\Cqrs\\Adapter\\AnnotationAdapter' => ['buses' => ['Iteration\\Iteration5\\Iteration5Bus' => ['Iteration\\Iteration5\\Iteration5Handler'], 'Malocher\\Cqrs\\Bus\\SystemBus' => ['Iteration\\Iteration5\\Iteration5Monitor']]]]]; $setup->initialize($configuration); $bus = $setup->getGate()->getBus('iteration-iteration5-bus'); $bus->invokeCommand(new Iteration5Command('Hello')); }
/** * * {@inheritDoc} */ public function createService(ServiceLocatorInterface $serviceLocator) { $configuration = $serviceLocator->get('configuration'); if (!isset($configuration['cqrs'])) { throw new \Exception('CQRS config missing'); } $cqrsConfig = $configuration['cqrs']; $gate = new Gate(); $cqrsSetup = new Setup(); $cqrsSetup->setGate($gate); $cqrsSetup->setCommandHandlerLoader($serviceLocator->get('malocher.cqrs.command_handler_loader')); $cqrsSetup->setQueryHandlerLoader($serviceLocator->get('malocher.cqrs.query_handler_loader')); $cqrsSetup->setEventListenerLoader($serviceLocator->get('malocher.cqrs.event_listener_loader')); $cqrsSetup->initialize($cqrsConfig); return $gate; }