Developed Doctrine_Import, changed Doctrine_Schema objects to have unified constructor
This commit is contained in:
parent
0c0e6fd637
commit
daaab94cfe
@ -35,22 +35,13 @@
|
||||
* reading to a reader object and passes the result to a builder object which
|
||||
* builds a Doctrine data model.
|
||||
*/
|
||||
class Doctrine_Import
|
||||
{
|
||||
|
||||
/** Aggregations: */
|
||||
|
||||
/** Compositions: */
|
||||
|
||||
/*** Attributes: ***/
|
||||
|
||||
class Doctrine_Import {
|
||||
/**
|
||||
* @access private
|
||||
* @var Doctrine_Import_Reader $reader
|
||||
*/
|
||||
private $reader;
|
||||
|
||||
/**
|
||||
* @access private
|
||||
* @var Doctrine_Import_Builder $builder
|
||||
*/
|
||||
private $builder;
|
||||
|
||||
@ -62,29 +53,21 @@ class Doctrine_Import
|
||||
*/
|
||||
public function import( ) {
|
||||
|
||||
} // end of member function import
|
||||
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @param Doctrine_Import_Reader reader * @return
|
||||
* @access public
|
||||
* @param Doctrine_Import_Reader reader
|
||||
* @return void
|
||||
*/
|
||||
public function setReader( $reader ) {
|
||||
|
||||
} // end of member function setReader
|
||||
|
||||
public function setReader(Doctrine_Import_Reader $reader) {
|
||||
$this->reader = $reader;
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @param Doctrine_Import_Builder builder * @return
|
||||
* @access public
|
||||
* @param Doctrine_Import_Builder builder
|
||||
* @return void
|
||||
*/
|
||||
public function setBuilder( $builder ) {
|
||||
|
||||
} // end of member function setBuilder
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
} // end of Doctrine_Import
|
||||
|
||||
public function setBuilder(Doctrine_Import_Builder $builder) {
|
||||
$this->builder = $builder;
|
||||
}
|
||||
}
|
||||
|
@ -33,28 +33,96 @@
|
||||
* class Doctrine_Import_Builder
|
||||
* Is responsible of building Doctrine structure based on a database schema.
|
||||
*/
|
||||
abstract class Doctrine_Import_Builder
|
||||
{
|
||||
class Doctrine_Import_Builder {
|
||||
|
||||
private $path = '';
|
||||
|
||||
private $suffix = '.php';
|
||||
|
||||
/** Aggregations: */
|
||||
|
||||
/** Compositions: */
|
||||
|
||||
/*** 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
|
||||
* @abstract
|
||||
* @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
|
||||
|
||||
}
|
||||
|
@ -33,51 +33,5 @@
|
||||
* class Doctrine_Import_Builder_BaseClass
|
||||
* Builds a Doctrine_Record base class definition based on a schema.
|
||||
*/
|
||||
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
|
||||
|
||||
class Doctrine_Import_Builder_BaseClass extends Doctrine_Import_Builder {
|
||||
}
|
||||
|
@ -18,7 +18,7 @@
|
||||
* and is licensed under the LGPL. For more information, see
|
||||
* <http://www.phpdoctrine.com>.
|
||||
*/
|
||||
|
||||
Doctrine::autoload('Doctrine_Import_Exception');
|
||||
/**
|
||||
* @package Doctrine
|
||||
* @url http://www.phpdoctrine.com
|
||||
@ -27,24 +27,7 @@
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* class Doctrine_Import_Builder_Exception
|
||||
*/
|
||||
class Doctrine_Import_Builder_Exception
|
||||
{
|
||||
|
||||
/** Aggregations: */
|
||||
|
||||
/** Compositions: */
|
||||
|
||||
/*** Attributes: ***/
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
} // end of Doctrine_Import_Builder_Exception
|
||||
|
||||
class Doctrine_Import_Builder_Exception extends Doctrine_Import_Exception { }
|
||||
|
13
lib/Doctrine/Import/Builder/Record.tpl
Normal file
13
lib/Doctrine/Import/Builder/Record.tpl
Normal 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() {
|
||||
|
||||
}
|
||||
}
|
32
lib/Doctrine/Import/Exception.php
Normal file
32
lib/Doctrine/Import/Exception.php
Normal 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 { }
|
@ -33,16 +33,7 @@
|
||||
* class Doctrine_Schema
|
||||
* Holds information on one to many databases
|
||||
*/
|
||||
class Doctrine_Schema extends Doctrine_Schema_Object
|
||||
implements Countable, IteratorAggregate
|
||||
{
|
||||
|
||||
/** Aggregations: */
|
||||
|
||||
/** Compositions: */
|
||||
|
||||
/*** Attributes: ***/
|
||||
|
||||
class Doctrine_Schema extends Doctrine_Schema_Object implements Countable, IteratorAggregate {
|
||||
/**
|
||||
* Holds any number of databases contained in the schema
|
||||
* @access private
|
||||
@ -57,7 +48,7 @@ class Doctrine_Schema extends Doctrine_Schema_Object
|
||||
*/
|
||||
public function addDatabase( $database ) {
|
||||
|
||||
} // end of member function addDatabase
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
@ -66,8 +57,7 @@ class Doctrine_Schema extends Doctrine_Schema_Object
|
||||
*/
|
||||
public function __toString( ) {
|
||||
|
||||
} // end of member function __toString
|
||||
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @return bool
|
||||
@ -75,11 +65,5 @@ class Doctrine_Schema extends Doctrine_Schema_Object
|
||||
*/
|
||||
public function isValid( ) {
|
||||
|
||||
} // end of member function isValid
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
} // end of Doctrine_Schema
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -40,18 +40,15 @@ class Doctrine_Schema_Column extends Doctrine_Schema_Object implements IteratorA
|
||||
*/
|
||||
protected $definition = array('name' => '',
|
||||
'type' => '',
|
||||
'length' => 0,
|
||||
'unique' => false,
|
||||
'primary' => 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() {
|
||||
return $this->definition['name'];
|
||||
}
|
||||
|
@ -26,65 +26,21 @@
|
||||
* @author Jukka Hassinen <Jukka.Hassinen@BrainAlliance.com>
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* class Doctrine_Schema_Database
|
||||
* Holds information on a database
|
||||
*/
|
||||
class Doctrine_Schema_Database extends Doctrine_Schema_Object
|
||||
implements Countable, IteratorAggregate
|
||||
{
|
||||
class Doctrine_Schema_Database extends Doctrine_Schema_Object {
|
||||
|
||||
protected $definition = array('name' => null,
|
||||
'type' => null,
|
||||
'charset' => null,
|
||||
'description' => null,
|
||||
'version' => null,
|
||||
'engine' => null);
|
||||
|
||||
/** 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;
|
||||
|
||||
|
||||
/**
|
||||
@ -94,8 +50,7 @@ class Doctrine_Schema_Database extends Doctrine_Schema_Object
|
||||
*/
|
||||
public function __clone( ) {
|
||||
|
||||
} // end of member function __clone
|
||||
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @return
|
||||
@ -103,8 +58,7 @@ class Doctrine_Schema_Database extends Doctrine_Schema_Object
|
||||
*/
|
||||
public function __toString( ) {
|
||||
|
||||
} // end of member function __toString
|
||||
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @return bool
|
||||
@ -112,8 +66,7 @@ class Doctrine_Schema_Database extends Doctrine_Schema_Object
|
||||
*/
|
||||
public function isValid( ) {
|
||||
|
||||
} // end of member function isValid
|
||||
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @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 ) {
|
||||
|
||||
} // end of member function addTable
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
} // end of Doctrine_Schema_Database
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -18,7 +18,7 @@
|
||||
* 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
|
||||
@ -32,19 +32,4 @@
|
||||
/**
|
||||
* class Doctrine_Schema_Exception
|
||||
*/
|
||||
class Doctrine_Schema_Exception extends Exception
|
||||
{
|
||||
|
||||
/** Aggregations: */
|
||||
|
||||
/** Compositions: */
|
||||
|
||||
/*** Attributes: ***/
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
} // end of Doctrine_Schema_Exception
|
||||
|
||||
class Doctrine_Schema_Exception extends Exception { }
|
||||
|
@ -18,36 +18,54 @@
|
||||
* and is licensed under the LGPL. For more information, see
|
||||
* <http://www.phpdoctrine.com>.
|
||||
*/
|
||||
|
||||
Doctrine::autoload('Doctrine_Access');
|
||||
/**
|
||||
* @package Doctrine
|
||||
* @url http://www.phpdoctrine.com
|
||||
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
|
||||
* @author Jukka Hassinen <Jukka.Hassinen@BrainAlliance.com>
|
||||
* @author Konsta Vesterinen
|
||||
* @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 {
|
||||
abstract class Doctrine_Schema_Object extends Doctrine_Access implements IteratorAggregate, Countable {
|
||||
|
||||
protected $children = array();
|
||||
|
||||
protected $definition = array('name' => '');
|
||||
|
||||
public function __construct(array $definition) {
|
||||
public function __construct(array $definition = array()) {
|
||||
foreach($this->definition as $key => $val) {
|
||||
if(isset($definition[$key]))
|
||||
$this->definition[$key] = $definition[$key];
|
||||
}
|
||||
}
|
||||
|
||||
public function get($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 getName() {
|
||||
return $this->definition['name'];
|
||||
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
|
||||
*/
|
||||
public function count() {
|
||||
if( ! empty($this->childs))
|
||||
return count($this->childs);
|
||||
if( ! empty($this->children))
|
||||
return count($this->children);
|
||||
|
||||
return count($this->definition);
|
||||
}
|
||||
@ -68,8 +86,8 @@ abstract class Doctrine_Schema_Object implements IteratorAggregate, Countable {
|
||||
* @access public
|
||||
*/
|
||||
public function getIterator() {
|
||||
if( ! empty($this->childs))
|
||||
return new ArrayIterator($this->childs);
|
||||
if( ! empty($this->children))
|
||||
return new ArrayIterator($this->children);
|
||||
|
||||
return new ArrayIterator($this->definition);
|
||||
}
|
||||
|
@ -33,14 +33,7 @@
|
||||
* class Doctrine_Schema_Relation
|
||||
* Holds information on a foreign key relation.
|
||||
*/
|
||||
class Doctrine_Schema_Relation extends Doctrine_Schema_Object
|
||||
{
|
||||
|
||||
/** Aggregations: */
|
||||
|
||||
/** Compositions: */
|
||||
|
||||
/*** Attributes: ***/
|
||||
class Doctrine_Schema_Relation extends Doctrine_Schema_Object {
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
public function setRelationBetween( $referringColumns, $referencedColumns ) {
|
||||
|
||||
} // end of member function setRelationBetween
|
||||
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @return
|
||||
@ -106,8 +100,7 @@ class Doctrine_Schema_Relation extends Doctrine_Schema_Object
|
||||
*/
|
||||
public function __toString( ) {
|
||||
|
||||
} // end of member function __toString
|
||||
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @return bool
|
||||
@ -115,11 +108,5 @@ class Doctrine_Schema_Relation extends Doctrine_Schema_Object
|
||||
*/
|
||||
public function isValid( ) {
|
||||
|
||||
} // end of member function isValid
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
} // end of Doctrine_Schema_Relation
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -33,50 +33,13 @@
|
||||
* class Doctrine_Schema_Table
|
||||
* Holds information on a database table
|
||||
*/
|
||||
class Doctrine_Schema_Table extends Doctrine_Schema_Object
|
||||
implements Countable, Countable, IteratorAggregate
|
||||
{
|
||||
class Doctrine_Schema_Table extends Doctrine_Schema_Object implements Countable, IteratorAggregate {
|
||||
|
||||
protected $definition = array('name' => '',
|
||||
'check' => '',
|
||||
'charset' => '',
|
||||
'description' => '');
|
||||
|
||||
/**
|
||||
* 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;
|
||||
/**
|
||||
*
|
||||
* @return bool
|
||||
@ -109,7 +72,7 @@ class Doctrine_Schema_Table extends Doctrine_Schema_Object
|
||||
* @access public
|
||||
*/
|
||||
public function addColumn(Doctrine_Schema_Column $column) {
|
||||
$name = $column->getName();
|
||||
$name = $column->get('name');
|
||||
$this->children[$name] = $column;
|
||||
|
||||
return $this;
|
||||
|
@ -3,13 +3,13 @@
|
||||
* ImportTestCase.php - 24.8.2006 2.37.14
|
||||
*
|
||||
* Note that some shortcuts maybe used here
|
||||
* i.e. these tests depends that exporting is working
|
||||
* i.e. these tests depends that exporting is working
|
||||
*
|
||||
* @author Jukka Hassinen <Jukka.Hassinen@BrainAlliance.com>
|
||||
* @version $Id$
|
||||
* @package Doctrine
|
||||
*/
|
||||
class Doctrine_ImportTestCase extends Doctrine_UnitTestCase
|
||||
class Doctrine_Import_TestCase extends Doctrine_UnitTestCase
|
||||
{
|
||||
private $tmpdir;
|
||||
|
||||
@ -25,17 +25,50 @@ class Doctrine_ImportTestCase extends Doctrine_UnitTestCase
|
||||
$reader = new Doctrine_Import_Reader_Db();
|
||||
$reader->setPdo($this->dbh);
|
||||
$this->schema = $reader->read();
|
||||
}
|
||||
|
||||
public function testBadImport() {
|
||||
$builder = new Doctrine_Import_Builder();
|
||||
|
||||
try {
|
||||
$builder->buildRecord(new Doctrine_Schema_Table());
|
||||
|
||||
//and building
|
||||
$this->tmpdir = $this->getTempDir();
|
||||
$this->suffix = '__Base';
|
||||
$this->fail();
|
||||
} catch(Doctrine_Import_Builder_Exception $e) {
|
||||
$this->pass();
|
||||
}
|
||||
|
||||
$builder = new Doctrine_Import_Builder_BaseClass();
|
||||
$builder->setOutputPath($this->tmpdir);
|
||||
$builder->setFileSuffix($this->suffix.'.php');
|
||||
$builder->build($this->schema);
|
||||
}
|
||||
|
||||
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()
|
||||
{
|
||||
|
||||
@ -62,9 +95,9 @@ class Doctrine_ImportTestCase extends Doctrine_UnitTestCase
|
||||
{
|
||||
$transArr = array();
|
||||
|
||||
/* From SQLite column types */
|
||||
|
||||
$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('varchar', 255, 'string', 255),
|
||||
);
|
||||
@ -103,21 +136,16 @@ 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()
|
||||
{
|
||||
/**
|
||||
if(function_exists('sys_get_temp_dir')) {
|
||||
$tempdir = sys_get_temp_dir();
|
||||
$tempdir = sys_get_temp_dir();
|
||||
} elseif (!empty($_ENV['TMP'])) {
|
||||
$tempdir = $_ENV['TMP'];
|
||||
} elseif (!empty($_ENV['TMPDIR'])) {
|
||||
@ -130,21 +158,22 @@ class Doctrine_ImportTestCase extends Doctrine_UnitTestCase
|
||||
}
|
||||
|
||||
if (empty($tempdir)) { return null; }
|
||||
|
||||
|
||||
$tempdir = rtrim($tempdir, '/');
|
||||
$tempdir .= DIRECTORY_SEPARATOR;
|
||||
|
||||
|
||||
if (is_writable($tempdir) == false) {
|
||||
return null;
|
||||
}
|
||||
$dir = tempnam($tempdir, 'doctrine_tests');
|
||||
|
||||
|
||||
@unlink($dir);
|
||||
@rmdir($dir);
|
||||
|
||||
|
||||
mkdir($dir);
|
||||
$dir .= DIRECTORY_SEPARATOR;
|
||||
|
||||
return $dir;
|
||||
|
||||
return $dir;
|
||||
*/
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,8 @@
|
||||
<?php
|
||||
|
||||
class RelationTest extends Doctrine_Record {
|
||||
public function setTableDefinition() {
|
||||
$this->hasColumn('name', 'string', 200);
|
||||
$this->hasColumn("child_id", "integer");
|
||||
}
|
||||
public function setUp() {
|
||||
@ -10,7 +12,7 @@ class RelationTest extends Doctrine_Record {
|
||||
}
|
||||
class RelationTestChild extends RelationTest {
|
||||
public function setUp() {
|
||||
$this->hasOne('RelationTest as Parent', 'RelationTestChild.child_id');
|
||||
$this->hasOne('RelationTest as Parent', 'RelationTestChild.child_id');
|
||||
|
||||
$this->ownsMany('RelationTestChild as Children', 'RelationTestChild.child_id');
|
||||
}
|
||||
@ -40,7 +42,9 @@ class OwnsOneToManyWithAlias extends Doctrine_Record {
|
||||
}
|
||||
}
|
||||
class HasManyToManyWithAlias extends Doctrine_Record {
|
||||
public function setTableDefinition() { }
|
||||
public function setTableDefinition() {
|
||||
$this->hasColumn('name', 'string', 200);
|
||||
}
|
||||
public function setUp() {
|
||||
$this->hasMany('RelationTest as AliasM2M', 'JoinTable.c2_id');
|
||||
}
|
||||
@ -48,7 +52,9 @@ class HasManyToManyWithAlias extends Doctrine_Record {
|
||||
class Doctrine_Relation_TestCase extends Doctrine_UnitTestCase {
|
||||
public function prepareData() { }
|
||||
public function prepareTables() {
|
||||
$this->tables = array();
|
||||
$this->tables = array('HasManyToManyWithAlias', 'RelationTest', 'JoinTable');
|
||||
|
||||
parent::prepareTables();
|
||||
}
|
||||
public function testOneToManyTreeRelationWithConcreteInheritance() {
|
||||
$component = new RelationTestChild();
|
||||
@ -78,7 +84,7 @@ class Doctrine_Relation_TestCase extends Doctrine_UnitTestCase {
|
||||
$this->assertTrue($rel instanceof Doctrine_Relation_LocalKey);
|
||||
}
|
||||
public function testOneToManyOwnsRelationWithAliases() {
|
||||
$this->manager->setAttribute(Doctrine::ATTR_CREATE_TABLES, false);
|
||||
|
||||
|
||||
$component = new RelationTest();
|
||||
|
||||
@ -104,10 +110,26 @@ class Doctrine_Relation_TestCase extends Doctrine_UnitTestCase {
|
||||
|
||||
$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() {
|
||||
$this->manager->setAttribute(Doctrine::ATTR_CREATE_TABLES, false);
|
||||
$user = new User();
|
||||
|
||||
// test that join table relations can be initialized even before the association have been initialized
|
||||
|
@ -9,7 +9,7 @@
|
||||
class Doctrine_SchemaTestCase extends Doctrine_UnitTestCase
|
||||
{
|
||||
|
||||
function testEverySchemaObjectIsThrowingExceptionOnNonPropertyAssignment()
|
||||
public function testEverySchemaObjectIsThrowingExceptionOnNonPropertyAssignment()
|
||||
{
|
||||
$isException = false;
|
||||
$obj = new Doctrine_Schema();
|
||||
@ -62,7 +62,7 @@ class Doctrine_SchemaTestCase extends Doctrine_UnitTestCase
|
||||
$this->assertTrue($isException);
|
||||
}
|
||||
|
||||
function testEverySchemaObjectIsThrowingExceptionOnNonPropertyAccess()
|
||||
public function testEverySchemaObjectIsThrowingExceptionOnNonPropertyAccess()
|
||||
{
|
||||
$isException = false;
|
||||
$obj = new Doctrine_Schema();
|
||||
@ -115,7 +115,7 @@ class Doctrine_SchemaTestCase extends Doctrine_UnitTestCase
|
||||
$this->assertTrue($isException);
|
||||
}
|
||||
|
||||
function testSchemaDatabasePropertiesAreAssignableAndAccessible()
|
||||
public function testSchemaDatabasePropertiesAreAssignableAndAccessible()
|
||||
{
|
||||
$obj = new Doctrine_Schema_Database();
|
||||
$vars = array(
|
||||
@ -135,7 +135,7 @@ class Doctrine_SchemaTestCase extends Doctrine_UnitTestCase
|
||||
|
||||
}
|
||||
|
||||
function testSchemaTablePropertiesAreAssignableAndAccessible()
|
||||
public function testSchemaTablePropertiesAreAssignableAndAccessible()
|
||||
{
|
||||
$obj = new Doctrine_Schema_Table();
|
||||
$vars = array(
|
||||
@ -152,19 +152,19 @@ class Doctrine_SchemaTestCase extends Doctrine_UnitTestCase
|
||||
}
|
||||
}
|
||||
|
||||
function testSchemaColumnPropertiesAreAssignableAndAccessible()
|
||||
public function testSchemaColumnPropertiesAreAssignableAndAccessible()
|
||||
{
|
||||
$obj = new Doctrine_Schema_Column();
|
||||
$vars = array(
|
||||
'name' => 'id',
|
||||
'type' => 'int',
|
||||
'length' => 10,
|
||||
'autoincrement' => true,
|
||||
'autoinc' => true,
|
||||
'default' => null,
|
||||
'notNull' => true,
|
||||
'description' => 'user id',
|
||||
'check' => 'id > 0',
|
||||
'charset' => 'UTF-8'
|
||||
'notnull' => true,
|
||||
// 'description' => 'user id',
|
||||
// 'check' => 'id > 0',
|
||||
// 'charset' => 'UTF-8'
|
||||
);
|
||||
|
||||
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 */
|
||||
|
||||
@ -198,4 +198,4 @@ class Doctrine_SchemaTestCase extends Doctrine_UnitTestCase
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -56,6 +56,11 @@ print "<pre>";
|
||||
|
||||
$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_RecordTestCase());
|
||||
@ -96,12 +101,6 @@ $test->addTestCase(new Doctrine_Filter_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_Query_ReferenceModel_TestCase());
|
||||
@ -119,6 +118,8 @@ $test->addTestCase(new Doctrine_BooleanTestCase());
|
||||
$test->addTestCase(new Doctrine_EnumTestCase());
|
||||
|
||||
$test->addTestCase(new Doctrine_Record_Filter_TestCase());
|
||||
|
||||
$test->addTestCase(new Doctrine_Query_Limit_TestCase());
|
||||
|
||||
$test->addTestCase(new Doctrine_Query_Condition_TestCase());
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user