Exemplo n.º 1
0
 /**
  *
  */
 public function __construct()
 {
     // The gate manages the bus system
     $this->gate = new Gate();
     // Create a bus and attach it to the gate
     $this->bus = new Iteration2Bus();
     $this->bus->setCommandHandlerLoader(new ClassMapCommandHandlerLoader());
     $this->bus->setEventListenerLoader(new ClassMapEventListenerLoader());
     $this->bus->setQueryHandlerLoader(new ClassMapQueryHandlerLoader());
     $this->gate->attach($this->bus);
     // Map a command to a handler
     $this->bus->mapCommand('Iteration\\Iteration2\\Iteration2Command', function (Iteration2Command $command) {
         $command->edit();
         print sprintf("%s says: %s ... Command\n", __METHOD__, $command->getPayload());
         $event = new Iteration2Event('Hello');
         $event->edit();
         $this->bus->publishEvent($event);
     });
     // Register a event to a handler
     $this->bus->registerEventListener('Iteration\\Iteration2\\Iteration2Event', function (Iteration2Event $event) {
         $event->edit();
         print sprintf("%s says: %s ... Event\n", __METHOD__, $event->getPayload());
     });
     // Send a command to the bus
     // Iteration1Handler::editCommand is mapped against this command and will be called
     $this->bus->invokeCommand(new Iteration2Command('Hello'));
 }
Exemplo n.º 2
0
 /**
  *
  */
 public function setUp()
 {
     $this->bus = new MockBus(new ClassMapCommandHandlerLoader(), new ClassMapEventListenerLoader(), new ClassMapQueryHandlerLoader());
     $this->anotherBus = new MockAnotherBus(new ClassMapCommandHandlerLoader(), new ClassMapEventListenerLoader(), new ClassMapQueryHandlerLoader());
     $gate = new Gate();
     $gate->attach($this->bus);
     $gate->attach($this->anotherBus);
 }
Exemplo n.º 3
0
 /**
  *
  */
 protected function setUp()
 {
     $this->gate = new Gate();
     $this->bus = new Integration2Bus();
     $this->bus->setCommandHandlerLoader(new ClassMapCommandHandlerLoader());
     $this->bus->setEventListenerLoader(new ClassMapEventListenerLoader());
     $this->bus->setQueryHandlerLoader(new ClassMapQueryHandlerLoader());
     $this->gate->attach($this->bus);
     $this->adapter = new AnnotationAdapter();
 }
Exemplo n.º 4
0
 /**
  *
  */
 protected function setUp()
 {
     $this->gate = new Gate();
     $this->bus = new Integration1Bus();
     $this->bus->setCommandHandlerLoader(new ClassMapCommandHandlerLoader());
     $this->bus->setEventListenerLoader(new ClassMapEventListenerLoader());
     $this->bus->setQueryHandlerLoader(new ClassMapQueryHandlerLoader());
     $this->bus->mapCommand('Malocher\\CqrsTest\\Integration\\Integration1\\Integration1Command', array('alias' => 'Malocher\\CqrsTest\\Integration\\Integration1\\Integration1Handler', 'method' => 'editCommand'));
     $this->bus->registerEventListener('Malocher\\CqrsTest\\Integration\\Integration1\\Integration1Event', array('alias' => 'Malocher\\CqrsTest\\Integration\\Integration1\\Integration1Handler', 'method' => 'editEvent'));
     $this->gate->attach($this->bus);
 }
Exemplo n.º 5
0
 /**
  * Sets up the fixture, for example, opens a network connection.
  * This method is called before a test is executed.
  */
 protected function setUp()
 {
     $classMapCommandHandlerLoader = new ClassMapCommandHandlerLoader();
     $classMapQueryHandlerLoader = new ClassMapQueryHandlerLoader();
     $this->Integration3EventListenerLoader = new Integration3EventListenerLoader();
     $this->Integration3EventListenerLoader->setIntegration3EventListener(new Integration3EventListener());
     $this->bus = new Integration3Bus();
     $this->bus->setCommandHandlerLoader($classMapCommandHandlerLoader);
     $this->bus->setEventListenerLoader($this->Integration3EventListenerLoader);
     $this->bus->setQueryHandlerLoader($classMapQueryHandlerLoader);
     $this->gate = new Gate();
     try {
         $this->gate->attach($this->bus);
     } catch (GateException $e) {
         echo $e->getMessage();
     }
 }
