/** * @command Malocher\Cqrs\Command\PublishEventCommand * @param PublishEventCommand $command */ public function publishEventHandler(PublishEventCommand $command) { print "---- monitoring start -----\n"; print sprintf("PublishEventCommand invoked by %s on %s \n", $command->getMessageClass(), $command->getBusName()); print sprintf("id:%s, edited:%s, ts:%s, version:%s, payload:%s \n", $command->getMessageVars()['id'], $command->getMessageVars()['edited'], $command->getMessageVars()['timestamp'], $command->getMessageVars()['version'], $command->getMessageVars()['payload']); print "---- monitoring ends ------\n"; }
public function testClosurePublishEvent() { $gate = new Gate(); $gate->enableSystemBus(); $gate->attach($this->bus); $this->bus->registerEventListener('Malocher\\CqrsTest\\Coverage\\Mock\\Event\\MockEvent', function (MockEvent $event) { $event->edit(); }); $gate->getSystemBus()->mapCommand('Malocher\\Cqrs\\Command\\PublishEventCommand', function (PublishEventCommand $command) { $this->publishEventCommand = $command; }); $gate->getSystemBus()->registerEventListener('Malocher\\Cqrs\\Event\\EventPublishedEvent', function (EventPublishedEvent $event) { $this->eventPublishedEvent = $event; }); $mockEvent = new MockEvent(); $gate->getBus($this->bus->getName())->publishEvent($mockEvent); $this->assertEquals(true, $mockEvent->isEdited()); $this->assertInstanceOf('Malocher\\Cqrs\\Command\\PublishEventCommand', $this->publishEventCommand); $this->assertInstanceOf('Malocher\\Cqrs\\Event\\EventPublishedEvent', $this->eventPublishedEvent); $this->assertEquals('Malocher\\CqrsTest\\Coverage\\Mock\\Event\\MockEvent', $this->publishEventCommand->getMessageClass()); $this->assertEquals('Malocher\\CqrsTest\\Coverage\\Mock\\Event\\MockEvent', $this->eventPublishedEvent->getMessageClass()); }