/**
  * @test
  * @covers ::persist
  */
 public function it_should_persist_an_aggregate_root()
 {
     $aggregate = new AggregateMock();
     $exampleEvent = m::mock(\stdClass::class);
     $aggregate->recordEvent($exampleEvent);
     $this->streamNameGenerator->shouldReceive('generate')->andReturn('stream.id');
     $this->eventSerializer->shouldReceive('serialize')->with($exampleEvent)->andReturn(['id' => 2]);
     $this->transaction->shouldReceive('push')->once()->with('stream.id', m::on(function ($events) use($exampleEvent) {
         /** @var WritableEvent $event */
         $event = current($events);
         $data = $event->toStreamData();
         $this->assertSame(get_class($exampleEvent), $data['eventType']);
         $this->assertSame(['id' => 2], $data['data']);
         $this->assertSame(['user_id' => 1], $data['metadata']);
         return true;
     }));
     $this->metadataStore->shouldReceive('metadata')->with($exampleEvent)->andReturn(['user_id' => 1]);
     $this->repository->persist($aggregate);
 }
 /**
  * @param IsEventSourced|object $aggregateRoot
  */
 public function persist($aggregateRoot)
 {
     $this->transaction->push($this->streamNameGenerator->generate(get_class($aggregateRoot), (string) $aggregateRoot->id()), $this->getWriteableEventsFromAggregate($aggregateRoot));
 }