Esempio n. 1
0
 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());
 }
Esempio n. 2
0
 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());
 }
Esempio n. 3
0
 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);
 }
Esempio n. 4
0
 /**
  *
  */
 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'));
 }