Exemplo n.º 6
0
 public function testGetBus_ErrorWhenNoDefaultBusIsDefined()
 {
     $this->setExpectedException('Malocher\\Cqrs\\Bus\\BusException');
     $mockBus = new MockBus(new ClassMapCommandHandlerLoader(), new ClassMapEventListenerLoader(), new ClassMapQueryHandlerLoader());
     $anotherBus = new \Malocher\CqrsTest\Coverage\Mock\Bus\MockAnotherBus(new ClassMapCommandHandlerLoader(), new ClassMapEventListenerLoader(), new ClassMapQueryHandlerLoader());
     $this->gate->attach($mockBus);
     $this->gate->attach($anotherBus);
     $this->assertEquals($this->gate->getBus(), $mockBus);
 }
Exemplo n.º 7
0
 /**
  *
  */
 public function __construct()
 {
     // The gate manages the bus system
     $this->gate = new Gate();
     // Create a bus and attach it to the gate
     $this->bus = new Iteration1Bus();
     $this->bus->setCommandHandlerLoader(new ClassMapCommandHandlerLoader());
     $this->bus->setEventListenerLoader(new ClassMapEventListenerLoader());
     $this->bus->setQueryHandlerLoader(new ClassMapQueryHandlerLoader());
     $this->gate->attach($this->bus);
     // Map a command to a handler
     $this->bus->mapCommand('Iteration\\Iteration1\\Iteration1Command', array('alias' => 'Iteration\\Iteration1\\Iteration1Handler', 'method' => 'editCommand'));
     // Register a event to a handler
     $this->bus->registerEventListener('Iteration\\Iteration1\\Iteration1Event', array('alias' => 'Iteration\\Iteration1\\Iteration1Handler', 'method' => 'editEvent'));
     // Send a command to the bus
     // Iteration1Handler::editCommand is mapped against this command and will be called
     $this->bus->invokeCommand(new Iteration1Command('Hello'));
 }
Exemplo n.º 8
0
 /**
  *
  */
 public function __construct()
 {
     // The gate manages the bus system
     $this->gate = new Gate();
     // Create a bus and attach it to the gate
     $this->bus = new Iteration3Bus();
     $this->bus->setCommandHandlerLoader(new ClassMapCommandHandlerLoader());
     $this->bus->setEventListenerLoader(new ClassMapEventListenerLoader());
     $this->bus->setQueryHandlerLoader(new ClassMapQueryHandlerLoader());
     $this->gate->attach($this->bus);
     // Use of AnnotationAdapter, adapters always us pipe
     $adapter = new AnnotationAdapter();
     $adapter->pipe($this->bus, array('Iteration\\Iteration3\\Iteration3Handler'));
     // See how this affects Iteration3Handler
     // Send a command to the bus
     // Iteration3Handler::editCommand is mapped against this command and will be called
     $this->bus->invokeCommand(new Iteration3Command('Hello'));
 }
Exemplo n.º 9
0
 /**
  *
  */
 public function __construct()
 {
     // The gate manages the bus system
     $this->gate = new Gate();
     // Create a bus and attach it to the gate
     $this->bus = new Iteration4Bus();
     $this->bus->setCommandHandlerLoader(new ClassMapCommandHandlerLoader());
     $this->bus->setEventListenerLoader(new ClassMapEventListenerLoader());
     $this->bus->setQueryHandlerLoader(new ClassMapQueryHandlerLoader());
     $this->gate->attach($this->bus);
     // Use of AnnotationAdapter, adapters always us pipe
     $adapter = new AnnotationAdapter();
     $adapter->pipe($this->bus, array('Iteration\\Iteration4\\Iteration4Handler'));
     // Enable the SystemBus and pipe it to some Monitoring
     $this->gate->enableSystemBus();
     $adapter->pipe($this->gate->getSystemBus(), array('Iteration\\Iteration4\\Iteration4Monitor'));
     // Send a command to the bus
     // Iteration4Handler::editCommand is mapped against this command and will be called
     $this->bus->invokeCommand(new Iteration4Command('Hello'));
 }
