/** * @dataProvider providerGetFieldThrowsExceptionWhenInvalidNameProvided * @expectedException zibo\ZiboException */ public function testGetFieldThrowsExceptionWhenInvalidNameProvided($name) { $table = new Table('table'); $table->getField($name); }
/** * Gets the indexes of a table * @param zibo\library\database\definition\Table $table Definition of the table * @return array Array with Index objects */ protected function getTableIndexes(Table $table) { $tableName = $this->connection->quoteIdentifier($table->getName()); $sql = 'SHOW INDEX FROM ' . $tableName; $result = $this->connection->execute($sql); $indexData = array(); foreach ($result as $data) { if ($data['Key_name'] == 'PRIMARY') { continue; } if (!array_key_exists($data['Key_name'], $indexData)) { $indexData[$data['Key_name']] = array(); } $indexData[$data['Key_name']][$data['Seq_in_index']] = $data['Column_name']; } $indexes = array(); foreach ($indexData as $indexName => $indexFields) { $fields = array(); foreach ($indexFields as $fieldName) { $fields[$fieldName] = $table->getField($fieldName); } $indexes[] = new Index($indexName, $fields); } return $indexes; }