/**
  */
 public function testFire()
 {
     $userObjList = $this->userProvider();
     $userObj = array_pop($userObjList);
     static::assertInstanceOf(User::class, $userObj);
     $esIndex = Mockery::mock(Index::class);
     $esIndex->shouldReceive('addDocuments')->times(1)->andReturn(Mockery::mock(ResponseSet::class));
     $this->esClient->shouldReceive('getIndex')->times(1)->andReturn($esIndex);
     $this->userRepo->fire($userObj, $errorInfo);
     $this->assertNull($errorInfo);
     $this->userPersist->setSnsid($userObj->snsid);
     $esIndex = Mockery::mock(Index::class);
     $esType = Mockery::mock(\Elastica\Type::class);
     $document = Mockery::mock(Document::class);
     $document->shouldReceive('getData')->times(1)->andReturn((new Factory())->toArray($userObj));
     $esType->shouldReceive('getDocument')->times(1)->andReturn($document);
     $esIndex->shouldReceive('getType')->times(1)->andReturn($esType);
     $this->esClient->shouldReceive('getIndex')->times(1)->andReturn($esIndex);
     $found = $this->userPersist->retrieve();
     $foundObj = $this->factory->makeUser($found);
     static::assertEquals($this->factory->toArray($userObj), $this->factory->toArray($foundObj));
 }
Example #2
0
 /**
  * @param array    $users
  * @param \Closure $callback
  *
  * @return \float[]
  */
 public function batchUpdate(array $users, \Closure $callback = null)
 {
     $count = count($users);
     if ($count === 0) {
         return [];
     }
     $esUserList = $this->sanitizeData($users);
     $this->lastRoundData = $esUserList;
     $deltaList = [];
     while ($batch = array_splice($esUserList, 0, $this->batchSize)) {
         $start = microtime(true);
         $errorString = '';
         $success = $this->repo->burst($batch, $errorString);
         if (!$success) {
             $this->batchResult[] = $errorString;
         }
         $delta = microtime(true) - $start;
         $deltaList[] = $delta;
         if (is_callable($callback)) {
             call_user_func($callback, count($batch), $delta);
         }
     }
     return $deltaList;
 }