示例#1
0
 /**
  * @dataProvider instanceProvider
  */
 public function testToArray(DiffOp $diffOp)
 {
     $array = $diffOp->toArray();
     $this->assertInternalType('array', $array);
     $this->assertArrayHasKey('type', $array);
     $this->assertInternalType('string', $array['type']);
     $this->assertEquals($diffOp->getType(), $array['type']);
 }
示例#2
0
 /**
  * Does the actual work.
  *
  * @param string[] $path
  * @param DiffOp $op
  *
  * @return string
  * @throws MWException
  */
 private function generateOpHtml(array $path, DiffOp $op)
 {
     if ($op->isAtomic()) {
         $html = $this->generateDiffHeaderHtml(implode(' / ', $path));
         //TODO: no path, but localized section title
         //FIXME: complex objects as values?
         if ($op->getType() === 'add') {
             /** @var DiffOpAdd $op */
             $html .= $this->generateChangeOpHtml(null, $op->getNewValue(), $path);
         } elseif ($op->getType() === 'remove') {
             /** @var DiffOpRemove $op */
             $html .= $this->generateChangeOpHtml($op->getOldValue(), null, $path);
         } elseif ($op->getType() === 'change') {
             /** @var DiffOpChange $op */
             $html .= $this->generateChangeOpHtml($op->getOldValue(), $op->getNewValue(), $path);
         } else {
             throw new MWException('Invalid diffOp type');
         }
     } else {
         $html = '';
         foreach ($op as $key => $subOp) {
             $html .= $this->generateOpHtml(array_merge($path, array($key)), $subOp);
         }
     }
     return $html;
 }
示例#3
0
 /**
  * Gets called before a new element is added to the ArrayObject.
  *
  * At this point the index is always set (ie not null) and the
  * value is always of the type returned by @see getObjectType.
  *
  * Should return a boolean. When false is returned the element
  * does not get added to the ArrayObject.
  *
  * @param int|string $index
  * @param DiffOp $value
  *
  * @return bool
  * @throws InvalidArgumentException
  */
 private function preSetElement($index, DiffOp $value)
 {
     if ($this->isAssociative === false && ($value->getType() !== 'add' && $value->getType() !== 'remove')) {
         throw new InvalidArgumentException('Diff operation with invalid type "' . $value->getType() . '" provided.');
     }
     if (array_key_exists($value->getType(), $this->typePointers)) {
         $this->typePointers[$value->getType()][] = $index;
     } else {
         throw new InvalidArgumentException('Diff operation with invalid type "' . $value->getType() . '" provided.');
     }
     return true;
 }