/**
  * @covers ::isNotPrimaryKey
  */
 public function testIsNotPrimaryKey()
 {
     $indices = new IndexCollection();
     $this->assertSame(0, $indices->isNotPrimaryKey()->count());
     $indices->add(new Index('PRIMARY', null, null));
     $this->assertSame(0, $indices->isNotPrimaryKey()->count());
     $indices->add(new Index(null, null, null));
     $this->assertSame(1, $indices->isNotPrimaryKey()->count());
 }
Esempio n. 2
0
 /**
  * Check for redundant indices on primary key column
  *
  * @param ColumnCollection $columns Table columns
  * @param IndexCollection  $indices Table indices
  *
  * @return array Result
  */
 public function checkRedundantIndicesOnPrimaryKey(ColumnCollection $columns, IndexCollection $indices)
 {
     $result = [];
     /**
      * Check primary key columns
      */
     foreach ($columns->isPrimaryKey() as $column) {
         $colums = [$column->getField()];
         /**
          * Check non primary key indices
          */
         foreach ($indices->isNotPrimaryKey() as $index) {
             /**
              * Check indices with just our primary key column
              */
             if ($index->isColumnsEqual($colums) === true) {
                 $indexType = $index->isUnique() === true ? 'unique' : 'key';
                 /**
                  * Check if index is unique
                  */
                 $result[] = ['type' => 'index', 'key' => $index->getKeyName(), 'description' => sprintf('An %s index on the primary key column is redundant', $indexType)];
             }
         }
     }
     return $result;
 }