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);
 }
Beispiel #3
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');
 }