Exemplo n.º 1
0
 public function testBuildCreateTable()
 {
     $schema = new Schema('foobar');
     $schema->addColumn('column', ['type' => 'int', 'ai' => true]);
     $query = new Query(Query::CREATE_TABLE, new User());
     $query->schema($schema);
     $this->assertRegExp('/CREATE\\s+TABLE IF NOT EXISTS (`|\\")?foobar(`|\\")? \\(\\n(`|\\")?column(`|\\")? INT NOT NULL AUTO_INCREMENT\\n\\);/', $this->object->buildCreateTable($query));
     $schema->addColumn('column', ['type' => 'int', 'ai' => true, 'primary' => true]);
     $this->assertRegExp('/CREATE\\s+TABLE IF NOT EXISTS (`|\\")?foobar(`|\\")? \\(\\n(`|\\")?column(`|\\")? INT NOT NULL AUTO_INCREMENT,\\nPRIMARY KEY \\((`|\\")?column(`|\\")?\\)\\n\\);/', $this->object->buildCreateTable($query));
     $schema->addColumn('column2', ['type' => 'int', 'null' => true, 'index' => true]);
     $this->assertRegExp('/CREATE\\s+TABLE IF NOT EXISTS (`|\\")?foobar(`|\\")? \\(\\n(`|\\")?column(`|\\")? INT NOT NULL AUTO_INCREMENT,\\n(`|\\")?column2(`|\\")? INT NULL,\\nPRIMARY KEY \\((`|\\")?column(`|\\")?\\)\\n\\);/', $this->object->buildCreateTable($query));
     $schema->addOption('engine', 'InnoDB');
     $this->assertRegExp('/CREATE\\s+TABLE IF NOT EXISTS (`|\\")?foobar(`|\\")? \\(\\n(`|\\")?column(`|\\")? INT NOT NULL AUTO_INCREMENT,\\n(`|\\")?column2(`|\\")? INT NULL,\\nPRIMARY KEY \\((`|\\")?column(`|\\")?\\)\\n\\) ENGINE InnoDB;/', $this->object->buildCreateTable($query));
 }