addRow() public method

Adds a row to the table with optional values.
public addRow ( array $values = [] )
$values array
コード例 #1
0
 public function testGetTable_b()
 {
     $expected = new PHPUnit_Extensions_Database_DataSet_DefaultTable(new PHPUnit_Extensions_Database_DataSet_DefaultTableMetaData('table_b', array('id', 'pet')));
     $expected->addRow(array('id' => 1, 'pet' => 'dog'));
     $expected->addRow(array('id' => 2, 'pet' => 'cat'));
     $this->assertThat($this->data_set->getTable('table_b'), new PHPUnit_Extensions_Database_Constraint_TableIsEqual($expected));
 }
コード例 #2
0
 public function testAssertEqualsFails()
 {
     $expected_table = new PHPUnit_Extensions_Database_DataSet_DefaultTable(new PHPUnit_Extensions_Database_DataSet_DefaultTableMetaData('table1', array('col1', 'col2', 'col3')));
     $expected_table->addRow(array('col1' => 'value1', 'col2' => 'value2', 'col3' => 'value3'));
     $expected_table->addRow(array('col1' => 'value4', 'col2' => 'value5', 'col3' => 'value6'));
     $expected_table->addRow(array('col1' => 'value7', 'col2' => 'value8', 'col3' => 'value9'));
     $this->assertFalse($this->table->matches($expected_table));
 }
コード例 #3
0
 public function testConstructorReplacements()
 {
     $tableMetaData = new PHPUnit_Extensions_Database_DataSet_DefaultTableMetaData('table1', array('table1_id', 'column1', 'column2', 'column3', 'column4'));
     $table = new PHPUnit_Extensions_Database_DataSet_DefaultTable($tableMetaData);
     $table->addRow(array('table1_id' => 1, 'column1' => 'My name is Mike Lively', 'column2' => 200, 'column3' => 34.64, 'column4' => 'yghkf;a  hahfg8ja h;'));
     $table->addRow(array('table1_id' => 2, 'column1' => 'hk;afg', 'column2' => 654, 'column3' => 46.54, 'column4' => '24rwehhads'));
     $table->addRow(array('table1_id' => 3, 'column1' => 'ha;gyt', 'column2' => 462, 'column3' => '[NULL] not really', 'column4' => NULL));
     $actual = new PHPUnit_Extensions_Database_DataSet_ReplacementTable($this->startingTable, array('[NULL]' => NULL), array('%%%name%%%' => 'Mike Lively'));
     PHPUnit_Extensions_Database_TestCase::assertTablesEqual($table, $actual);
 }
コード例 #4
0
 public function setUp()
 {
     $table1MetaData = new PHPUnit_Extensions_Database_DataSet_DefaultTableMetaData('table1', array('table1_id', 'column1', 'column2', 'column3', 'column4'));
     $table2MetaData = new PHPUnit_Extensions_Database_DataSet_DefaultTableMetaData('table2', array('table2_id', 'column5', 'column6', 'column7', 'column8'));
     $table1 = new PHPUnit_Extensions_Database_DataSet_DefaultTable($table1MetaData);
     $table2 = new PHPUnit_Extensions_Database_DataSet_DefaultTable($table2MetaData);
     $table1->addRow(array('table1_id' => 1, 'column1' => 'tgfahgasdf', 'column2' => 200, 'column3' => 34.64, 'column4' => 'yghkf;a  hahfg8ja h;'));
     $table1->addRow(array('table1_id' => 2, 'column1' => 'hk;afg', 'column2' => 654, 'column3' => 46.54, 'column4' => '24rwehhads'));
     $table1->addRow(array('table1_id' => 3, 'column1' => 'ha;gyt', 'column2' => 462, 'column3' => 1654.4, 'column4' => 'asfgklg'));
     $table2->addRow(array('table2_id' => 1, 'column5' => 'fhah', 'column6' => 456, 'column7' => 46.5, 'column8' => 'fsdbghfdas'));
     $table2->addRow(array('table2_id' => 2, 'column5' => 'asdhfoih', 'column6' => 654, 'column7' => NULL, 'column8' => '43asdfhgj'));
     $table2->addRow(array('table2_id' => 3, 'column5' => 'ajsdlkfguitah', 'column6' => 654, 'column7' => NULL, 'column8' => NULL));
     $this->expectedDataSet = new PHPUnit_Extensions_Database_DataSet_DefaultDataSet(array($table1, $table2));
 }