Exemplo n.º 10
0
 /**
  * load bus
  *
  * @param $busClass
  * @return mixed
  * @throws ConfigurationException
  */
 protected function loadBus($busClass)
 {
     $bus = new $busClass();
     if ($bus instanceof CommandHandlerLoaderAwareInterface) {
         if (is_null($this->getCommandHandlerLoader())) {
             throw ConfigurationException::initializeError('CommandHandlerLoaderInterface not initialized. Create a new CommandHandlerLoader() and pass it to setCommandHandlerLoader()');
         }
         $bus->setCommandHandlerLoader($this->commandHandlerLoader);
     }
     if ($bus instanceof EventListenerLoaderAwareInterface) {
         if (is_null($this->getEventListenerLoader())) {
             throw ConfigurationException::initializeError('EventListenerLoaderInterface not initialized. Create a new EventListenerLoader() and pass it to setEventListenerLoader()');
         }
         $bus->setEventListenerLoader($this->eventListenerLoader);
     }
     if ($bus instanceof QueryHandlerLoaderAwareInterface) {
         if (is_null($this->getQueryHandlerLoader())) {
             throw ConfigurationException::initializeError('QueryHandlerLoaderInterface not initialized. Create a new QueryHandlerLoader() and pass it to setQueryHandlerLoader()');
         }
         $bus->setQueryHandlerLoader($this->queryHandlerLoader);
     }
     $this->gate->attach($bus);
     return $bus;
 }
Exemplo n.º 11
0
 public function testPublishEvent()
 {
     $gate = new Gate();
     $gate->attach($this->bus);
     $this->bus->registerEventListener('Malocher\\CqrsTest\\Coverage\\Mock\\Event\\MockEvent', function (MockEvent $event) {
         $event->edit();
     });
     $mockEvent = new MockEvent();
     $this->bus->publishEvent($mockEvent);
     $this->assertEquals(true, $mockEvent->isEdited());
 }
Exemplo n.º 12
0
 public function testArrayMapPublishEventMissingAdapterTrait()
 {
     $this->setExpectedException('Malocher\\Cqrs\\Bus\\BusException');
     $gate = new Gate();
     $gate->enableSystemBus();
     $gate->attach($this->bus);
     $this->bus->registerEventListener('Malocher\\CqrsTest\\Coverage\\Mock\\Event\\MockEvent', array('alias' => 'Malocher\\CqrsTest\\Coverage\\Mock\\Event\\MockEventHandler', 'method' => 'handleEvent'));
     $gate->getSystemBus()->mapCommand('Malocher\\Cqrs\\Command\\PublishEventCommand', array('alias' => 'Malocher\\CqrsTest\\Coverage\\Mock\\Command\\MockCommandHandler', 'method' => 'handleCommand'));
     $gate->getSystemBus()->registerEventListener('Malocher\\Cqrs\\Event\\EventPublishedEvent', array('alias' => 'Malocher\\CqrsTest\\Coverage\\Mock\\Event\\MockEventHandlerNoAdapter', 'method' => 'handleEvent'));
     $mockEvent = new MockEvent();
     $gate->getBus($this->bus->getName())->publishEvent($mockEvent);
 }
 public function testUninstall()
 {
     $this->fs->ensureDirectoryExists($this->pluginDir);
     $installer = new GingerInstaller($this->io, $this->composer);
     $repository = new ComposerRepositoryMock();
     $package = new Package('gingerwfms/wf-configurator-backend', '1.0.0', '1.0.0');
     $package->setType('ginger-backend-plugin');
     $package->setExtra(array('plugin-namespace' => 'WfConfiguratorBackend'));
     $repository->addPackage($package);
     $gate = new Gate();
     $mockBus = new CqrsBusMock();
     $pluginNamespace = '';
     $pluginName = '';
     $pluginType = '';
     $pluginVersion = '';
     $mockBus->mapCommand('GingerPluginInstaller\\Cqrs\\UninstallPluginCommand', function (UninstallPluginCommand $command) use(&$pluginNamespace, &$pluginName, &$pluginType, &$pluginVersion) {
         $pluginNamespace = $command->getPluginNamespace();
         $pluginName = $command->getPluginName();
         $pluginType = $command->getPluginType();
         $pluginVersion = $command->getPluginVersion();
     });
     $gate->attach($mockBus);
     $gate->setDefaultBusName($mockBus->getName());
     Bootstrap::getServiceManager()->setAllowOverride(true);
     Bootstrap::getServiceManager()->setService('malocher.cqrs.gate', $gate);
     $installer->uninstall($repository, $package);
     $this->assertSame('WfConfiguratorBackend', $pluginNamespace);
     $this->assertSame('gingerwfms/wf-configurator-backend', $pluginName);
     $this->assertSame('ginger-backend-plugin', $pluginType);
     $this->assertSame('1.0.0', $pluginVersion);
 }