/** * 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; }
/** * @dataProvider instanceProvider */ public function testCount(DiffOp $diffOp) { if ($diffOp->isAtomic()) { $this->assertSame(1, $diffOp->count()); } else { $count = 0; /** * @var DiffOp $childOp */ foreach ($diffOp as $childOp) { $count += $childOp->count(); } $this->assertSame($count, $diffOp->count()); } }