public function testOverrulesWithPartial() { $without = new Index('without', array('col1', 'col2'), true, false, array(), array()); $partial = new Index('partial', array('col1', 'col2'), true, false, array(), array('where' => 'col1 IS NULL')); $another = new Index('another', array('col1', 'col2'), true, false, array(), array('where' => 'col1 IS NULL')); $this->assertFalse($partial->overrules($without)); $this->assertFalse($without->overrules($partial)); $this->assertTrue($partial->overrules($partial)); $this->assertTrue($partial->overrules($another)); $this->assertTrue($another->overrules($partial)); }
/** * Add index to table * * @param Index $indexCandidate * @return Table */ protected function _addIndex(Index $indexCandidate) { // check for duplicates foreach ($this->_indexes as $existingIndex) { if ($indexCandidate->isFullfilledBy($existingIndex)) { return $this; } } $indexName = $indexCandidate->getName(); $indexName = strtolower($indexName); if (isset($this->_indexes[$indexName]) || $this->_primaryKeyName != false && $indexCandidate->isPrimary()) { throw SchemaException::indexAlreadyExists($indexName, $this->_name); } // remove overruled indexes foreach ($this->_indexes as $idxKey => $existingIndex) { if ($indexCandidate->overrules($existingIndex)) { unset($this->_indexes[$idxKey]); } } if ($indexCandidate->isPrimary()) { $this->_primaryKeyName = $indexName; } $this->_indexes[$indexName] = $indexCandidate; return $this; }