public function testEventsForwardedToTerminals()
 {
     $mockTerminal1 = $this->getMock(TerminalInterface::class);
     $mockTerminal2 = $this->getMock(TerminalInterface::class);
     $this->testSubject->setTerminals([$mockTerminal1, $mockTerminal2]);
     $mockTerminal1->expects($this->once())->method('publish');
     $mockTerminal2->expects($this->once())->method('publish');
     $this->testSubject->publish($this->newEvent());
 }
 public function testAnnotatedHandlersRecognized()
 {
     //        $delegate = new SimpleEventBus(new InMemoryEventListenerRegistry());
     $listener = new MyReplayAwareListener();
     $adapter = new AnnotatedEventListenerAdapter($listener, $this->delegate, new SimpleAnnotationReaderFactory());
     $this->delegate->getEventListenerRegistry()->subscribe($adapter);
     $this->testSubject->startReplay();
     $this->assertEquals(0, $listener->counter);
     $this->assertEquals(1, $listener->before);
     $this->assertEquals(1, $listener->after);
 }
    }
}
// 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
$eventListener = new UserEventListener();
$eventBus->subscribe($eventListener);
//7. send commands
$aggregateIdentifier = Uuid::uuid1()->toString();
$commandGateway->send(new CreateUserCommand($aggregateIdentifier, '*****@*****.**'));
$commandGateway->send(new ChangeUserEmailCommand($aggregateIdentifier, '*****@*****.**'));
//8. read back aggregate from store