/**
  * @since 0.4
  *
  * @param ReferenceList $references
  * @param Summary|null $summary
  *
  * @throws ChangeOpException
  */
 protected function setReference(ReferenceList $references, Summary $summary = null)
 {
     if (!$references->hasReferenceHash($this->referenceHash)) {
         throw new ChangeOpException("Reference with hash {$this->referenceHash} does not exist");
     }
     $currentIndex = $references->indexOf($this->reference);
     if ($this->index === null && $currentIndex !== false) {
         // Set index to current index to not have the reference removed and appended but
         // retain its position within the list of references.
         $this->index = $currentIndex;
     }
     if ($references->hasReference($this->reference) && $this->index === $currentIndex) {
         throw new ChangeOpException('The statement has already a reference with hash ' . $this->reference->getHash() . ' and index (' . $currentIndex . ') is not changed');
     }
     $references->removeReferenceHash($this->referenceHash);
     $references->addReference($this->reference, $this->index);
     $this->updateSummary($summary, 'set');
 }
 public function testGivenAnArrayOfSnaks_addNewReferenceAddsThem()
 {
     $references = new ReferenceList();
     $snaks = array(new PropertyNoValueSnak(1), new PropertyNoValueSnak(3), new PropertyNoValueSnak(2));
     $references->addNewReference($snaks);
     $this->assertTrue($references->hasReference(new Reference($snaks)));
 }