Example #1
0
 public function testElementsInRecuriveDiff()
 {
     $old = array('en' => array('en-foo', 'en-bar'), 'de' => array('de-0', 'de-1'), 'onoez' => array('~=[,,_,,]:3'), 'a' => 'b');
     $new = array('en' => array('en-foo', 'en-baz'), 'nl' => array('nl-0', 'nl-1'), 'onoez' => array('~=[,,_,,]:3'), 'a' => 'b');
     $differ = new MapDiffer(true);
     $diff = new Diff($differ->doDiff($old, $new));
     $this->assertTrue($diff->offsetExists('en'));
     $this->assertTrue($diff->offsetExists('de'));
     $this->assertTrue($diff->offsetExists('nl'));
     $this->assertFalse($diff->offsetExists('onoez'));
     $this->assertFalse($diff->offsetExists('a'));
     $this->assertInstanceOf('Diff\\DiffOp\\Diff\\Diff', $diff['de']);
     $this->assertInstanceOf('Diff\\DiffOp\\Diff\\Diff', $diff['nl']);
     $this->assertInstanceOf('Diff\\DiffOp\\Diff\\Diff', $diff['en']);
     $this->assertSame(2, count($diff['de']));
     $this->assertSame(2, count($diff['nl']));
     $this->assertSame(2, count($diff['en']));
     /**
      * @var Diff $listDiff
      */
     $listDiff = $diff['en'];
     $add = $listDiff->getAdditions();
     $add = array_shift($add);
     $this->assertEquals('en-baz', $add->getNewValue());
     $remove = $listDiff->getRemovals();
     $remove = array_shift($remove);
     $this->assertEquals('en-bar', $remove->getOldValue());
 }
Example #2
0
 public function testRemoveEmptyOperations()
 {
     $diff = new Diff(array());
     $diff['foo'] = new DiffOpAdd(1);
     $diff['bar'] = new Diff(array(new DiffOpAdd(1)), true);
     $diff['baz'] = new Diff(array(new DiffOpAdd(1)), false);
     $diff['bah'] = new Diff(array(), false);
     $diff['spam'] = new Diff(array(), true);
     $diff->removeEmptyOperations();
     $this->assertTrue($diff->offsetExists('foo'));
     $this->assertTrue($diff->offsetExists('bar'));
     $this->assertTrue($diff->offsetExists('baz'));
     $this->assertFalse($diff->offsetExists('bah'));
     $this->assertFalse($diff->offsetExists('spam'));
 }