Exemplo n.º 1
0
 public function testMatchGrep()
 {
     $test = ['name' => ['name2' => ['name3' => 'yep pa'], 'name4' => 'pa red pa'], 'surname' => '#blue sky'];
     $match = Parser::match($test, ['grep' => ['name.name2.name3' => ['yep', 'blue', 'red']]]);
     $this->assertTrue($match);
     $match = Parser::match($test, ['grep' => ['name.name2.name3' => ['yep', 'blue', 'red'], 'name.name4' => 'red', 'surname' => ['blue']]]);
     $this->assertTrue($match);
     $match = Parser::match($test, ['grep' => ['name.name2.name3' => ['ye', 'blue', 'red']]]);
     $this->assertFalse($match);
 }
Exemplo n.º 2
0
 /**
  * Given an array of tweets and a collection
  * return the tweets that missing from the collection
  *
  * @see self::write() for $options
  * @param array $tweets
  * @param \MongoDB\Collection $collection
  * @param array $options
  * @return array
  */
 private function filterToSave(array $tweets, \MongoDB\Collection $collection, array $options)
 {
     $toSave = [];
     foreach ($tweets as $key => $tweet) {
         if (!Parser::match($tweet, $options)) {
             continue;
         }
         $countTweets = $collection->count(['id_str' => $tweet['id_str']]);
         if ($countTweets === 0) {
             $toSave[] = $tweet;
         }
     }
     return $toSave;
 }