Exemplo n.º 1
0
 public function testCompareDifferentOrder()
 {
     $c1 = new Column('Foo');
     $c2 = new Column('Bar');
     $i1 = new Index('Foo_Bar_Index');
     $i1->addColumn($c1);
     $i1->addColumn($c2);
     $c3 = new Column('Foo');
     $c4 = new Column('Bar');
     $i2 = new Index('Foo_Bar_Index');
     $i2->addColumn($c4);
     $i2->addColumn($c3);
     $this->assertTrue(IndexComparator::computeDiff($i1, $i2));
 }
Exemplo n.º 2
0
 /**
  * Returns the number of differences.
  *
  * Compare the indices and unique indices of the fromTable and the toTable,
  * and modifies the inner tableDiff if necessary.
  *
  * @param  boolean $caseInsensitive
  * @return integer
  */
 public function compareIndices($caseInsensitive = false)
 {
     $indexDifferences = 0;
     $fromTableIndices = array_merge($this->getFromTable()->getIndices(), $this->getFromTable()->getUnices());
     $toTableIndices = array_merge($this->getToTable()->getIndices(), $this->getToTable()->getUnices());
     foreach ($fromTableIndices as $fromTableIndexPos => $fromTableIndex) {
         foreach ($toTableIndices as $toTableIndexPos => $toTableIndex) {
             $sameName = $caseInsensitive ? strtolower($fromTableIndex->getName()) == strtolower($toTableIndex->getName()) : $fromTableIndex->getName() == $toTableIndex->getName();
             if ($sameName) {
                 if (false === IndexComparator::computeDiff($fromTableIndex, $toTableIndex, $caseInsensitive)) {
                     //no changes
                     unset($fromTableIndices[$fromTableIndexPos]);
                     unset($toTableIndices[$toTableIndexPos]);
                 } else {
                     // same name, but different columns
                     $this->tableDiff->addModifiedIndex($fromTableIndex->getName(), $fromTableIndex, $toTableIndex);
                     unset($fromTableIndices[$fromTableIndexPos]);
                     unset($toTableIndices[$toTableIndexPos]);
                     $indexDifferences++;
                 }
             }
         }
     }
     foreach ($fromTableIndices as $fromTableIndex) {
         $this->tableDiff->addRemovedIndex($fromTableIndex->getName(), $fromTableIndex);
         $indexDifferences++;
     }
     foreach ($toTableIndices as $toTableIndex) {
         $this->tableDiff->addAddedIndex($toTableIndex->getName(), $toTableIndex);
         $indexDifferences++;
     }
     return $indexDifferences;
 }