/**
  *
  */
 public function testPartial()
 {
     $docFactory = new DocumentFactory(self::$documentPrototype);
     $userInfo = ['snsid' => '100001349218797', 'name' => 'jiangyu', 'email' => '*****@*****.**', 'country' => 'CN'];
     $payload = $docFactory->buildPayload($userInfo);
     $this->assertArrayNotHasKey('name', $payload, print_r($payload, true));
     $this->assertArrayNotHasKey('email', $payload, print_r($payload, true));
     $this->assertArrayHasKey('country', $payload, print_r($payload, true));
     $document = $docFactory->buildDocument($userInfo['snsid'], $payload);
     $this->assertNotEmpty($document->getIndex(), 'Bad index ' . print_r($document, true));
     $this->assertNotEmpty($document->getType(), 'Bad type ' . print_r($document, true));
 }
 /**
  * @param array $userInfoList
  *
  * @return Generator
  */
 protected function documentsGenerator(array $userInfoList)
 {
     while ($batch = array_splice($userInfoList, 0, $this->magicNumber)) {
         $documents = array_map(function (array $userInfo) {
             return $this->documentFactory->make($userInfo['snsid'], $userInfo);
         }, $batch);
         (yield $documents);
     }
 }
Exemple #3
0
 /**
  * @param User $user
  *
  * @return array
  */
 public function toArray(User $user)
 {
     return $this->documentFactory->buildPayload(get_object_vars($user));
 }