public function testInitializeEvent() { $configuration = array('adapters' => array('Malocher\\Cqrs\\Adapter\\ArrayMapAdapter' => array('buses' => array('Malocher\\CqrsTest\\Integration\\Integration4\\Integration4Bus' => array('Malocher\\CqrsTest\\Integration\\Integration4\\Integration4Event' => function (Integration4Event $event) { $event->edit(); }))))); $this->object->initialize($configuration); $mockEvent = new Integration4Event(); $this->object->getGate()->getBus('test-integration-Integration4-bus')->publishEvent($mockEvent); //The EventListenerCallback should call $mockEvent->edit(), otherwise //$mockEvent->isEdited() returns false $this->assertTrue($mockEvent->isEdited()); }
public function testInitialize() { $configuration = array('adapters' => array('Malocher\\Cqrs\\Adapter\\AnnotationAdapter' => array('buses' => array('Malocher\\CqrsTest\\Integration\\Integration5\\Integration5Bus' => array('Malocher\\CqrsTest\\Integration\\Integration5\\Integration5Handler'))))); $this->object->initialize($configuration); $bus = $this->object->getGate()->getBus('test-integration-Integration5-bus'); $mockCommand = new Integration5Command(); $mockCommand->callback = function ($isEdited) { $this->assertTrue($isEdited); }; $mockEvent = new Integration5Event(); $mockEvent->callback = function ($isEdited) { $this->assertTrue($isEdited); }; $bus->invokeCommand($mockCommand); $bus->publishEvent($mockEvent); }
public function testInitializeWithoutQuerytHandlerLoader() { $this->setExpectedException('Malocher\\Cqrs\\Configuration\\ConfigurationException'); $configuration = array('enable_system_bus' => true, 'adapters' => array('Malocher\\Cqrs\\Adapter\\ArrayMapAdapter' => array('buses' => array('Malocher\\CqrsTest\\Coverage\\Mock\\Bus\\MockBus' => array('Malocher\\CqrsTest\\Coverage\\Mock\\Query\\MockQuery' => array('alias' => 'Malocher\\CqrsTest\\Coverage\\Mock\\Query\\MockQueryHandler', 'method' => 'handleQuery')))))); $this->setup->setGate(new Gate()); $this->setup->setCommandHandlerLoader(new ClassMapCommandHandlerLoader()); $this->setup->setEventListenerLoader(new ClassMapEventListenerLoader()); $this->setup->initialize($configuration); }
/** * */ 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; }