public function testCorrelationDataIsAttached() { CorrelationDataHolder::setCorrelationData(array('correlationId' => 'test')); $this->testSubject->send(new HelloCommand('Hi !!!')); \Phake::verify($this->mockCommandBus)->dispatch(\Phake::capture($command), null); $this->assertEquals(array('correlationId' => 'test'), $command->getMetaData()->all()); }
} } class UserEventListener implements EventListenerInterface { public function handle(EventMessageInterface $event) { print_r($event->getPayload()); } } // set up logging $logger = new Logger('governor'); $logger->pushHandler(new StreamHandler('php://stdout', Logger::DEBUG)); // 1. create a command bus and command gateway $commandBus = new SimpleCommandBus(); $commandBus->setLogger($logger); $commandGateway = new DefaultCommandGateway($commandBus); $rootDirectory = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'CommandHandlerExample'; @mkdir($rootDirectory); echo sprintf("Initializing FileSystemEventStore in %s\n", $rootDirectory); // 2. initialize the event store $eventStore = new FilesystemEventStore(new SimpleEventFileResolver($rootDirectory), new JMSSerializer()); // 3. create the event bus $eventBus = new SimpleEventBus(); $eventBus->setLogger($logger); // 4. create an event sourcing repository $repository = new EventSourcingRepository(User::class, $eventBus, new NullLockManager(), $eventStore, new GenericAggregateFactory(User::class)); //5. create and register our commands $commandHandler = new UserCommandHandler($repository); $commandBus->subscribe('CommandHandlerExample\\CreateUserCommand', $commandHandler); $commandBus->subscribe('CommandHandlerExample\\ChangeUserEmailCommand', $commandHandler); //6. create and register the eventlistener