getTableNames() публичный Метод

Returns an array of table names contained in the dataset.
public getTableNames ( ) : array
Результат array
Пример #1
0
 public function execute(\PHPUnit_Extensions_Database_DB_IDatabaseConnection $connection, \PHPUnit_Extensions_Database_DataSet_IDataSet $dataSet)
 {
     foreach ($dataSet->getTableNames() as $tableName) {
         $connection->getConnection()->query("Alter Table {$tableName} NOCHECK Constraint All");
     }
     foreach ($dataSet->getTableNames() as $tableName) {
         $connection->getConnection()->query("Delete From {$tableName}");
     }
     foreach ($dataSet->getTableNames() as $tableName) {
         $connection->getConnection()->query("DBCC CHECKIDENT ({$tableName}, RESEED, 0)");
     }
     foreach ($dataSet->getTableNames() as $tableName) {
         $connection->getConnection()->query("Alter Table {$tableName} CHECK Constraint All");
     }
 }
 /**
  * Adds a new data set to the composite.
  *
  * The dataset may not define tables that already exist in the composite.
  *
  * @param PHPUnit_Extensions_Database_DataSet_IDataSet $dataSet
  */
 public function addDataSet(PHPUnit_Extensions_Database_DataSet_IDataSet $dataSet)
 {
     foreach ($dataSet->getTableNames() as $tableName) {
         if (in_array($tableName, $this->getTableNames())) {
             throw new InvalidArgumentException("DataSet contains a table that already exists: {$tableName}");
         }
     }
     $this->dataSets[] = $dataSet;
 }
Пример #3
0
 public function execute(\PHPUnit_Extensions_Database_DB_IDatabaseConnection $connection, \PHPUnit_Extensions_Database_DataSet_IDataSet $dataSet)
 {
     foreach ($dataSet->getTableNames() as $tableName) {
         $connection->getConnection()->query("Alter Table {$tableName} NOCHECK Constraint All");
     }
     parent::execute($connection, $dataSet);
     foreach ($dataSet->getTableNames() as $tableName) {
         $connection->getConnection()->query("Alter Table {$tableName} CHECK Constraint All");
     }
 }
 /**
  * Adds a new data set to the composite.
  *
  * The dataset may not define tables that already exist in the composite.
  *
  * @param PHPUnit_Extensions_Database_DataSet_IDataSet $dataSet
  */
 public function addDataSet(PHPUnit_Extensions_Database_DataSet_IDataSet $dataSet)
 {
     foreach ($dataSet->getTableNames() as $tableName) {
         if (!in_array($tableName, $this->getTableNames())) {
             $this->motherDataset->addTable($dataSet->getTable($tableName));
         } else {
             $other = $dataSet->getTable($tableName);
             $table = $this->getTable($tableName);
             if (!$table->getTableMetaData()->matches($other->getTableMetaData())) {
                 throw new InvalidArgumentException("There is already a table named {$tableName} with different table definition");
             }
             $table->addTableRows($dataSet->getTable($tableName));
         }
     }
 }
 /**
  * Asserts that the given data set matches this data set.
  *
  * @param PHPUnit_Extensions_Database_DataSet_IDataSet $other
  */
 public function matches(PHPUnit_Extensions_Database_DataSet_IDataSet $other)
 {
     $thisTableNames = $this->getTableNames();
     $otherTableNames = $other->getTableNames();
     sort($thisTableNames);
     sort($otherTableNames);
     if ($thisTableNames != $otherTableNames) {
         return FALSE;
     }
     foreach ($thisTableNames as $tableName) {
         $table = $this->getTable($tableName);
         if (!$table->matches($other->getTable($tableName))) {
             return FALSE;
         }
     }
     return TRUE;
 }
Пример #6
0
 /**
  * Asserts that the given data set matches this data set.
  *
  * @param PHPUnit_Extensions_Database_DataSet_IDataSet $other
  */
 public function assertEquals(PHPUnit_Extensions_Database_DataSet_IDataSet $other)
 {
     $thisTableNames = $this->getTableNames();
     $otherTableNames = $other->getTableNames();
     sort($thisTableNames);
     sort($otherTableNames);
     if ($thisTableNames != $otherTableNames) {
         throw new Exception("Expected following tables: " . implode(', ', $thisTableNames) . "; has columns: " . implode(', ', $otherTableNames));
     }
     foreach ($thisTableNames as $tableName) {
         $this->getTable($tableName)->assertEquals($other->getTable($tableName));
     }
     return TRUE;
 }
Пример #7
0
    /**
     * Load date into moodle database tables from standard PHPUnit data set.
     *
     * Note: it is usually better to use data generators
     *
     * @param PHPUnit_Extensions_Database_DataSet_IDataSet $dataset
     * @return void
     */
    protected function loadDataSet(PHPUnit_Extensions_Database_DataSet_IDataSet $dataset) {
        global $DB;

        $structure = phpunit_util::get_tablestructure();

        foreach($dataset->getTableNames() as $tablename) {
            $table = $dataset->getTable($tablename);
            $metadata = $dataset->getTableMetaData($tablename);
            $columns = $metadata->getColumns();

            $doimport = false;
            if (isset($structure[$tablename]['id']) and $structure[$tablename]['id']->auto_increment) {
                $doimport = in_array('id', $columns);
            }

            for($r=0; $r<$table->getRowCount(); $r++) {
                $record = $table->getRow($r);
                if ($doimport) {
                    $DB->import_record($tablename, $record);
                } else {
                    $DB->insert_record($tablename, $record);
                }
            }
            if ($doimport) {
                $DB->get_manager()->reset_sequence(new xmldb_table($tablename));
            }
        }
    }