You can incrementally add CSV files as tables to your datasets
Author: Mike Lively (m@digitalsandwich.com)
Inheritance: extends PHPUnit_Extensions_Database_DataSet_AbstractDataSet
 public function testForce()
 {
     $this->commandTester->execute(array('command' => 'metadata:load', '--path' => __DIR__ . '/metadata/fake_sugar', '--metadata-file' => $this->getYamlFilename(MetadataTestCase::METADATA_NEW), '--force' => null));
     $expected = new \PHPUnit_Extensions_Database_DataSet_YamlDataSet($this->getYamlFilename(MetadataTestCase::DB_NEW_DATASET));
     $queryTable = $this->getConnection()->createQueryTable('fields_meta_data', 'SELECT * FROM fields_meta_data ORDER BY BINARY id ASC');
     $this->assertTablesEqual($expected->getTable('fields_meta_data'), $queryTable);
 }
 public function testRealDb()
 {
     $meta = new Relationship(new NullLogger(), $this->getPdo());
     $db = $meta->loadFromDb();
     $meta->setDefFile(__DIR__ . '/relationships/metadata_base.yaml');
     $base = $meta->loadFromFile();
     $this->assertEquals($base, $db);
     $meta->setDefFile(__DIR__ . '/relationships/metadata_new.yaml');
     $new = $meta->loadFromFile();
     $diff = $meta->diff($base, $new);
     $meta->executeQueries($diff);
     $expected = new \PHPUnit_Extensions_Database_DataSet_YamlDataSet(__DIR__ . '/relationships/db_new_dataset.yaml');
     $queryTable = $this->getConnection()->createQueryTable('relationships', 'SELECT * FROM relationships ORDER BY BINARY id ASC');
     $this->assertTablesEqual($expected->getTable('relationships'), $queryTable);
 }
Exemple #3
0
    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);
    }
 /**
  * Read everything from the datasets directory and insert into the db.
  */
 public function loadAllFixtures()
 {
     $fixturesDir = __DIR__ . '/../../fixtures';
     $this->getConnection()->getConnection()->query("SET FOREIGN_KEY_CHECKS = 0;");
     $xmlFiles = glob($fixturesDir . '/*.xml');
     foreach ($xmlFiles as $xmlFixture) {
         $op = new PHPUnit_Extensions_Database_Operation_Insert();
         $dataset = $this->createXMLDataSet($xmlFixture);
         $this->_tablesToTruncate = array_merge($this->_tablesToTruncate, $dataset->getTableNames());
         $op->execute($this->_dbconn, $dataset);
     }
     $yamlFiles = glob($fixturesDir . '/*.yaml');
     foreach ($yamlFiles as $yamlFixture) {
         $op = new PHPUnit_Extensions_Database_Operation_Insert();
         $dataset = new PHPUnit_Extensions_Database_DataSet_YamlDataSet($yamlFixture);
         $this->_tablesToTruncate = array_merge($this->_tablesToTruncate, $dataset->getTableNames());
         $op->execute($this->_dbconn, $dataset);
     }
     $this->getConnection()->getConnection()->query("SET FOREIGN_KEY_CHECKS = 1;");
 }
Exemple #5
0
 /**
  * Test for `Schema::create()`.
  *
  * @since 1.0.0
  * @access public
  *
  * @requires function Freyja\Database\Schema\Schema::__construct
  * @requires function Freyja\Database\Database::__construct
  * @requires function Freyja\Database\Database::connect
  * @requires function Freyja\Database\Driver\MySqlDriver::connect
  * @requires function Freyja\Database\Schema\Schema::create
  */
 public function testCreate()
 {
     // Load data.
     $ds = $this->getDataSet(array('customers'));
     $this->loadDataSet($ds);
     // Set accessbiility to object property.
     $reflection_schema = new ReflectionProperty('Freyja\\Database\\Schema\\Schema', 'schema');
     $reflection_schema->setAccessible(true);
     $prod_id = new Field('product_id');
     $prod_id->varchar(200);
     $name = new Field('name');
     $name->varchar(200);
     $quantity = new Field('quantity');
     $quantity->varchar(200);
     $prods = new Table('products', array($prod_id, $name, $quantity));
     $db = new Database(new MySqlDriver());
     $schema = new Schema($db->connect('localhost', 'test', 'travis', ''));
     $schema->create($prods);
     $query = new MySqlQuery();
     $query->table('products')->insert(array('product_id', 'name', 'quantity'), array(array(null, null, null)));
     $db->execute($query);
     $query_table = $this->getConnection()->createQueryTable('products', 'SELECT * FROM products');
     $expected_table = new \PHPUnit_Extensions_Database_DataSet_YamlDataSet(dirname(__FILE__) . '/fixtures/products.yml');
     $this->assertTablesEqual($query_table, $expected_table->getTable('products'));
     $expected_schema = array('fields' => array('product_id' => array('type' => 'VARCHAR(200)', 'default' => null, 'NOT NULL' => false, 'UNSIGNED' => false, 'AUTO_INCREMENT' => false), 'name' => array('type' => 'VARCHAR(200)', 'default' => null, 'NOT NULL' => false, 'UNSIGNED' => false, 'AUTO_INCREMENT' => false), 'quantity' => array('type' => 'VARCHAR(200)', 'default' => null, 'NOT NULL' => false, 'UNSIGNED' => false, 'AUTO_INCREMENT' => false)), 'primary' => array(), 'foreign' => array(), 'charset' => 'utf8', 'collation' => 'utf8_unicode_ci', 'engine' => 'InnoDB');
     $retr_schema = $reflection_schema->getValue($schema);
     $this->assertEquals($expected_schema, $retr_schema['tables']['products'], 'Failed asserting that Schema::create() correctly update the database schema.');
     $this->getConnection()->getConnection()->exec('DROP TABLE IF EXISTS products');
 }