This commit is contained in:
parent
c26ed8441b
commit
9fcf6cc1b0
@ -32,84 +32,21 @@
|
||||
*/
|
||||
class Doctrine_Import_TestCase extends Doctrine_UnitTestCase
|
||||
{
|
||||
|
||||
|
||||
public function prepareTables()
|
||||
{ }
|
||||
public function prepareData()
|
||||
{ }
|
||||
|
||||
public function setUp()
|
||||
public function testImport()
|
||||
{
|
||||
parent::setUp();
|
||||
$this->dbh = new PDO('sqlite::memory:');
|
||||
|
||||
//reading
|
||||
$reader = new Doctrine_Import_Reader_Db();
|
||||
$reader->setPdo($this->dbh);
|
||||
$this->schema = $reader->read();
|
||||
}
|
||||
$this->dbh->exec('CREATE TABLE import_test_user (id INTEGER PRIMARY KEY, name TEXT)');
|
||||
|
||||
public function testBadImport()
|
||||
{
|
||||
$builder = new Doctrine_Import_Builder();
|
||||
$this->conn = Doctrine_Manager::connection($this->dbh);
|
||||
|
||||
try {
|
||||
$builder->buildRecord(new Doctrine_Schema_Table());
|
||||
$this->conn->import->import('Import/_files');
|
||||
|
||||
$this->fail();
|
||||
} catch(Doctrine_Import_Builder_Exception $e) {
|
||||
$this->pass();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function testImportTable()
|
||||
{
|
||||
$definition = array('name' => 'import_test');
|
||||
|
||||
$table = new Doctrine_Schema_Table($definition);
|
||||
$def = array('name' => 'name',
|
||||
'type' => 'string',
|
||||
'length' => 20,
|
||||
'default' => 'someone');
|
||||
|
||||
$table->addColumn(new Doctrine_Schema_Column($def));
|
||||
|
||||
$def = array('name' => 'created',
|
||||
'type' => 'integer',
|
||||
'notnull' => true);
|
||||
|
||||
$table->addColumn(new Doctrine_Schema_Column($def));
|
||||
|
||||
$builder = new Doctrine_Import_Builder();
|
||||
|
||||
$builder->setTargetPath('tmp');
|
||||
try {
|
||||
$builder->buildRecord($table);
|
||||
|
||||
$this->pass();
|
||||
} catch(Doctrine_Import_Builder_Exception $e) {
|
||||
$this->fail();
|
||||
}
|
||||
$this->assertTrue(file_exists('tmp' . DIRECTORY_SEPARATOR . 'ImportTest.php'));
|
||||
}
|
||||
public function testImportedComponent()
|
||||
{
|
||||
require_once('tmp' . DIRECTORY_SEPARATOR . 'ImportTest.php');
|
||||
|
||||
$r = new ImportTest();
|
||||
$columns = $r->getTable()->getColumns();
|
||||
|
||||
// id column is auto-created
|
||||
|
||||
$this->assertEqual($columns['id'][0], 'integer');
|
||||
$this->assertEqual($columns['id'][1], 20);
|
||||
|
||||
$this->assertEqual($columns['name'][0], 'string');
|
||||
$this->assertEqual($columns['name'][1], 20);
|
||||
|
||||
$this->assertEqual($columns['created'][0], 'integer');
|
||||
|
||||
unlink('tmp' . DIRECTORY_SEPARATOR . 'ImportTest.php');
|
||||
$this->assertTrue(file_exists('Import/_files/ImportTestUser.php'));
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user