1
0
mirror of synced 2025-02-01 04:51:45 +03:00

added new driver tests

This commit is contained in:
zYne 2006-11-22 23:35:34 +00:00
parent 9200d1271a
commit ec662f3ee4
6 changed files with 267 additions and 9 deletions

98
tests/DriverTestCase.php Normal file
View File

@ -0,0 +1,98 @@
<?php
class AdapterMock implements Doctrine_Adapter_Interface {
private $name;
private $queries = array();
public function __construct($name) {
$this->name = $name;
}
public function getName() {
return $this->name;
}
public function pop() {
return array_pop($this->queries);
}
public function prepare($prepareString){
return new AdapterStatementMock;
}
public function query($queryString) {
$this->queries[] = $queryString;
return new AdapterStatementMock;
}
public function quote($input){ }
public function exec($statement) {
$this->queries[] = $statement;
return 0;
}
public function lastInsertId(){ }
public function beginTransaction(){
$this->queries[] = 'BEGIN TRANSACTION';
}
public function commit(){
$this->queries[] = 'COMMIT';
}
public function rollBack(){ }
public function errorCode(){ }
public function errorInfo(){ }
public function getAttribute($attribute) {
if($attribute == PDO::ATTR_DRIVER_NAME)
return $this->name;
}
public function setAttribute($attribute, $value) {
}
}
class AdapterStatementMock {
public function fetch($fetchMode) {
return array();
}
public function fetchAll($fetchMode) {
return array();
}
}
class Doctrine_Driver_UnitTestCase extends UnitTestCase {
protected $driverName = false;
protected $generic = false;
protected $manager;
protected $conn;
protected $adapter;
protected $export;
protected $dataDict;
protected $transaction;
public function __construct($driverName, $generic = false) {
$this->driverName = $driverName;
$this->generic = $generic;
}
public function init() {
$this->adapter = new AdapterMock($this->driverName);
$this->manager = Doctrine_Manager::getInstance();
$this->manager->setDefaultAttributes();
$this->conn = $this->manager->openConnection($this->adapter);
if( ! $this->generic) {
$this->export = $this->conn->export;
$tx = 'Doctrine_Transaction_' . ucwords($this->adapter->getName());
if(class_exists($tx))
$this->transaction = new $tx($this->conn);
//$this->dataDict = $this->conn->dataDict;
} else {
$this->export = new Doctrine_Export($this->conn);
$this->transaction = new Doctrine_Transaction($this->conn);
}
}
public function setUp() {
static $init = false;
if( ! $init) {
$this->init();
$init = true;
}
}
}
?>

View File

