1
0
mirror of synced 2025-02-06 15:29:26 +03:00

Developed Doctrine_Import, changed Doctrine_Schema objects to have unified constructor

This commit is contained in:
zYne 2006-10-23 19:55:30 +00:00
parent 0c0e6fd637
commit daaab94cfe
17 changed files with 317 additions and 351 deletions

View File

@ -35,22 +35,13 @@
* reading to a reader object and passes the result to a builder object which * reading to a reader object and passes the result to a builder object which
* builds a Doctrine data model. * builds a Doctrine data model.
*/ */
class Doctrine_Import class Doctrine_Import {
{
/** Aggregations: */
/** Compositions: */
/*** Attributes: ***/
/** /**
* @access private * @var Doctrine_Import_Reader $reader
*/ */
private $reader; private $reader;
/** /**
* @access private * @var Doctrine_Import_Builder $builder
*/ */
private $builder; private $builder;
@ -62,29 +53,21 @@ class Doctrine_Import
*/ */
public function import( ) { public function import( ) {
} // end of member function import }
/** /**
* *
* @param Doctrine_Import_Reader reader * @return * @param Doctrine_Import_Reader reader
* @access public * @return void
*/ */
public function setReader( $reader ) { public function setReader(Doctrine_Import_Reader $reader) {
$this->reader = $reader;
} // end of member function setReader }
/** /**
* *
* @param Doctrine_Import_Builder builder * @return * @param Doctrine_Import_Builder builder
* @access public * @return void
*/ */
public function setBuilder( $builder ) { public function setBuilder(Doctrine_Import_Builder $builder) {
$this->builder = $builder;
} // end of member function setBuilder }
}
} // end of Doctrine_Import

View File

@ -33,28 +33,96 @@
* class Doctrine_Import_Builder * class Doctrine_Import_Builder
* Is responsible of building Doctrine structure based on a database schema. * Is responsible of building Doctrine structure based on a database schema.
*/ */
abstract class Doctrine_Import_Builder class Doctrine_Import_Builder {
{
/** Aggregations: */ private $path = '';
/** Compositions: */ private $suffix = '.php';
/*** Attributes: ***/ private static $tpl;
public function __construct() {
if( ! isset(self::$tpl))
self::$tpl = file_get_contents(Doctrine::getPath()
. DIRECTORY_SEPARATOR . 'Doctrine'
. DIRECTORY_SEPARATOR . 'Import'
. DIRECTORY_SEPARATOR . 'Builder'
. DIRECTORY_SEPARATOR . 'Record.tpl');
}
/** /**
* *
* @param Doctrine_Schema schema * @param string path
* @return * @return
* @abstract
* @access public * @access public
*/ */
abstract public function build(Doctrine_Schema $schema ); public function setTargetPath($path) {
if( ! file_exists($path)) {
mkdir($path, 0777);
}
$this->path = $path;
}
public function getTargetPath() {
return $this->path;
}
/**
*
* @param string path
* @return
* @access public
*/
public function setFileSuffix($suffix) {
$this->suffix = $suffix;
}
public function getFileSuffix() {
return $this->suffix;
}
public function buildRecord(Doctrine_Schema_Table $table) {
if (empty($this->path))
throw new Doctrine_Import_Builder_Exception('No build target directory set.');
if (is_writable($this->path) === false)
throw new Doctrine_Import_Builder_Exception('Build target directory ' . $this->path . ' is not writable.');
$created = date('l dS \of F Y h:i:s A');
$className = Doctrine::classify($table->get('name'));
$fileName = $this->path . DIRECTORY_SEPARATOR . $className . $this->suffix;
$columns = array();
$i = 0;
foreach($table as $name => $column) {
$columns[$i] = ' $this->hasColumn(\'' . $column['name'] . '\', \'' . $column['type'] . '\'';
if($column['length'])
$columns[$i] .= ', ' . $column['length'];
$columns[$i] .= ');';
if($i < (count($table) - 1))
$columns[$i] .= '
';
$i++;
}
$content = sprintf(self::$tpl, $created, $className, implode('', $columns));
$bytes = file_put_contents($fileName, $content);
if($bytes === false)
throw new Doctrine_Import_Builder_Exception("Couldn't write file " . $fileName);
}
/**
*
* @param Doctrine_Schema_Object $schema
* @return
* @access public
* @throws Doctrine_Import_Exception
*/
public function build(Doctrine_Schema_Object $schema) {
}
}
} // end of Doctrine_Import_Builder

View File

@ -33,51 +33,5 @@
* class Doctrine_Import_Builder_BaseClass * class Doctrine_Import_Builder_BaseClass
* Builds a Doctrine_Record base class definition based on a schema. * Builds a Doctrine_Record base class definition based on a schema.
*/ */
class Doctrine_Import_Builder_BaseClass extends Doctrine_Import_Builder class Doctrine_Import_Builder_BaseClass extends Doctrine_Import_Builder {
{
/** Aggregations: */
/** Compositions: */
/*** Attributes: ***/
private $path = '';
private $suffix = '.php';
/**
*
* @param string path
* @return
* @access public
*/
public function setOutputPath( $path ) {
$this->path = $path;
} // end of member function setOuputPath
/**
*
* @param string path
* @return
* @access public
*/
public function setFileSuffix( $suffix ) {
$this->suffix = $suffix;
} // end of member function setOuputPath
/**
*
* @param Doctrine_Schema schema
* @return
* @access public
* @throws Doctrine_Import_Exception
*/
public function build(Doctrine_Schema $schema )
{
/* @todo FIXME i am incomplete*/
} }
} // end of Doctrine_Import_Builder_BaseClass

View File

@ -18,7 +18,7 @@
* and is licensed under the LGPL. For more information, see * and is licensed under the LGPL. For more information, see
* <http://www.phpdoctrine.com>. * <http://www.phpdoctrine.com>.
*/ */
Doctrine::autoload('Doctrine_Import_Exception');
/** /**
* @package Doctrine * @package Doctrine
* @url http://www.phpdoctrine.com * @url http://www.phpdoctrine.com
@ -27,24 +27,7 @@
* @version $Id$ * @version $Id$
*/ */
/** /**
* class Doctrine_Import_Builder_Exception * class Doctrine_Import_Builder_Exception
*/ */
class Doctrine_Import_Builder_Exception class Doctrine_Import_Builder_Exception extends Doctrine_Import_Exception { }
{
/** Aggregations: */
/** Compositions: */
/*** Attributes: ***/
} // end of Doctrine_Import_Builder_Exception

View File

@ -0,0 +1,13 @@
<?php
/**
* This class has been auto-generated by the Doctrine ORM Framework
* Created: %s
*/
class %s extends Doctrine_Record {
public function setTableDefinition() {
%s
}
public function setUp() {
}
}

View File

@ -0,0 +1,32 @@
<?php
/*
* $Id$
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information, see
* <http://www.phpdoctrine.com>.
*/
Doctrine::autoload('Doctrine_Exception');
/**
* @package Doctrine
* @url http://www.phpdoctrine.com
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @version $Id$
*/
/**
* class Doctrine_Import_Exception
*/
class Doctrine_Import_Exception extends Doctrine_Exception { }

View File

@ -33,16 +33,7 @@
* class Doctrine_Schema * class Doctrine_Schema
* Holds information on one to many databases * Holds information on one to many databases
*/ */
class Doctrine_Schema extends Doctrine_Schema_Object class Doctrine_Schema extends Doctrine_Schema_Object implements Countable, IteratorAggregate {
implements Countable, IteratorAggregate
{
/** Aggregations: */
/** Compositions: */
/*** Attributes: ***/
/** /**
* Holds any number of databases contained in the schema * Holds any number of databases contained in the schema
* @access private * @access private
@ -57,7 +48,7 @@ class Doctrine_Schema extends Doctrine_Schema_Object
*/ */
public function addDatabase( $database ) { public function addDatabase( $database ) {
} // end of member function addDatabase }
/** /**
* *
@ -66,8 +57,7 @@ class Doctrine_Schema extends Doctrine_Schema_Object
*/ */
public function __toString( ) { public function __toString( ) {
} // end of member function __toString }
/** /**
* *
* @return bool * @return bool
@ -75,11 +65,5 @@ class Doctrine_Schema extends Doctrine_Schema_Object
*/ */
public function isValid( ) { public function isValid( ) {
} // end of member function isValid }
}
} // end of Doctrine_Schema

View File

@ -40,18 +40,15 @@ class Doctrine_Schema_Column extends Doctrine_Schema_Object implements IteratorA
*/ */
protected $definition = array('name' => '', protected $definition = array('name' => '',
'type' => '', 'type' => '',
'length' => 0,
'unique' => false, 'unique' => false,
'primary' => false, 'primary' => false,
'notnull' => false, 'notnull' => false,
'default' => null, 'default' => false,
'autoinc' => false
); );
public function __construct(array $definition) {
foreach($this->definition as $key => $val) {
if(isset($definition[$key]))
$this->definition[$key] = $definition[$key];
}
}
public function getName() { public function getName() {
return $this->definition['name']; return $this->definition['name'];
} }

View File

@ -28,63 +28,19 @@
*/ */
/** /**
* class Doctrine_Schema_Database * class Doctrine_Schema_Database
* Holds information on a database * Holds information on a database
*/ */
class Doctrine_Schema_Database extends Doctrine_Schema_Object class Doctrine_Schema_Database extends Doctrine_Schema_Object {
implements Countable, IteratorAggregate
{
/** Aggregations: */ protected $definition = array('name' => null,
'type' => null,
'charset' => null,
'description' => null,
'version' => null,
'engine' => null);
/** 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;
/** /**
@ -94,8 +50,7 @@ class Doctrine_Schema_Database extends Doctrine_Schema_Object
*/ */
public function __clone( ) { public function __clone( ) {
} // end of member function __clone }
/** /**
* *
* @return * @return
@ -103,8 +58,7 @@ class Doctrine_Schema_Database extends Doctrine_Schema_Object
*/ */
public function __toString( ) { public function __toString( ) {
} // end of member function __toString }
/** /**
* *
* @return bool * @return bool
@ -112,8 +66,7 @@ class Doctrine_Schema_Database extends Doctrine_Schema_Object
*/ */
public function isValid( ) { public function isValid( ) {
} // end of member function isValid }
/** /**
* *
* @param Doctrine_Schema_Table table * @return Doctrine_Schema_Table * @param Doctrine_Schema_Table table * @return Doctrine_Schema_Table
@ -121,11 +74,5 @@ class Doctrine_Schema_Database extends Doctrine_Schema_Object
*/ */
public function addTable( $table = null ) { public function addTable( $table = null ) {
} // end of member function addTable }
}
} // end of Doctrine_Schema_Database

View File

@ -18,7 +18,7 @@
* and is licensed under the LGPL. For more information, see * and is licensed under the LGPL. For more information, see
* <http://www.phpdoctrine.com>. * <http://www.phpdoctrine.com>.
*/ */
Doctrine::autoload('Doctrine_Exception');
/** /**
* @package Doctrine * @package Doctrine
* @url http://www.phpdoctrine.com * @url http://www.phpdoctrine.com
@ -32,19 +32,4 @@
/** /**
* class Doctrine_Schema_Exception * class Doctrine_Schema_Exception
*/ */
class Doctrine_Schema_Exception extends Exception class Doctrine_Schema_Exception extends Exception { }
{
/** Aggregations: */
/** Compositions: */
/*** Attributes: ***/
} // end of Doctrine_Schema_Exception

View File

@ -18,36 +18,54 @@
* and is licensed under the LGPL. For more information, see * and is licensed under the LGPL. For more information, see
* <http://www.phpdoctrine.com>. * <http://www.phpdoctrine.com>.
*/ */
Doctrine::autoload('Doctrine_Access');
/** /**
* @package Doctrine * @package Doctrine
* @url http://www.phpdoctrine.com * @url http://www.phpdoctrine.com
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL * @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @author Jukka Hassinen <Jukka.Hassinen@BrainAlliance.com> * @author Jukka Hassinen <Jukka.Hassinen@BrainAlliance.com>
* @author Konsta Vesterinen
* @version $Id$ * @version $Id$
*/ */
/** /**
* class Doctrine_Schema_Object * class Doctrine_Schema_Object
* Catches any non-property call from child classes and throws an exception. * Catches any non-property call from child classes and throws an exception.
*/ */
abstract class Doctrine_Schema_Object implements IteratorAggregate, Countable { abstract class Doctrine_Schema_Object extends Doctrine_Access implements IteratorAggregate, Countable {
protected $children = array(); protected $children = array();
protected $definition = array('name' => ''); protected $definition = array('name' => '');
public function __construct(array $definition) { public function __construct(array $definition = array()) {
foreach($this->definition as $key => $val) { foreach($this->definition as $key => $val) {
if(isset($definition[$key])) if(isset($definition[$key]))
$this->definition[$key] = $definition[$key]; $this->definition[$key] = $definition[$key];
} }
} }
public function getName() { public function get($name) {
return $this->definition['name']; if( ! array_key_exists($name, $this->definition))
throw new Doctrine_Schema_Exception('Unknown definition '. $name);
return $this->definition[$name];
}
public function set($name, $value) {
if( ! array_key_exists($name, $this->definition))
throw new Doctrine_Schema_Exception('Unknown definition '. $name);
$this->definition[$name] = $value;
}
public function contains($name) {
return array_key_exists($name, $this->definition);
}
public function toArray() {
return $this->definition;
} }
/** /**
* *
@ -55,8 +73,8 @@ abstract class Doctrine_Schema_Object implements IteratorAggregate, Countable {
* @access public * @access public
*/ */
public function count() { public function count() {
if( ! empty($this->childs)) if( ! empty($this->children))
return count($this->childs); return count($this->children);
return count($this->definition); return count($this->definition);
} }
@ -68,8 +86,8 @@ abstract class Doctrine_Schema_Object implements IteratorAggregate, Countable {
* @access public * @access public
*/ */
public function getIterator() { public function getIterator() {
if( ! empty($this->childs)) if( ! empty($this->children))
return new ArrayIterator($this->childs); return new ArrayIterator($this->children);
return new ArrayIterator($this->definition); return new ArrayIterator($this->definition);
} }

View File

@ -33,14 +33,7 @@
* class Doctrine_Schema_Relation * class Doctrine_Schema_Relation
* Holds information on a foreign key relation. * Holds information on a foreign key relation.
*/ */
class Doctrine_Schema_Relation extends Doctrine_Schema_Object class Doctrine_Schema_Relation extends Doctrine_Schema_Object {
{
/** Aggregations: */
/** Compositions: */
/*** Attributes: ***/
/** /**
* Columns that refer to another table * Columns that refer to another table
@ -92,13 +85,14 @@ class Doctrine_Schema_Relation extends Doctrine_Schema_Object
/** /**
* *
* @param Doctrine_Schema_Column referringColumns * @param Doctrine_Schema_Column referencedColumns * @return * @param Doctrine_Schema_Column referringColumns
* @param Doctrine_Schema_Column referencedColumns
* @return
* @access public * @access public
*/ */
public function setRelationBetween( $referringColumns, $referencedColumns ) { public function setRelationBetween( $referringColumns, $referencedColumns ) {
} // end of member function setRelationBetween }
/** /**
* *
* @return * @return
@ -106,8 +100,7 @@ class Doctrine_Schema_Relation extends Doctrine_Schema_Object
*/ */
public function __toString( ) { public function __toString( ) {
} // end of member function __toString }
/** /**
* *
* @return bool * @return bool
@ -115,11 +108,5 @@ class Doctrine_Schema_Relation extends Doctrine_Schema_Object
*/ */
public function isValid( ) { public function isValid( ) {
} // end of member function isValid }
}
} // end of Doctrine_Schema_Relation

View File

@ -33,50 +33,13 @@
* class Doctrine_Schema_Table * class Doctrine_Schema_Table
* Holds information on a database table * Holds information on a database table
*/ */
class Doctrine_Schema_Table extends Doctrine_Schema_Object class Doctrine_Schema_Table extends Doctrine_Schema_Object implements Countable, IteratorAggregate {
implements Countable, Countable, IteratorAggregate
{
/** protected $definition = array('name' => '',
* Unique key fields 'check' => '',
* @access public 'charset' => '',
*/ 'description' => '');
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;
/** /**
* *
* @return bool * @return bool
@ -109,7 +72,7 @@ class Doctrine_Schema_Table extends Doctrine_Schema_Object
* @access public * @access public
*/ */
public function addColumn(Doctrine_Schema_Column $column) { public function addColumn(Doctrine_Schema_Column $column) {
$name = $column->getName(); $name = $column->get('name');
$this->children[$name] = $column; $this->children[$name] = $column;
return $this; return $this;

View File

@ -9,7 +9,7 @@
* @version $Id$ * @version $Id$
* @package Doctrine * @package Doctrine
*/ */
class Doctrine_ImportTestCase extends Doctrine_UnitTestCase class Doctrine_Import_TestCase extends Doctrine_UnitTestCase
{ {
private $tmpdir; private $tmpdir;
@ -25,17 +25,50 @@ class Doctrine_ImportTestCase extends Doctrine_UnitTestCase
$reader = new Doctrine_Import_Reader_Db(); $reader = new Doctrine_Import_Reader_Db();
$reader->setPdo($this->dbh); $reader->setPdo($this->dbh);
$this->schema = $reader->read(); $this->schema = $reader->read();
//and building
$this->tmpdir = $this->getTempDir();
$this->suffix = '__Base';
$builder = new Doctrine_Import_Builder_BaseClass();
$builder->setOutputPath($this->tmpdir);
$builder->setFileSuffix($this->suffix.'.php');
$builder->build($this->schema);
} }
public function testBadImport() {
$builder = new Doctrine_Import_Builder();
try {
$builder->buildRecord(new Doctrine_Schema_Table());
$this->fail();
} catch(Doctrine_Import_Builder_Exception $e) {
$this->pass();
}
}
public function testImportTable() {
$definition = array('name' => 'user');
$table = new Doctrine_Schema_Table($definition);
$def = array('name' => 'name',
'type' => 'string',
'length' => 20);
$table->addColumn(new Doctrine_Schema_Column($def));
$def = array('name' => 'created',
'type' => 'integer');
$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();
}
unlink('tmp' . DIRECTORY_SEPARATOR . 'User.php');
}
/**
public function testDatabaseConnectionIsReverseEngineeredToSchema() public function testDatabaseConnectionIsReverseEngineeredToSchema()
{ {
@ -62,9 +95,9 @@ class Doctrine_ImportTestCase extends Doctrine_UnitTestCase
{ {
$transArr = array(); $transArr = array();
/* From SQLite column types */
$transArr['sqlite'] = array( $transArr['sqlite'] = array(
/* array(native type, native length, doctrine type, doctrine length), */ // array(native type, native length, doctrine type, doctrine length),
array('int', 11, 'int', 11), array('int', 11, 'int', 11),
//array('varchar', 255, 'string', 255), //array('varchar', 255, 'string', 255),
); );
@ -103,19 +136,14 @@ class Doctrine_ImportTestCase extends Doctrine_UnitTestCase
} }
} }
public function tearDown()
{
@unlink($this->tmpdir);
@rmdir($this->tmpdir);
}
/**
* Gets the system temporary directory name
* @return null on failure to resolve the system temp dir
*/ */
// Gets the system temporary directory name
// @return null on failure to resolve the system temp dir
private function getTempDir() private function getTempDir()
{ {
/**
if(function_exists('sys_get_temp_dir')) { if(function_exists('sys_get_temp_dir')) {
$tempdir = sys_get_temp_dir(); $tempdir = sys_get_temp_dir();
} elseif (!empty($_ENV['TMP'])) { } elseif (!empty($_ENV['TMP'])) {
@ -146,5 +174,6 @@ class Doctrine_ImportTestCase extends Doctrine_UnitTestCase
$dir .= DIRECTORY_SEPARATOR; $dir .= DIRECTORY_SEPARATOR;
return $dir; return $dir;
*/
} }
} }

View File

@ -1,6 +1,8 @@
<?php <?php
class RelationTest extends Doctrine_Record { class RelationTest extends Doctrine_Record {
public function setTableDefinition() { public function setTableDefinition() {
$this->hasColumn('name', 'string', 200);
$this->hasColumn("child_id", "integer"); $this->hasColumn("child_id", "integer");
} }
public function setUp() { public function setUp() {
@ -40,7 +42,9 @@ class OwnsOneToManyWithAlias extends Doctrine_Record {
} }
} }
class HasManyToManyWithAlias extends Doctrine_Record { class HasManyToManyWithAlias extends Doctrine_Record {
public function setTableDefinition() { } public function setTableDefinition() {
$this->hasColumn('name', 'string', 200);
}
public function setUp() { public function setUp() {
$this->hasMany('RelationTest as AliasM2M', 'JoinTable.c2_id'); $this->hasMany('RelationTest as AliasM2M', 'JoinTable.c2_id');
} }
@ -48,7 +52,9 @@ class HasManyToManyWithAlias extends Doctrine_Record {
class Doctrine_Relation_TestCase extends Doctrine_UnitTestCase { class Doctrine_Relation_TestCase extends Doctrine_UnitTestCase {
public function prepareData() { } public function prepareData() { }
public function prepareTables() { public function prepareTables() {
$this->tables = array(); $this->tables = array('HasManyToManyWithAlias', 'RelationTest', 'JoinTable');
parent::prepareTables();
} }
public function testOneToManyTreeRelationWithConcreteInheritance() { public function testOneToManyTreeRelationWithConcreteInheritance() {
$component = new RelationTestChild(); $component = new RelationTestChild();
@ -78,7 +84,7 @@ class Doctrine_Relation_TestCase extends Doctrine_UnitTestCase {
$this->assertTrue($rel instanceof Doctrine_Relation_LocalKey); $this->assertTrue($rel instanceof Doctrine_Relation_LocalKey);
} }
public function testOneToManyOwnsRelationWithAliases() { public function testOneToManyOwnsRelationWithAliases() {
$this->manager->setAttribute(Doctrine::ATTR_CREATE_TABLES, false);
$component = new RelationTest(); $component = new RelationTest();
@ -104,10 +110,26 @@ class Doctrine_Relation_TestCase extends Doctrine_UnitTestCase {
$this->assertTrue($component->AliasM2M instanceof Doctrine_Collection); $this->assertTrue($component->AliasM2M instanceof Doctrine_Collection);
$component->AliasM2M[0]->name = '1';
$component->AliasM2M[1]->name = '2';
$component->name = '2';
$count = $this->dbh->count();
$component->save();
$this->assertEqual($this->dbh->count(), ($count + 5));
$this->assertEqual($component->AliasM2M->count(), 2);
$component = $component->getTable()->find($component->id);
$this->assertEqual($component->AliasM2M->count(), 2);
} }
public function testManyToManyRelation() { public function testManyToManyRelation() {
$this->manager->setAttribute(Doctrine::ATTR_CREATE_TABLES, false);
$user = new User(); $user = new User();
// test that join table relations can be initialized even before the association have been initialized // test that join table relations can be initialized even before the association have been initialized

View File

@ -9,7 +9,7 @@
class Doctrine_SchemaTestCase extends Doctrine_UnitTestCase class Doctrine_SchemaTestCase extends Doctrine_UnitTestCase
{ {
function testEverySchemaObjectIsThrowingExceptionOnNonPropertyAssignment() public function testEverySchemaObjectIsThrowingExceptionOnNonPropertyAssignment()
{ {
$isException = false; $isException = false;
$obj = new Doctrine_Schema(); $obj = new Doctrine_Schema();
@ -62,7 +62,7 @@ class Doctrine_SchemaTestCase extends Doctrine_UnitTestCase
$this->assertTrue($isException); $this->assertTrue($isException);
} }
function testEverySchemaObjectIsThrowingExceptionOnNonPropertyAccess() public function testEverySchemaObjectIsThrowingExceptionOnNonPropertyAccess()
{ {
$isException = false; $isException = false;
$obj = new Doctrine_Schema(); $obj = new Doctrine_Schema();
@ -115,7 +115,7 @@ class Doctrine_SchemaTestCase extends Doctrine_UnitTestCase
$this->assertTrue($isException); $this->assertTrue($isException);
} }
function testSchemaDatabasePropertiesAreAssignableAndAccessible() public function testSchemaDatabasePropertiesAreAssignableAndAccessible()
{ {
$obj = new Doctrine_Schema_Database(); $obj = new Doctrine_Schema_Database();
$vars = array( $vars = array(
@ -135,7 +135,7 @@ class Doctrine_SchemaTestCase extends Doctrine_UnitTestCase
} }
function testSchemaTablePropertiesAreAssignableAndAccessible() public function testSchemaTablePropertiesAreAssignableAndAccessible()
{ {
$obj = new Doctrine_Schema_Table(); $obj = new Doctrine_Schema_Table();
$vars = array( $vars = array(
@ -152,19 +152,19 @@ class Doctrine_SchemaTestCase extends Doctrine_UnitTestCase
} }
} }
function testSchemaColumnPropertiesAreAssignableAndAccessible() public function testSchemaColumnPropertiesAreAssignableAndAccessible()
{ {
$obj = new Doctrine_Schema_Column(); $obj = new Doctrine_Schema_Column();
$vars = array( $vars = array(
'name' => 'id', 'name' => 'id',
'type' => 'int', 'type' => 'int',
'length' => 10, 'length' => 10,
'autoincrement' => true, 'autoinc' => true,
'default' => null, 'default' => null,
'notNull' => true, 'notnull' => true,
'description' => 'user id', // 'description' => 'user id',
'check' => 'id > 0', // 'check' => 'id > 0',
'charset' => 'UTF-8' // 'charset' => 'UTF-8'
); );
foreach ($vars as $key => $val) foreach ($vars as $key => $val)
@ -174,12 +174,12 @@ class Doctrine_SchemaTestCase extends Doctrine_UnitTestCase
} }
} }
function testSchemaDatabaseIsCloneable() public function testSchemaDatabaseIsCloneable()
{ {
} }
function testSchemaIsTraversable() public function testSchemaIsTraversable()
{ {
/* @todo complete */ /* @todo complete */

View File

@ -56,6 +56,11 @@ print "<pre>";
$test = new GroupTest("Doctrine Framework Unit Tests"); $test = new GroupTest("Doctrine Framework Unit Tests");
$test->addTestCase(new Doctrine_Import_TestCase());
$test->addTestCase(new Doctrine_SchemaTestCase());
$test->addTestCase(new Doctrine_Relation_TestCase()); $test->addTestCase(new Doctrine_Relation_TestCase());
$test->addTestCase(new Doctrine_RecordTestCase()); $test->addTestCase(new Doctrine_RecordTestCase());
@ -96,12 +101,6 @@ $test->addTestCase(new Doctrine_Filter_TestCase());
$test->addTestCase(new Doctrine_RawSql_TestCase()); $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_CollectionTestCase()); $test->addTestCase(new Doctrine_CollectionTestCase());
$test->addTestCase(new Doctrine_Query_ReferenceModel_TestCase()); $test->addTestCase(new Doctrine_Query_ReferenceModel_TestCase());
@ -120,6 +119,8 @@ $test->addTestCase(new Doctrine_EnumTestCase());
$test->addTestCase(new Doctrine_Record_Filter_TestCase()); $test->addTestCase(new Doctrine_Record_Filter_TestCase());
$test->addTestCase(new Doctrine_Query_Limit_TestCase());
$test->addTestCase(new Doctrine_Query_Condition_TestCase()); $test->addTestCase(new Doctrine_Query_Condition_TestCase());
$test->addTestCase(new Doctrine_Query_ComponentAlias_TestCase()); $test->addTestCase(new Doctrine_Query_ComponentAlias_TestCase());