/** @test */
 function it_should_persist_an_event()
 {
     $store = Mockery::mock(EventStore::class);
     $subscriber = new PersistEventsSubscriber($store, new StoredEventFactory(new JsonSerializer()));
     $store->shouldReceive('append')->once()->with(Mockery::type(StoredEvent::class));
     $subscriber->handle(A::transferWasMadeEvent()->build());
 }
예제 #2
0
 /** @before */
 function generateFixtures()
 {
     $this->store = $this->storeInstance();
     $factory = new StoredEventFactory(new JsonSerializer());
     $event1 = $factory->from(A::transferWasMadeEvent()->build());
     $this->event2 = $factory->from(A::transferWasMadeEvent()->build());
     $event3 = $factory->from(A::transferWasMadeEvent()->build());
     $this->event4 = $factory->from(A::transferWasMadeEvent()->build());
     $this->store->append($event1);
     $this->store->append($this->event2);
     $this->store->append($event3);
     $this->store->append($this->event4);
 }
 /** @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());
 }