@ -2,7 +2,26 @@
class Doctrine_Export_Mysql_TestCase extends Doctrine_Export_TestCase {
public function __construct() {
parent::__construct('mysql');
}
}
public function testAlterTableThrowsExceptionWithoutValidTableName() {
try {
$this->export->alterTable(0,0,array());
$this->fail();
} catch(Doctrine_Export_Exception $e) {
$this->pass();
}
}
public function testCreateTableExecutesSql() {
$name = 'mytable';
$fields = array('id' => array('type' => 'integer', 'unsigned' => 1));
$options = array('type' => 'foo');
//$this->export->createTable($name, $fields, $options);
}
public function testCreateDatabaseExecutesSql() {
$this->export->createDatabase('db');

View File

@ -0,0 +1,26 @@
<?php
class Doctrine_Export_Oracle_TestCase extends Doctrine_Export_TestCase {
public function __construct() {
parent::__construct('oci');
}
public function testCreateSequenceExecutesSql() {
$sequenceName = 'sequence';
$start = 1;
$query = 'CREATE SEQUENCE ' . $sequenceName . ' START WITH ' . $start . ' INCREMENT BY 1 NOCACHE';
$this->export->createSequence($sequenceName, $start);
$this->assertEqual($this->adapter->pop(), $query);
}
public function testDropSequenceExecutesSql() {
$sequenceName = 'sequence';
$query = 'DROP SEQUENCE ' . $sequenceName;;
$this->export->dropSequence($sequenceName);
$this->assertEqual($this->adapter->pop(), $query);
}
}
?>

View File

@ -1,15 +1,7 @@
<?php
class Doctrine_Export_TestCase extends Doctrine_Driver_UnitTestCase {
public function testAlterTableThrowsExceptionWithoutValidTableName() {
try {
$this->export->alterTable(0,0,array());
$this->fail();
} catch(Doctrine_Export_Exception $e) {
$this->pass();
}
}
public function testCreateTableThrowsExceptionWithoutValidTableName() {
try {
$this->export->createTable(0,array(),array());
@ -28,6 +20,11 @@ class Doctrine_Export_TestCase extends Doctrine_Driver_UnitTestCase {
$this->pass();
}
}
public function testDropConstraintExecutesSql() {
$this->export->dropConstraint('sometable', 'relevancy');
$this->assertEqual($this->adapter->pop(), 'ALTER TABLE sometable DROP CONSTRAINT relevancy');
}
public function testCreateIndexExecutesSql() {
$this->export->createIndex('sometable', 'relevancy', array('fields' => array('title' => array(), 'content' => array())));

View File

@ -0,0 +1,39 @@
<?php
class Doctrine_Transaction_Mysql_TestCase extends Doctrine_Driver_UnitTestCase {
public function __construct() {
parent::__construct('mysql');
}
public function testCreateSavePointExecutesSql() {
$this->transaction->createSavePoint('mypoint');
$this->assertEqual($this->adapter->pop(), 'SAVEPOINT mypoint');
}
public function testReleaseSavePointExecutesSql() {
$this->transaction->releaseSavePoint('mypoint');
$this->assertEqual($this->adapter->pop(), 'RELEASE SAVEPOINT mypoint');
}
public function testRollbackSavePointExecutesSql() {
$this->transaction->rollbackSavePoint('mypoint');
$this->assertEqual($this->adapter->pop(), 'ROLLBACK TO SAVEPOINT mypoint');
}
public function testGetIsolationExecutesSql() {
$this->transaction->getIsolation();
$this->assertEqual($this->adapter->pop(), 'SELECT @@tx_isolation');
}
public function testSetIsolationThrowsExceptionOnUnknownIsolationMode() {
try {
$this->transaction->setIsolation('unknown');
$this->fail();
} catch(Doctrine_Transaction_Exception $e) {
$this->pass();
}
}
public function testSetIsolationExecutesSql() {
$this->transaction->setIsolation('READ UNCOMMITTED');
$this->assertEqual($this->adapter->pop(), 'SET SESSION TRANSACTION ISOLATION LEVEL READ UNCOMMITTED');
}
}

View File

@ -0,0 +1,79 @@
<?php
class Doctrine_Transaction_TestCase extends Doctrine_Driver_UnitTestCase {
public function __construct() {
parent::__construct('sqlite', true);
}
public function testCreateSavepointIsOnlyImplementedAtDriverLevel() {
try {
$this->transaction->createSavePoint('point');
$this->fail();
} catch(Doctrine_Transaction_Exception $e) {
$this->pass();
}
}
public function testReleaseSavepointIsOnlyImplementedAtDriverLevel() {
try {
$this->transaction->releaseSavePoint('point');
$this->fail();
} catch(Doctrine_Transaction_Exception $e) {
$this->pass();
}
}
public function testRollbackSavepointIsOnlyImplementedAtDriverLevel() {
try {
$this->transaction->rollbackSavePoint('point');
$this->fail();
} catch(Doctrine_Transaction_Exception $e) {
$this->pass();
}
}
public function testSetIsolationIsOnlyImplementedAtDriverLevel() {
try {
$this->transaction->setIsolation('READ UNCOMMITTED');
$this->fail();
} catch(Doctrine_Transaction_Exception $e) {
$this->pass();
}
}
public function testGetIsolationIsOnlyImplementedAtDriverLevel() {
try {
$this->transaction->GetIsolation('READ UNCOMMITTED');
$this->fail();
} catch(Doctrine_Transaction_Exception $e) {
$this->pass();
}
}
public function testTransactionLevelIsInitiallyZero() {
$this->assertEqual($this->transaction->getTransactionLevel(), 0);
}
public function testGetStateReturnsStateConstant() {
$this->assertEqual($this->transaction->getState(), Doctrine_Transaction::STATE_SLEEP);
}
public function testExceptionIsThrownWhenCommittingNotActiveTransaction() {
try {
$this->transaction->commit();
$this->fail();
} catch(Doctrine_Transaction_Exception $e) {
$this->pass();
}
}
public function testExceptionIsThrownWhenUsingRollbackOnNotActiveTransaction() {
try {
$this->transaction->rollback();
$this->fail();
} catch(Doctrine_Transaction_Exception $e) {
$this->pass();
}
}
public function testBeginTransactionStartsNewTransaction() {
$this->transaction->beginTransaction();
$this->assertEqual($this->adapter->pop(), 'BEGIN TRANSACTION');
}
public function testCommitMethodCommitsCurrentTransaction() {
$this->transaction->commit();
$this->assertEqual($this->adapter->pop(), 'COMMIT');
}
}