コード例 #5
0
 public function testConstructorReplacements()
 {
     $table1MetaData = new PHPUnit_Extensions_Database_DataSet_DefaultTableMetaData('table1', array('table1_id', 'column1', 'column2', 'column3', 'column4'));
     $table2MetaData = new PHPUnit_Extensions_Database_DataSet_DefaultTableMetaData('table2', array('table2_id', 'column5', 'column6', 'column7', 'column8'));
     $table1 = new PHPUnit_Extensions_Database_DataSet_DefaultTable($table1MetaData);
     $table2 = new PHPUnit_Extensions_Database_DataSet_DefaultTable($table2MetaData);
     $table1->addRow(array('table1_id' => 1, 'column1' => 'My name is Mike Lively', 'column2' => 200, 'column3' => 34.64, 'column4' => 'yghkf;a  hahfg8ja h;'));
     $table1->addRow(array('table1_id' => 2, 'column1' => 'hk;afg', 'column2' => 654, 'column3' => 46.54, 'column4' => '24rwehhads'));
     $table1->addRow(array('table1_id' => 3, 'column1' => 'ha;gyt', 'column2' => 462, 'column3' => 1654.4, 'column4' => NULL));
     $table2->addRow(array('table2_id' => 1, 'column5' => 'fhah', 'column6' => 456, 'column7' => 46.5, 'column8' => 'My name is Mike Lively'));
     $table2->addRow(array('table2_id' => 2, 'column5' => 'asdhfoih', 'column6' => 654, 'column7' => NULL, 'column8' => '43asdfhgj'));
     $table2->addRow(array('table2_id' => 3, 'column5' => 'ajsdlkfguitah', 'column6' => 654, 'column7' => NULL, 'column8' => '[NULL] not really'));
     $expected = new PHPUnit_Extensions_Database_DataSet_DefaultDataSet(array($table1, $table2));
     $actual = new PHPUnit_Extensions_Database_DataSet_ReplacementDataSet($this->startingDataSet, array('[NULL]' => NULL), array('%%%name%%%' => 'Mike Lively'));
     PHPUnit_Extensions_Database_TestCase::assertDataSetsEqual($expected, $actual);
 }
コード例 #6
0
 /**
  * Construct a new PHPUnit_ArrayDataSet object.
  * @param array $data An array of data.
  * @param True if the data array is a result of a PDO query, false otherwise.
  */
 public function __construct(array $data, $pdo = false)
 {
     if ($pdo) {
         $tableName = 'Table';
         $columns = array();
         if (isset($data[0])) {
             $columns = array_keys(get_object_vars($data[0]));
         }
         $metaData = new PHPUnit_Extensions_Database_DataSet_DefaultTableMetaData($tableName, $columns);
         $table = new PHPUnit_Extensions_Database_DataSet_DefaultTable($metaData);
         foreach ($data as $row) {
             $table->addRow(get_object_vars($row));
         }
         $this->tables[$tableName] = $table;
     } else {
         foreach ($data as $tableName => $rows) {
             $columns = array();
             if (isset($rows[0])) {
                 $columns = array_keys($rows[0]);
             }
             $metaData = new PHPUnit_Extensions_Database_DataSet_DefaultTableMetaData($tableName, $columns);
             $table = new PHPUnit_Extensions_Database_DataSet_DefaultTable($metaData);
             foreach ($rows as $row) {
                 $table->addRow($row);
             }
             $this->tables[$tableName] = $table;
         }
     }
 }
