/**
  * @dataProvider addProvider
  * @param object[] $objectsSource
  * @param object $object
  * @param int|null $index
  * @param object[] $objectsDestination
  */
 public function testAddObjectAtIndex(array $objectsSource, $object, $index, array $objectsDestination)
 {
     $indexedArray = new ByPropertyIdArray($objectsSource);
     $indexedArray->buildIndex();
     $indexedArray->addObjectAtIndex($object, $index);
     $this->assertEquals($objectsDestination, $indexedArray->toFlatArray());
 }
 /**
  * @param Statement[] $statements
  *
  * @throws ChangeOpException
  * @return Statement[]
  */
 private function addStatement(array $statements)
 {
     // If we fail with the user supplied index and the index is greater than or equal 0
     // presume the user wants to have the index at the end of the list.
     if ($this->index < 0) {
         throw new ChangeOpException('Can not add claim at given index: ' . $this->index);
     }
     $indexedStatements = new ByPropertyIdArray($statements);
     $indexedStatements->buildIndex();
     try {
         $indexedStatements->addObjectAtIndex($this->statement, $this->index);
         $statements = $indexedStatements->toFlatArray();
     } catch (OutOfBoundsException $ex) {
         $statements[] = $this->statement;
     }
     return $statements;
 }