Example #1
0
 /**
  * Persists participation in MongoDB
  *
  * @param string $userIdentifier Web user unique identification
  * @param string $scenarioIdentifier Scenario where tests has been executed (ie. url)
  *
  * @return boolean
  */
 public function store($userIdentifier, $scenarioIdentifier)
 {
     if (empty($this->participations)) {
         return false;
     }
     $documents = [];
     $uniqueRunIdentifier = uniqid('', true);
     foreach ($this->participations as $testIdentifier => $variantIdentifier) {
         $document = ['testIdentifier' => $testIdentifier, 'variantIdentifier' => $variantIdentifier, 'userIdentifier' => $userIdentifier, 'scenarioIdentifier' => $scenarioIdentifier, 'runIdentifier' => $uniqueRunIdentifier, 'createdAt' => new \MongoDB\BSON\UTCDatetime(time() * 1000)];
         $documents[] = ['insertOne' => [$document]];
     }
     $result = $this->collection->bulkWrite($documents);
     return $result->getInsertedCount();
 }