/**
  * @test
  */
 public function itCommitsAnEventStreamAndThenReadsIt()
 {
     $id = AggregateId::fromString('08cd0c48-6560-430b-93d5-fcb5902f6ae3');
     $originalEventStream = $this->createEventStream($id);
     $this->eventStore->commit($originalEventStream);
     $readEventStream = $this->eventStore->read($id);
     $this->assertEquals($originalEventStream, $readEventStream);
 }
    /**
     * @test
     */
    public function itCommitsAnEventStream()
    {
        $aggregateId = AggregateId::fromString('some-id');
        $this->serializer->shouldReceive('serialize')->times(3)->with(Mockery::type('SimpleES\\EventSourcing\\Event\\DomainEvent'))->andReturn('{"foo": "bar"}');
        $this->serializer->shouldReceive('serialize')->times(3)->with(Mockery::type('SimpleES\\EventSourcing\\Metadata\\Metadata'))->andReturn('{"bar": "foo"}');
        $sql = <<<EOQ
INSERT INTO event_store
(event_id, event_name, event_payload, aggregate_id, aggregate_version, took_place_at, metadata)
VALUES
(:event_id, :event_name, :event_payload, :aggregate_id, :aggregate_version, :took_place_at, :metadata)
EOQ;
        $stmt = Mockery::mock('Doctrine\\DBAL\\Driver\\Statement');
        $stmt->shouldReceive('bindValue')->once()->with('event_id', 'event-1', Type::GUID);
        $stmt->shouldReceive('bindValue')->once()->with('event_name', 'an_event_happened', Type::STRING);
        $stmt->shouldReceive('bindValue')->once()->with('aggregate_version', 0, Type::INTEGER);
        $stmt->shouldReceive('bindValue')->once()->with('event_id', 'event-2', Type::GUID);
        $stmt->shouldReceive('bindValue')->once()->with('event_name', 'another_event_happened', Type::STRING);
        $stmt->shouldReceive('bindValue')->once()->with('aggregate_version', 1, Type::INTEGER);
        $stmt->shouldReceive('bindValue')->once()->with('event_id', 'event-3', Type::GUID);
        $stmt->shouldReceive('bindValue')->once()->with('event_name', 'yet_another_event_happened', Type::STRING);
        $stmt->shouldReceive('bindValue')->once()->with('aggregate_version', 2, Type::INTEGER);
        $stmt->shouldReceive('bindValue')->times(3)->with('event_payload', '{"foo": "bar"}', Type::TEXT);
        $stmt->shouldReceive('bindValue')->times(3)->with('aggregate_id', (string) $aggregateId, Type::GUID);
        $stmt->shouldReceive('bindValue')->times(3)->with('took_place_at', Mockery::type('string'), Type::STRING);
        $stmt->shouldReceive('bindValue')->times(3)->with('metadata', '{"bar": "foo"}', Type::TEXT);
        $stmt->shouldReceive('execute')->times(3);
        $this->connection->shouldReceive('prepare')->once()->with($sql)->andReturn($stmt);
        $eventStream = $this->createEventStream($aggregateId);
        $this->eventStore->commit($eventStream);
        $stmt->shouldHaveReceived('execute');
    }