diff --git a/Doctrine/Schema.php b/Doctrine/Schema.php new file mode 100644 index 000000000..66491eb54 --- /dev/null +++ b/Doctrine/Schema.php @@ -0,0 +1,85 @@ +. + */ + +/** + * @package Doctrine + * @url http://www.phpdoctrine.com + * @license http://www.opensource.org/licenses/lgpl-license.php LGPL + * @author Jukka Hassinen + * @version $Id$ + */ + + + +/** + * class Doctrine_Schema + * Holds information on one to many databases + */ +class Doctrine_Schema extends Doctrine_Schema_Object + implements Countable, IteratorAggregate +{ + + /** Aggregations: */ + + /** Compositions: */ + + /*** Attributes: ***/ + + /** + * Holds any number of databases contained in the schema + * @access private + */ + private $childs; + + + /** + * + * @param Doctrine_Schema_Database database * @return + * @access public + */ + public function addDatabase( $database ) { + + } // end of member function addDatabase + + /** + * + * @return + * @access public + */ + public function __toString( ) { + + } // end of member function __toString + + /** + * + * @return bool + * @access public + */ + public function isValid( ) { + + } // end of member function isValid + + + + + +} // end of Doctrine_Schema +?> diff --git a/Doctrine/Schema/Column.php b/Doctrine/Schema/Column.php new file mode 100644 index 000000000..f9e78e638 --- /dev/null +++ b/Doctrine/Schema/Column.php @@ -0,0 +1,134 @@ +. + */ + +/** + * @package Doctrine + * @url http://www.phpdoctrine.com + * @license http://www.opensource.org/licenses/lgpl-license.php LGPL + * @author Jukka Hassinen + * @version $Id$ + */ + + + +/** + * class Doctrine_Schema_Column + * Holds information on a database table field + */ +class Doctrine_Schema_Column extends Doctrine_Schema_Object + implements IteratorAggregate +{ + + /** Aggregations: */ + + /** Compositions: */ + var $m_Vector = array(); + + /*** Attributes: ***/ + + /** + * Column name + * @access public + */ + public $name; + + /** + * Column type e.g. varchar, char, int etc. + * @access public + */ + public $type; + + /** + * Field max length + * @access public + */ + public $length; + + /** + * Is an autoincrement column + * @access public + */ + public $autoincrement; + + /** + * Default field value + * @access public + */ + public $default; + + /** + * Is not null + * @access public + */ + public $notNull; + + /** + * Column comment + * @access public + */ + public $description; + + /** + * Column level check constraint + * @access public + */ + public $check; + + /** + * Character encoding e.g. ISO-8859-1 or UTF-8 etc. + * @access public + */ + public $charset; + + + /** + * + * @return + * @access public + */ + public function __toString( ) { + + } // end of member function __toString + + /** + * + * @return + * @access public + */ + public function __clone( ) { + + } // end of member function __clone + + /** + * + * @return bool + * @access public + */ + public function isValid( ) { + + } // end of member function isValid + + + + + +} // end of Doctrine_Schema_Column +?> diff --git a/Doctrine/Schema/Database.php b/Doctrine/Schema/Database.php new file mode 100644 index 000000000..8c0c7764f --- /dev/null +++ b/Doctrine/Schema/Database.php @@ -0,0 +1,131 @@ +. + */ + +/** + * @package Doctrine + * @url http://www.phpdoctrine.com + * @license http://www.opensource.org/licenses/lgpl-license.php LGPL + * @author Jukka Hassinen + * @version $Id$ + */ + + + +/** + * class Doctrine_Schema_Database + * Holds information on a database + */ +class Doctrine_Schema_Database extends Doctrine_Schema_Object + implements Countable, IteratorAggregate +{ + + /** Aggregations: */ + + /** Compositions: */ + var $m_; + + /*** Attributes: ***/ + + /** + * Database name + * @access public + */ + public $name; + + /** + * Database driver type + * @access public + */ + public $type; + + /** + * Database server version + * @access public + */ + public $version; + + /** + * The underlaying engine in the database e.g. InnoDB or MyISAM in MySQL. + * @access public + */ + public $engine; + + /** + * Character encoding e.g. ISO-8859-1 or UTF-8 etc. + * @access public + */ + public $charset; + + /** + * Foreign key constraints in the database + * @access public + */ + public $foreignKeyRelations; + + /** + * Tables in the database + * @access private + */ + private $childs; + + + /** + * + * @return + * @access public + */ + public function __clone( ) { + + } // end of member function __clone + + /** + * + * @return + * @access public + */ + public function __toString( ) { + + } // end of member function __toString + + /** + * + * @return bool + * @access public + */ + public function isValid( ) { + + } // end of member function isValid + + /** + * + * @param Doctrine_Schema_Table table * @return Doctrine_Schema_Table + * @access public + */ + public function addTable( $table = null ) { + + } // end of member function addTable + + + + + +} // end of Doctrine_Schema_Database +?> diff --git a/Doctrine/Schema/Exception.php b/Doctrine/Schema/Exception.php new file mode 100644 index 000000000..3f123513b --- /dev/null +++ b/Doctrine/Schema/Exception.php @@ -0,0 +1,50 @@ +. + */ + +/** + * @package Doctrine + * @url http://www.phpdoctrine.com + * @license http://www.opensource.org/licenses/lgpl-license.php LGPL + * @author Jukka Hassinen + * @version $Id$ + */ + + + +/** + * class Doctrine_Schema_Exception + */ +class Doctrine_Schema_Exception extends Exception +{ + + /** Aggregations: */ + + /** Compositions: */ + + /*** Attributes: ***/ + + + + + + +} // end of Doctrine_Schema_Exception +?> diff --git a/Doctrine/Schema/Object.php b/Doctrine/Schema/Object.php new file mode 100644 index 000000000..3396fee40 --- /dev/null +++ b/Doctrine/Schema/Object.php @@ -0,0 +1,101 @@ +. + */ + +/** + * @package Doctrine + * @url http://www.phpdoctrine.com + * @license http://www.opensource.org/licenses/lgpl-license.php LGPL + * @author Jukka Hassinen + * @version $Id$ + */ + + + +/** + * class Doctrine_Schema_Object + * Catches any non-property call from child classes and throws an exception. + */ +abstract class Doctrine_Schema_Object + implements IteratorAggregate, Countable +{ + + /** Aggregations: */ + + /** Compositions: */ + + /*** Attributes: ***/ + + + /** + * + * @param string _property + * @param mixed _value + * @return + * @access public + */ + public function __set( $_property, $_value ) + { + throw new Doctrine_Schema_Exception('Assignment of non-property'); + } // end of member function __set + + /** + * + * @param string _property + * @return + * @access public + */ + public function __get( $_property ) + { + throw new Doctrine_Schema_Exception('Access of non-property'); + } // end of member function __get + + + + /** + * + * @return int + * @access public + */ + public function count( ) + { + if(!empty($this->childs)) + { + return count($this->childs); + } + return 0; + } + + /** + * + * @return + * @access public + */ + public function getIterator( ) + { + if(!empty($this->childs)) + { + return new ArrayIterator($this->childs); + } + return new ArrayIterator(); + } + +} // end of Doctrine_Schema_Object + diff --git a/Doctrine/Schema/Relation.php b/Doctrine/Schema/Relation.php new file mode 100644 index 000000000..f7b025392 --- /dev/null +++ b/Doctrine/Schema/Relation.php @@ -0,0 +1,125 @@ +. + */ + +/** + * @package Doctrine + * @url http://www.phpdoctrine.com + * @license http://www.opensource.org/licenses/lgpl-license.php LGPL + * @author Jukka Hassinen + * @version $Id$ + */ + + + +/** + * class Doctrine_Schema_Relation + * Holds information on a foreign key relation. + */ +class Doctrine_Schema_Relation extends Doctrine_Schema_Object +{ + + /** Aggregations: */ + + /** Compositions: */ + + /*** Attributes: ***/ + + /** + * Columns that refer to another table + * @access public + */ + public $referencingFields; + + /** + * Columns that are referred from another table + * @access public + */ + public $referredFields; + + /** + * ON UPDATE or ON DELETE action + * @static + * @access public + */ + public static $ACTION_RESTRICT = 1; + + /** + * ON UPDATE or ON DELETE action + * @static + * @access public + */ + public static $ACTION_SET_NULL = 2; + + /** + * ON UPDATE or ON DELETE action + * @static + * @access public + */ + public static $ACTION_CASCADE = 3; + + /** + * ON UPDATE or ON DELETE action + * @static + * @access public + */ + public static $ACTION_NO_ACTION = 4; + + /** + * ON UPDATE or ON DELETE action + * @static + * @access public + */ + public static $ACTION_SET_DEFAULT = 5; + + + /** + * + * @param Doctrine_Schema_Column referringColumns * @param Doctrine_Schema_Column referencedColumns * @return + * @access public + */ + public function setRelationBetween( $referringColumns, $referencedColumns ) { + + } // end of member function setRelationBetween + + /** + * + * @return + * @access public + */ + public function __toString( ) { + + } // end of member function __toString + + /** + * + * @return bool + * @access public + */ + public function isValid( ) { + + } // end of member function isValid + + + + + +} // end of Doctrine_Schema_Relation +?> diff --git a/Doctrine/Schema/Table.php b/Doctrine/Schema/Table.php new file mode 100644 index 000000000..aec7bf689 --- /dev/null +++ b/Doctrine/Schema/Table.php @@ -0,0 +1,137 @@ +. + */ + +/** + * @package Doctrine + * @url http://www.phpdoctrine.com + * @license http://www.opensource.org/licenses/lgpl-license.php LGPL + * @author Jukka Hassinen + * @version $Id$ + */ + + + +/** + * class Doctrine_Schema_Table + * Holds information on a database table + */ +class Doctrine_Schema_Table extends Doctrine_Schema_Object + implements Countable, Countable, IteratorAggregate +{ + + /** Aggregations: */ + + /** Compositions: */ + var $m_Vector = array(); + var $m_; + + /*** Attributes: ***/ + + /** + * Unique key fields + * @access public + */ + public $uniqueKeys; + + /** + * Indexed columns + * @access public + */ + public $indexes; + + /** + * Table name + * @access public + */ + public $name; + + /** + * @access public + */ + public $primaryKeys; + + /** + * Check constraint definition + * @access public + */ + public $check; + + /** + * Character encoding e.g. ISO-8859-1 or UTF-8 etc. + * @access public + */ + public $charset; + + /** + * Description or comment given in the schema + * @access public + */ + public $description; + + /** + * Columns of the table + * @access private + */ + private $childs; + + + /** + * + * @return + * @access public + */ + public function __toString( ) { + + } // end of member function __toString + + /** + * + * @return + * @access public + */ + public function __clone( ) { + + } // end of member function __clone + + /** + * + * @return bool + * @access public + */ + public function isValid( ) { + + } // end of member function isValid + + /** + * + * @param Doctrine_Schema_Column column * @return Doctrine_Schema_Column + * @access public + */ + public function addColumn( $column = null ) { + + } // end of member function addColumn + + + + + +} // end of Doctrine_Schema_Table +?> diff --git a/manual/architecture/Doctrine_Import.png b/manual/architecture/Doctrine_Import.png index a7f22317b..23557fb99 100644 Binary files a/manual/architecture/Doctrine_Import.png and b/manual/architecture/Doctrine_Import.png differ diff --git a/manual/architecture/Doctrine_Import.xmi b/manual/architecture/Doctrine_Import.xmi index 072dd0ff0..e118b47ce 100644 --- a/manual/architecture/Doctrine_Import.xmi +++ b/manual/architecture/Doctrine_Import.xmi @@ -1,5 +1,5 @@ - + umbrello uml modeller http://uml.sf.net @@ -17,6 +17,7 @@ + @@ -32,57 +33,63 @@ - + - + - + - - - - - - - - + + + + + + + + - + + + + + + + - + - - - - - - - - - + + + + + + + + + - + @@ -91,7 +98,7 @@ - + @@ -104,29 +111,29 @@ - + - + - - + + - + - + @@ -135,9 +142,9 @@ - - - + + + @@ -156,14 +163,14 @@ - - + + - + @@ -172,28 +179,34 @@ - + - + - - - - - - - + + + + + + + - + + + + + + + @@ -206,28 +219,31 @@ - + - + - + + + + - + - + - + @@ -236,7 +252,7 @@ - + @@ -257,8 +273,31 @@ + + + + + + + + + + + + + + + + + + + + + + + @@ -290,7 +329,7 @@ - + @@ -307,33 +346,44 @@ + + + + + + + + + + + - + - + - - + + - - - + + + - - - + + + - + - - + + @@ -342,27 +392,31 @@ - - - + + + - + - - + + + + + + - + - + @@ -380,14 +434,14 @@ - - + + - - + + @@ -396,21 +450,21 @@ - + - - + + - - + + - + - - + + - - + + @@ -418,21 +472,13 @@ - + - - + + - - - - - - - - - - + + @@ -449,24 +495,25 @@ - + + - - + + - - + + - + - - + + @@ -480,92 +527,112 @@ - + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + - - - - - - - - - - + + - - + + - + - - + + - + - - + + - + - - + + - + - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -615,19 +682,6 @@ - - - - - - - - - - - - - @@ -642,9 +696,25 @@ + + + + + + + + + + + + + + + + @@ -659,18 +729,26 @@ - - + - + + - + + + + + + + + + diff --git a/tests/ImportTestCase.php b/tests/ImportTestCase.php new file mode 100644 index 000000000..44aace5bd --- /dev/null +++ b/tests/ImportTestCase.php @@ -0,0 +1,25 @@ + + * @version $Id$ + * @package doctrine + */ +class Doctrine_ImportTestCase extends Doctrine_UnitTestCase +{ + function testDatabaseConnectionIsReverseEngineeredToSchema() + { + + } + + function testNativeColumnDefinitionsAreTranslatedCorrectly() + { + + } + + function testDoctrineRecordBaseClassesAreBuildCorrectlyAndToPath() + { + + } +} \ No newline at end of file diff --git a/tests/SchemaTestCase.php b/tests/SchemaTestCase.php new file mode 100644 index 000000000..abe51aa7a --- /dev/null +++ b/tests/SchemaTestCase.php @@ -0,0 +1,201 @@ + + * @version $Id$ + * @package Doctrine + */ +class Doctrine_SchemaTestCase extends Doctrine_UnitTestCase +{ + + function testEverySchemaObjectIsThrowingExceptionOnNonPropertyAssignment() + { + $isException = false; + $obj = new Doctrine_Schema(); + try { + $obj->no_such_property = 'this should throw an exception'; + } catch (Doctrine_Schema_Exception $e) + { + $isException = true; + } + $this->assertTrue($isException); + + $isException = false; + $obj = new Doctrine_Schema_Database(); + try { + $obj->no_such_property = 'this should throw an exception'; + } catch (Doctrine_Schema_Exception $e) + { + $isException = true; + } + $this->assertTrue($isException); + + $isException = false; + $obj = new Doctrine_Schema_Table(); + try { + $obj->no_such_property = 'this should throw an exception'; + } catch (Doctrine_Schema_Exception $e) + { + $isException = true; + } + $this->assertTrue($isException); + + $isException = false; + $obj = new Doctrine_Schema_Column(); + try { + $obj->no_such_property = 'this should throw an exception'; + } catch (Doctrine_Schema_Exception $e) + { + $isException = true; + } + $this->assertTrue($isException); + + $isException = false; + $obj = new Doctrine_Schema_Relation(); + try { + $obj->no_such_property = 'this should throw an exception'; + } catch (Doctrine_Schema_Exception $e) + { + $isException = true; + } + $this->assertTrue($isException); + } + + function testEverySchemaObjectIsThrowingExceptionOnNonPropertyAccess() + { + $isException = false; + $obj = new Doctrine_Schema(); + try { + $value = $obj->no_such_property; + } catch (Doctrine_Schema_Exception $e) + { + $isException = true; + } + $this->assertTrue($isException); + + $isException = false; + $obj = new Doctrine_Schema_Database(); + try { + $value = $obj->no_such_property; + } catch (Doctrine_Schema_Exception $e) + { + $isException = true; + } + $this->assertTrue($isException); + + $isException = false; + $obj = new Doctrine_Schema_Table(); + try { + $value = $obj->no_such_property; + } catch (Doctrine_Schema_Exception $e) + { + $isException = true; + } + $this->assertTrue($isException); + + $isException = false; + $obj = new Doctrine_Schema_Column(); + try { + $value = $obj->no_such_property; + } catch (Doctrine_Schema_Exception $e) + { + $isException = true; + } + $this->assertTrue($isException); + + $isException = false; + $obj = new Doctrine_Schema_Relation(); + try { + $value = $obj->no_such_property; + } catch (Doctrine_Schema_Exception $e) + { + $isException = true; + } + $this->assertTrue($isException); + } + + function testSchemaDatabasePropertiesAreAssignableAndAccessible() + { + $obj = new Doctrine_Schema_Database(); + $vars = array( + 'name' => 'mydatabase', + 'type' => 'MySQL', + 'version' => '5.0', + 'engine' => 'InnoDB', + 'charset' => 'UTF-8' + ); + + foreach ($vars as $key => $val) + { + $obj->$key = $val; + $this->assertEqual($obj->$key, $val); + } + + + } + + function testSchemaTablePropertiesAreAssignableAndAccessible() + { + $obj = new Doctrine_Schema_Table(); + $vars = array( + 'name' => 'User', + 'check' => '(col1 < col2)', + 'charset' => 'UTF-8', + 'description' => 'User data' + ); + + foreach ($vars as $key => $val) + { + $obj->$key = $val; + $this->assertEqual($obj->$key, $val); + } + } + + function testSchemaColumnPropertiesAreAssignableAndAccessible() + { + $obj = new Doctrine_Schema_Column(); + $vars = array( + 'name' => 'id', + 'type' => 'int', + 'length' => 10, + 'autoincrement' => true, + 'default' => null, + 'notNull' => true, + 'description' => 'user id', + 'check' => 'id > 0', + 'charset' => 'UTF-8' + ); + + foreach ($vars as $key => $val) + { + $obj->$key = $val; + $this->assertEqual($obj->$key, $val); + } + } + + function testSchemaDatabaseIsCloneable() + { + } + + + function testSchemaIsTraversable() + { + /* @todo complete */ + + $schema = new Doctrine_Schema(); + + foreach($schema as $key => $db) + { + $this->assertEqual($db->name, $key); + foreach($db as $key => $table) + { + $this->assertEqual($table->name, $key); + foreach($table as $key => $col) + { + $this->assertEqual($col->name, $key); + } + } + } + } +} \ No newline at end of file diff --git a/tests/run.php b/tests/run.php index ea0b125be..c720045f1 100644 --- a/tests/run.php +++ b/tests/run.php @@ -25,6 +25,9 @@ require_once("FilterTestCase.php"); require_once("ValueHolderTestCase.php"); require_once("QueryLimitTestCase.php"); +require_once("SchemaTestCase.php"); +require_once("ImportTestCase.php"); + error_reporting(E_ALL); $test = new GroupTest("Doctrine Framework Unit Tests"); @@ -69,6 +72,10 @@ $test->addTestCase(new Doctrine_RawSql_TestCase()); $test->addTestCase(new Doctrine_Query_Limit_TestCase()); +$test->addTestCase(new Doctrine_SchemaTestCase()); + +$test->addTestCase(new Doctrine_ImportTestCase()); + //$test->addTestCase(new Doctrine_Cache_FileTestCase()); //$test->addTestCase(new Doctrine_Cache_SqliteTestCase());