Exemple #1
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());
 }