/**
  * @test
  */
 public function singleFilterCanBeAttachedToExistingFilters()
 {
     $filters = new FiltersCollection();
     $filters->addFilters(array('limit' => 12, 'offset' => 4));
     $filters->addFilter('username', 'someone');
     $this->assertEquals(array('username' => 'someone'), $filters->getFilter('data'));
     $this->assertEquals(12, $filters->getFilter('limit'));
     $this->assertEquals(4, $filters->getFilter('offset'));
 }
 /**
  * @param MessageCollection $messages
  * @param FiltersCollection $filters
  *
  * @return bool
  */
 public function retrieve(MessageCollection $messages, FiltersCollection $filters = null)
 {
     $findQuery = $this->prepareQuery($filters->getFilter('data'));
     try {
         $retrieved = $this->storage->find($this->collectionName, $findQuery);
         if ($filters->hasFilter('limit')) {
             $retrieved->limit($filters->getFilter('limit'));
         }
         if ($filters->hasFilter('offset')) {
             $retrieved->skip($filters->getFilter('offset'));
         }
         $retrieved->sort(array($this->defaultSortBy => -1));
     } catch (\MongoException $e) {
         $this->lastErrorMsg = $e->getMessage();
         return false;
     }
     foreach ($retrieved as $message) {
         $uniqueId = new UniqueId($message['id']);
         $messageFactory = new MessageFactory($uniqueId);
         $messages[] = $messageFactory->fromArray($message);
     }
     return true;
 }