Example #1
0
 /**
  * @vcr PersonTests/testMergePerson.json
  * @link https://familysearch.org/developers/docs/api/tree/Merge_Person_usecase
  */
 public function testMergePerson()
 {
     $factory = new FamilyTreeStateFactory();
     $this->collectionState($factory);
     /** @var FamilyTreePersonState $person1 */
     $person1 = $this->collectionState()->addPerson(PersonBuilder::buildPerson('male'))->get();
     /** @var FamilyTreePersonState $person2 */
     $person2 = $this->collectionState()->addPerson(PersonBuilder::buildPerson('male'))->get();
     $this->queueForDelete($person2, $person1);
     /** @var  \Gedcomx\Extensions\FamilySearch\Rs\Client\PersonMergeState $result */
     $result = $person1->readMergeAnalysis($person2);
     /** @var  \Gedcomx\Extensions\FamilySearch\Platform\Tree\MergeAnalysis $analysis */
     $analysis = $result->getAnalysis();
     $merge = new Merge();
     $merge->setResourcesToCopy($analysis->getDuplicateResources());
     /** @var \Gedcomx\Extensions\FamilySearch\Platform\Tree\MergeConflict $resource */
     foreach ($analysis->getConflictingResources() as $resource) {
         if ($resource->getDuplicateResource()) {
             $ref = $resource->getDuplicateResource();
             $merge->addResourceToCopy($ref);
         }
     }
     $state = $result->doMerge($merge);
     $this->assertEquals(HttpStatus::NO_CONTENT, $state->getStatus(), $this->buildFailMessage(__METHOD__, $state));
 }
Example #2
0
 /**
  * @link https://familysearch.org/developers/docs/api/tree/Merge_Person_usecase
  */
 public function testMergePerson()
 {
     $factory = new FamilyTreeStateFactory();
     $this->collectionState($factory);
     $person = PersonBuilder::buildPerson('male');
     /** @var FamilyTreePersonState $person1 */
     $person1 = $this->collectionState()->addPerson($person)->get();
     /** @var FamilyTreePersonState $person2 */
     $person2 = $this->collectionState()->addPerson($person)->get();
     $this->queueForDelete($person2, $person1);
     /** @var  \Gedcomx\Extensions\FamilySearch\Rs\Client\PersonMergeState $result */
     $result = $person1->readMergeAnalysis($person2);
     /** @var  \Gedcomx\Extensions\FamilySearch\Platform\Tree\MergeAnalysis $analysis */
     $analysis = $result->getAnalysis();
     $merge = new Merge();
     $merge->setResourcesToCopy($analysis->getDuplicateResources());
     /** @var \Gedcomx\Extensions\FamilySearch\Platform\Tree\MergeConflict $resource */
     foreach ($analysis->getConflictingResources() as $resource) {
         if ($resource->getDuplicateResource()) {
             $ref = $resource->getDuplicateResource();
             $merge->addResourceToCopy($ref);
         }
     }
     $state = $result->doMerge($merge);
     $this->assertEquals(HttpStatus::NO_CONTENT, $state->getResponse()->getStatusCode(), $this->buildFailMessage(__METHOD__, $state));
     //  Read the results of the merge
     $person1 = $person1->get();
     $person2 = $person2->get();
     //  HttpStatus::MOVED_PERMANENTLY is the correct response for a person that has been merged.
     //  However, asserting that response assumes that the HTTP client does not automatically
     //  follow redirects, which Guzzle does.
     //
     //  Rather than disabling the redirect feature, we'll assert that both person states have the
     //  same URI now.
     $this->assertEquals($person1->getSelfUri(), $person2->getSelfUri(), "Person URIs don't match.");
 }