getTable() public method

Returns a table object for the given table.
public getTable ( string $tableName ) : PHPUnit_Extensions_Database_DataSet_ITable
$tableName string
return PHPUnit_Extensions_Database_DataSet_ITable
 /**
  * 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;
 }
Esempio n. 3
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;
 }
Esempio n. 4
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));
            }
        }
    }