/** @test */
 function it_should_persist_an_event_published_inside_an_slim_route()
 {
     /** @var \Hexagonal\Bridges\Doctrine2\DomainEvents\EventStoreRepository $store */
     $store = $this->entityManager->getRepository(StoredEvent::class);
     $publisher = new EventPublisher();
     $middleware = new StoreEventsMiddleware(new PersistEventsSubscriber($store, new StoredEventFactory(new JsonSerializer())), $publisher);
     $app = new Slim();
     $app->get('/', function () use($publisher) {
         $events = new SplObjectStorage();
         $events->attach(A::transferWasMadeEvent()->build());
         $publisher->publish($events);
     });
     $app->add($middleware);
     Environment::mock(['REQUEST_METHOD' => 'GET']);
     $app->run();
     $this->assertCount(1, $store->allEvents());
 }
 /**
  * Register the services for Transfer Funds feature delivered through a
  * console command
  *
  * @param Container $container
  */
 public function register(Container $container)
 {
     $container['ewallet.member_repository'] = function () use($container) {
         return $container['doctrine.em']->getRepository(Member::class);
     };
     $container['ewallet.template_engine'] = function () use($container) {
         return new TwigTemplateEngine($container['twig.environment']);
     };
     $container['ewallet.transfer_funds'] = function () use($container) {
         $transferFunds = new TransferFundsTransactionally($container['ewallet.member_repository']);
         $transferFunds->setTransactionalSession(new DoctrineSession($container['doctrine.em']));
         $transferFunds->setPublisher($container['ewallet.events_publisher']);
         return $transferFunds;
     };
     $container['ewallet.member_formatter'] = function () {
         return new MemberFormatter();
     };
     $container['ewallet.events_publisher'] = function () use($container) {
         $publisher = new EventPublisher();
         $publisher->subscribe($container['ewallet.transfer_funds_logger']);
         return $publisher;
     };
     $container['ewallet.transfer_funds_logger'] = function () use($container) {
         return new LogTransferWasMadeSubscriber($container['ewallet.logger'], $container['ewallet.member_formatter']);
     };
     $container['ewallet.logger'] = function () use($container) {
         $logger = new Logger($container['monolog']['ewallet']['channel']);
         $logger->pushHandler(new StreamHandler($container['monolog']['ewallet']['path'], Logger::DEBUG));
         return $logger;
     };
     $container['ewallet.transfer_mail_sender'] = function () use($container) {
         return new TransferFundsZendMailSender($container['ewallet.template_engine'], (new TransportFactory())->buildTransport($container['mail']));
     };
     $container['ewallet.transfer_mail_notifier'] = function () use($container) {
         return new TransferFundsEmailNotifier($container['ewallet.member_repository'], $container['ewallet.transfer_mail_sender']);
     };
     $container['ewallet.event_store'] = function () use($container) {
         return $container['doctrine.em']->getRepository(StoredEvent::class);
     };
     $container['ewallet.event_persist_subscriber'] = function () use($container) {
         return new PersistEventsSubscriber($container['ewallet.event_store'], new StoredEventFactory(new JsonSerializer()));
     };
     $container['ewallet.store_events_listener'] = function () use($container) {
         return new StoreEventsListener($container['ewallet.event_persist_subscriber'], $container['ewallet.events_publisher']);
     };
     $container['ewallet.console.dispatcher'] = function () use($container) {
         $dispatcher = new EventDispatcher();
         $dispatcher->addListener(ConsoleEvents::COMMAND, $container['ewallet.store_events_listener']);
         return $dispatcher;
     };
     $container['ewallet.twig.extension'] = function () {
         return new EwalletExtension(new MemberFormatter());
     };
     $container->extend('twig.loader', function (Loader $loader) {
         $loader->addPath(__DIR__ . '/../../../../EwalletModule/Bridges/Twig/Resources/templates');
         $loader->addPath(__DIR__ . '/../../SymfonyConsole/Resources/templates');
         return $loader;
     });
     $container->extend('twig.environment', function (Environment $twig) use($container) {
         $twig->addExtension($container['ewallet.twig.extension']);
         return $twig;
     });
 }
 /**
  * Register the subscriber that stores domain events only for the
  * `ewallet:transfer` command
  *
  * @param ConsoleCommandEvent $event
  */
 public function storeEvents(ConsoleCommandEvent $event)
 {
     if ('ewallet:transfer' === $event->getCommand()->getName()) {
         $this->publisher->subscribe($this->subscriber);
     }
 }
 /**
  * Register event subscriber to persist all domain events generated by
  * the web application
  */
 public function call()
 {
     $this->publisher->subscribe($this->subscriber);
     $this->next->call();
 }