コード例 #7
0
ファイル: arraydataset.php プロジェクト: evltuma/moodle
 /**
  * @param array $data
  */
 public function __construct(array $data)
 {
     foreach ($data as $tableName => $rows) {
         $firstrow = reset($rows);
         if (array_key_exists(0, $firstrow)) {
             // columns in first row
             $columnsInFirstRow = true;
             $columns = $firstrow;
             $key = key($rows);
             unset($rows[$key]);
         } else {
             // column name is in each row as key
             $columnsInFirstRow = false;
             $columns = array_keys($firstrow);
         }
         $metaData = new PHPUnit_Extensions_Database_DataSet_DefaultTableMetaData($tableName, $columns);
         $table = new PHPUnit_Extensions_Database_DataSet_DefaultTable($metaData);
         foreach ($rows as $row) {
             if ($columnsInFirstRow) {
                 $row = array_combine($columns, $row);
             }
             $table->addRow($row);
         }
         $this->tables[$tableName] = $table;
     }
 }
コード例 #8
0
 /**
  * @expectedException           InvalidArgumentException
  * @expectedExceptionMessage    There is already a table named table3 with different table definition
  */
 public function testExceptionOnIncompatibleTablesSameTableNames2()
 {
     $inCompatibleTableMetaData = new PHPUnit_Extensions_Database_DataSet_DefaultTableMetaData('table3', array('table3_id', 'column13', 'column14', 'column15', 'column16'));
     $inCompatibleTable = new PHPUnit_Extensions_Database_DataSet_DefaultTable($inCompatibleTableMetaData);
     $inCompatibleTable->addRow(array('column13' => 'asdasda asdasd', 'column14' => 'aiafsjas asd', 'column15' => 'asdasdasd', 'column16' => 2141));
     $compositeDataSet = new PHPUnit_Extensions_Database_DataSet_CompositeDataSet(array(new PHPUnit_Extensions_Database_DataSet_DefaultDataSet(array($inCompatibleTable)), $this->expectedDataSet2));
 }
コード例 #9
0
ファイル: YamlDataSetTest.php プロジェクト: naderman/dbunit
    public function testYamlDataSet()
    {
        $table1MetaData = new PHPUnit_Extensions_Database_DataSet_DefaultTableMetaData('table1', array('table1_id', 'column1', 'column2', 'column3', 'column4'));
        $table2MetaData = new PHPUnit_Extensions_Database_DataSet_DefaultTableMetaData('table2', array('table2_id', 'column5', 'column6', 'column7', 'column8'));
        $table1 = new PHPUnit_Extensions_Database_DataSet_DefaultTable($table1MetaData);
        $table2 = new PHPUnit_Extensions_Database_DataSet_DefaultTable($table2MetaData);
        $table1->addRow(array('table1_id' => 1, 'column1' => 'tgfahgasdf', 'column2' => 200, 'column3' => 34.64, 'column4' => 'yghkf;a  hahfg8ja h;'));
        $table1->addRow(array('table1_id' => 2, 'column1' => 'hk;afg', 'column2' => 654, 'column3' => 46.54, 'column4' => '24rwehhads'));
        $table1->addRow(array('table1_id' => 3, 'column1' => 'ha;gyt', 'column2' => 462, 'column3' => 1654.4, 'column4' => 'asfgklg'));
        $table2->addRow(array('table2_id' => 1, 'column5' => 'fhah', 'column6' => 456, 'column7' => 46.5, 'column8' => 'fsdb, ghfdas'));
        $table2->addRow(array('table2_id' => 2, 'column5' => 'asdhfoih', 'column6' => 654, 'column7' => 'blah', 'column8' => '43asd "fhgj" sfadh'));
        $table2->addRow(array('table2_id' => 3, 'column5' => 'ajsdlkfguitah', 'column6' => 654, 'column7' => 'blah', 'column8' => 'thesethasdl
asdflkjsadf asdfsadfhl "adsf, halsdf" sadfhlasdf'));
        $expectedDataSet = new PHPUnit_Extensions_Database_DataSet_DefaultDataSet(array($table1, $table2));
        $yamlDataSet = new PHPUnit_Extensions_Database_DataSet_YamlDataSet(dirname(__FILE__) . '/../_files/YamlDataSets/testDataSet.yaml');
        PHPUnit_Extensions_Database_DataSet_YamlDataSet::write($yamlDataSet, '/tmp/yaml.dataset');
        PHPUnit_Extensions_Database_TestCase::assertDataSetsEqual($expectedDataSet, $yamlDataSet);
    }
コード例 #10
0
    public function testCSVDataSet()
    {
        $table1MetaData = new PHPUnit_Extensions_Database_DataSet_DefaultTableMetaData('table1', ['table1_id', 'column1', 'column2', 'column3', 'column4']);
        $table2MetaData = new PHPUnit_Extensions_Database_DataSet_DefaultTableMetaData('table2', ['table2_id', 'column5', 'column6', 'column7', 'column8']);
        $table1 = new PHPUnit_Extensions_Database_DataSet_DefaultTable($table1MetaData);
        $table2 = new PHPUnit_Extensions_Database_DataSet_DefaultTable($table2MetaData);
        $table1->addRow(['table1_id' => 1, 'column1' => 'tgfahgasdf', 'column2' => 200, 'column3' => 34.64, 'column4' => 'yghkf;a  hahfg8ja h;']);
        $table1->addRow(['table1_id' => 2, 'column1' => 'hk;afg', 'column2' => 654, 'column3' => 46.54, 'column4' => '24rwehhads']);
        $table1->addRow(['table1_id' => 3, 'column1' => 'ha;gyt', 'column2' => 462, 'column3' => 1654.4, 'column4' => 'asfgklg']);
        $table2->addRow(['table2_id' => 1, 'column5' => 'fhah', 'column6' => 456, 'column7' => 46.5, 'column8' => 'fsdb, ghfdas']);
        $table2->addRow(['table2_id' => 2, 'column5' => 'asdhfoih', 'column6' => 654, 'column7' => 'blah', 'column8' => '43asd "fhgj" sfadh']);
        $table2->addRow(['table2_id' => 3, 'column5' => 'ajsdlkfguitah', 'column6' => 654, 'column7' => 'blah', 'column8' => 'thesethasdl
asdflkjsadf asdfsadfhl "adsf, halsdf" sadfhlasdf']);
        $expectedDataSet = new PHPUnit_Extensions_Database_DataSet_DefaultDataSet([$table1, $table2]);
        $csvDataSet = new PHPUnit_Extensions_Database_DataSet_CsvDataSet();
        $csvDataSet->addTable('table1', dirname(__FILE__) . '/../_files/CsvDataSets/table1.csv');
        $csvDataSet->addTable('table2', dirname(__FILE__) . '/../_files/CsvDataSets/table2.csv');
        PHPUnit_Extensions_Database_TestCase::assertDataSetsEqual($expectedDataSet, $csvDataSet);
    }
コード例 #11
0
 public function testAlternateParser()
 {
     $table1MetaData = new PHPUnit_Extensions_Database_DataSet_DefaultTableMetaData('math_table', ['answer']);
     $table1 = new PHPUnit_Extensions_Database_DataSet_DefaultTable($table1MetaData);
     $table1->addRow(['answer' => 'pi/2']);
     $expectedDataSet = new PHPUnit_Extensions_Database_DataSet_DefaultDataSet([$table1]);
     $parser = new Extensions_Database_DataSet_YamlDataSetTest_PiOver2Parser();
     $yamlDataSet = new PHPUnit_Extensions_Database_DataSet_YamlDataSet(dirname(__FILE__) . '/../_files/YamlDataSets/testDataSet.yaml', $parser);
     PHPUnit_Extensions_Database_TestCase::assertDataSetsEqual($expectedDataSet, $yamlDataSet);
 }
コード例 #12
0
 /**
  * @param array $data
  */
 public function __construct(array $data)
 {
     foreach ($data as $tableName => $rows) {
         $meta = new \PHPUnit_Extensions_Database_DataSet_DefaultTableMetaData($tableName, isset($rows[0]) ? array_keys($rows[0]) : array());
         $table = new \PHPUnit_Extensions_Database_DataSet_DefaultTable($meta);
         foreach ($rows as $row) {
             $table->addRow($row);
         }
         $this->_tables[$tableName] = $table;
     }
 }
コード例 #13
0
 public function __construct(array $data, array $tables = array())
 {
     $this->tables = $tables;
     foreach ($data as $table_name => $rows) {
         $table = new PHPUnit_Extensions_Database_DataSet_DefaultTable(new PHPUnit_Extensions_Database_DataSet_DefaultTableMetaData($table_name, $this->getColumns($rows)));
         foreach ($rows as $row) {
             $table->addRow($row);
         }
         $this->tables[$table_name] = $table;
     }
 }
コード例 #14
0
 public function testEntitiesXml()
 {
     $metaData = new PHPUnit_Extensions_Database_DataSet_DefaultTableMetaData('table1', array('col1', 'col2'), array('col1'));
     $table = new PHPUnit_Extensions_Database_DataSet_DefaultTable($metaData);
     $table->addRow(array('col1' => 1, 'col2' => '<?xml version="1.0"?><myxml>test</myxml>'));
     $dataSet = new PHPUnit_Extensions_Database_DataSet_DefaultDataSet(array($table));
     $expectedFile = dirname(__FILE__) . '/../_files/XmlDataSets/XmlWriterEntities.xml';
     $filename = dirname(__FILE__) . '/' . uniqid() . '.xml';
     PHPUnit_Extensions_Database_DataSet_XmlDataSet::write($dataSet, $filename);
     $this->assertXmlFileEqualsXmlFile($expectedFile, $filename);
     unlink($filename);
 }
コード例 #15
0
ファイル: DbAssertions.php プロジェクト: noikiy/tools
 private function _arrayToDataSet(array $toConvert, $tableName = 'theTable')
 {
     $columns = array();
     if (isset($toConvert[0])) {
         $columns = array_keys($toConvert[0]);
     }
     $metaData = new PHPUnit_Extensions_Database_DataSet_DefaultTableMetaData($tableName, $columns);
     $table = new PHPUnit_Extensions_Database_DataSet_DefaultTable($metaData);
     foreach ($toConvert as $row) {
         $table->addRow($row);
     }
     return $table;
 }
コード例 #16
0
    public function setUp()
    {
        $table1MetaData = new PHPUnit_Extensions_Database_DataSet_DefaultTableMetaData('table1', array('table1_id', 'column1', 'column2', 'column3', 'column4'));
        $table2MetaData = new PHPUnit_Extensions_Database_DataSet_DefaultTableMetaData('table2', array('table2_id', 'column5', 'column6', 'column7', 'column8'));
        $table3MetaData = new PHPUnit_Extensions_Database_DataSet_DefaultTableMetaData('table3', array('table3_id', 'column9', 'column10', 'column11', 'column12'));
        $table1 = new PHPUnit_Extensions_Database_DataSet_DefaultTable($table1MetaData);
        $table2 = new PHPUnit_Extensions_Database_DataSet_DefaultTable($table2MetaData);
        $table3 = new PHPUnit_Extensions_Database_DataSet_DefaultTable($table3MetaData);
        $table1->addRow(array('table1_id' => 1, 'column1' => 'tgfahgasdf', 'column2' => 200, 'column3' => 34.64, 'column4' => 'yghkf;a  hahfg8ja h;'));
        $table1->addRow(array('table1_id' => 2, 'column1' => 'hk;afg', 'column2' => 654, 'column3' => 46.54, 'column4' => '24rwehhads'));
        $table1->addRow(array('table1_id' => 3, 'column1' => 'ha;gyt', 'column2' => 462, 'column3' => 1654.4, 'column4' => 'asfgklg'));
        $table2->addRow(array('table2_id' => 1, 'column5' => 'fhah', 'column6' => 456, 'column7' => 46.5, 'column8' => 'fsdb, ghfdas'));
        $table2->addRow(array('table2_id' => 2, 'column5' => 'asdhfoih', 'column6' => 654, 'column7' => 'blah', 'column8' => '43asd "fhgj" sfadh'));
        $table2->addRow(array('table2_id' => 3, 'column5' => 'ajsdlkfguitah', 'column6' => 654, 'column7' => 'blah', 'column8' => 'thesethasdl
asdflkjsadf asdfsadfhl "adsf, halsdf" sadfhlasdf'));
        $table3->addRow(array('table3_id' => 1, 'column9' => 'sfgsda', 'column10' => 16, 'column11' => 45.57, 'column12' => 'sdfh .ds,ajfas asdf h'));
        $table3->addRow(array('table3_id' => 2, 'column9' => 'afdstgb', 'column10' => 41, 'column11' => 46.645, 'column12' => '87yhasdf sadf yah;/a '));
        $table3->addRow(array('table3_id' => 3, 'column9' => 'gldsf', 'column10' => 46, 'column11' => 123.456, 'column12' => '0y8hosnd a/df7y olgbjs da'));
        $this->expectedDataSet1 = new PHPUnit_Extensions_Database_DataSet_DefaultDataSet(array($table1, $table2));
        $this->expectedDataSet2 = new PHPUnit_Extensions_Database_DataSet_DefaultDataSet(array($table3));
        $this->expectedDataSet3 = new PHPUnit_Extensions_Database_DataSet_DefaultDataSet(array($table1, $table2, $table3));
    }
コード例 #17
0
ファイル: ArraySet.php プロジェクト: swansoft/swanphp
 /**
  * __construct
  *
  * @param array $data
  * @access public
  * @return void
  */
 public function __construct(array $data)
 {
     foreach ($data as $table_name => $rows) {
         $columns = array();
         if (isset($rows[0])) {
             $columns = array_keys($rows[0]);
         }
         $meta_data = new \PHPUnit_Extensions_Database_DataSet_DefaultTableMetaData($table_name, $columns);
         $table = new \PHPUnit_Extensions_Database_DataSet_DefaultTable($meta_data);
         foreach ($rows as $row) {
             $table->addRow($row);
         }
         $this->__tables[$table_name] = $table;
     }
 }
コード例 #18
0
ファイル: ArrayDataSet.php プロジェクト: cspray/dupp
 /**
  * @param array $data
  */
 public function __construct(array $data)
 {
     foreach ($data as $tableName => $rows) {
         $columns = [];
         if (isset($rows[0])) {
             $columns = array_keys($rows[0]);
         }
         $metaData = new DbUnitTableMetaData($tableName, $columns);
         $table = new DbUnitTable($metaData);
         foreach ($rows as $row) {
             $table->addRow($row);
         }
         $this->tables[$tableName] = $table;
     }
 }
コード例 #19
0
ファイル: PsvDataSet.php プロジェクト: noikiy/tools
 /**
  * @param array $data
  */
 public function __construct($psvContent)
 {
     $this->psvParser = new PsvParser();
     $psvTree = $this->psvParser->parsePsvTree($psvContent);
     foreach ($psvTree as $tableName => $rows) {
         $columns = array();
         if (isset($rows[0])) {
             $columns = array_keys($rows[0]);
         }
         $metaData = new \PHPUnit_Extensions_Database_DataSet_DefaultTableMetaData($tableName, $columns);
         $table = new \PHPUnit_Extensions_Database_DataSet_DefaultTable($metaData);
         foreach ($rows as $row) {
             $table->addRow($row);
         }
         $this->tables[$tableName] = $table;
     }
 }
コード例 #20
0
 public function testCreateIterator()
 {
     $expectedTable1 = $this->getConnection()->createDataSet(['table1'])->getTable('table1');
     $expectedTable2 = new PHPUnit_Extensions_Database_DataSet_DefaultTable(new PHPUnit_Extensions_Database_DataSet_DefaultTableMetaData('query1', ['tc1', 'tc2']));
     $expectedTable2->addRow(['tc1' => 'bar', 'tc2' => 'blah']);
     foreach ($this->dataSet as $i => $table) {
         /* @var $table PHPUnit_Extensions_Database_DataSet_ITable */
         switch ($table->getTableMetaData()->getTableName()) {
             case 'table1':
                 $this->assertTablesEqual($expectedTable1, $table);
                 break;
             case 'query1':
                 $this->assertTablesEqual($expectedTable2, $table);
                 break;
             default:
                 $this->fail('Proper keys not present from the iterator');
         }
     }
 }
コード例 #21
0
 /**
  * Adds a table to the dataset
  *
  * The table will be given the passed name. $csvFile should be a path to
  * a valid csv file (based on the arguments passed to the constructor.)
  *
  * @param string $tableName
  * @param string $csvFile
  */
 public function addTable($tableName, $csvFile)
 {
     if (!is_file($csvFile)) {
         throw new InvalidArgumentException("Could not find csv file: {$csvFile}");
     }
     if (!is_readable($csvFile)) {
         throw new InvalidArgumentException("Could not read csv file: {$csvFile}");
     }
     $fh = fopen($csvFile, 'r');
     $columns = $this->getCsvRow($fh);
     if ($columns === FALSE) {
         throw new InvalidArgumentException("Could not determine the headers from the given file {$csvFile}");
     }
     $metaData = new PHPUnit_Extensions_Database_DataSet_DefaultTableMetaData($tableName, $columns);
     $table = new PHPUnit_Extensions_Database_DataSet_DefaultTable($metaData);
     while (($row = $this->getCsvRow($fh)) !== FALSE) {
         $table->addRow(array_combine($columns, $row));
     }
     $this->tables[$tableName] = $table;
 }
コード例 #22
0
 public function testExecute()
 {
     $connection = $this->getConnection();
     /* @var $connection PHPUnit_Extensions_Database_DB_DefaultDatabaseConnection */
     $table1 = new PHPUnit_Extensions_Database_DataSet_DefaultTable(new PHPUnit_Extensions_Database_DataSet_DefaultTableMetaData('table1', array('table1_id', 'column1', 'column2', 'column3', 'column4')));
     $table1->addRow(array('table1_id' => 1, 'column1' => 'foo', 'column2' => 42, 'column3' => 4.2, 'column4' => 'bar'));
     $table1->addRow(array('table1_id' => 2, 'column1' => 'qwerty', 'column2' => 23, 'column3' => 2.3, 'column4' => 'dvorak'));
     $table2 = new PHPUnit_Extensions_Database_DataSet_DefaultTable(new PHPUnit_Extensions_Database_DataSet_DefaultTableMetaData('table2', array('table2_id', 'column5', 'column6', 'column7', 'column8')));
     $table2->addRow(array('table2_id' => 1, 'column5' => 'fdyhkn', 'column6' => 64, 'column7' => 4568.64, 'column8' => 'hkladfg'));
     $dataSet = new PHPUnit_Extensions_Database_DataSet_DefaultDataSet(array($table1, $table2));
     $mockOperation = $this->getMock('PHPUnit_Extensions_Database_Operation_RowBased', array('buildOperationQuery', 'buildOperationArguments'));
     /* @var $mockOperation PHPUnit_Framework_MockObject_MockObject */
     $mockOperation->expects($this->at(0))->method('buildOperationQuery')->with($connection->createDataSet()->getTableMetaData('table1'), $table1)->will($this->returnValue('INSERT INTO table1 (table1_id, column1, column2, column3, column4) VALUES (?, ?, ?, ?, ?)'));
     $mockOperation->expects($this->at(1))->method('buildOperationArguments')->with($connection->createDataSet()->getTableMetaData('table1'), $table1, 0)->will($this->returnValue(array(1, 'foo', 42, 4.2, 'bar')));
     $mockOperation->expects($this->at(2))->method('buildOperationArguments')->with($connection->createDataSet()->getTableMetaData('table1'), $table1, 1)->will($this->returnValue(array(2, 'qwerty', 23, 2.3, 'dvorak')));
     $mockOperation->expects($this->at(3))->method('buildOperationQuery')->with($connection->createDataSet()->getTableMetaData('table2'), $table2)->will($this->returnValue('INSERT INTO table2 (table2_id, column5, column6, column7, column8) VALUES (?, ?, ?, ?, ?)'));
     $mockOperation->expects($this->at(4))->method('buildOperationArguments')->with($connection->createDataSet()->getTableMetaData('table2'), $table2, 0)->will($this->returnValue(array(1, 'fdyhkn', 64, 4568.64, 'hkladfg')));
     /* @var $mockOperation PHPUnit_Extensions_Database_Operation_RowBased */
     $mockOperation->execute($connection, $dataSet);
     $this->assertDataSetsEqual(new PHPUnit_Extensions_Database_DataSet_FlatXmlDataSet(dirname(__FILE__) . '/../_files/XmlDataSets/RowBasedExecute.xml'), $connection->createDataSet(array('table1', 'table2')));
 }
コード例 #23
0
ファイル: QueryTableTest.php プロジェクト: AroundPBT/PHPBoost
 public function testAssertEqualsFails()
 {
     $this->setExpectedException('Exception', 'Expected row count of 2, has a row count of 3');
     $expected_table = new PHPUnit_Extensions_Database_DataSet_DefaultTable(new PHPUnit_Extensions_Database_DataSet_DefaultTableMetaData('table1', array('col1', 'col2', 'col3')));
     $expected_table->addRow(array('col1' => 'value1', 'col2' => 'value2', 'col3' => 'value3'));
     $expected_table->addRow(array('col1' => 'value4', 'col2' => 'value5', 'col3' => 'value6'));
     $expected_table->addRow(array('col1' => 'value7', 'col2' => 'value8', 'col3' => 'value9'));
     $this->table->assertEquals($expected_table);
 }
コード例 #24
0
 /**
  * @param array $category
  * @param array $expectedRow
  */
 public function updateOne($category, $expectedRow)
 {
     // Prepare expected data
     $columnsSelect = implode(', ', array_keys($expectedRow));
     $queryTableBefore = $this->getDatabaseTester()->getConnection()->createQueryTable($this->dbTable, 'SELECT ' . $columnsSelect . ' FROM ' . $this->dbTable);
     $rowCount = $queryTableBefore->getRowCount();
     $expectedTable = new \PHPUnit_Extensions_Database_DataSet_DefaultTable($queryTableBefore->getTableMetaData());
     for ($row = 0; $row < $rowCount; $row++) {
         $currentRow = $queryTableBefore->getRow($row);
         if ($currentRow['id'] == $expectedRow['id']) {
             $expectedTable->addRow($expectedRow);
         } else {
             $expectedTable->addRow($currentRow);
         }
     }
     // Start the action
     $dataFactory = $this->Plugin()->getDataFactory();
     $catDbAdapter = $dataFactory->createDbAdapter($this->dbAdapter);
     $catDbAdapter->write($category);
     // Assert
     $queryTable = $this->getDatabaseTester()->getConnection()->createQueryTable($this->dbTable, 'SELECT ' . $columnsSelect . ' FROM ' . $this->dbTable);
     $this->assertTablesEqual($expectedTable, $queryTable);
 }