diff --git a/lib/Doctrine/Export/Schema.php b/lib/Doctrine/Export/Schema.php index a280f6efa..e737bf2fd 100644 --- a/lib/Doctrine/Export/Schema.php +++ b/lib/Doctrine/Export/Schema.php @@ -37,36 +37,7 @@ * @author Nicolas Bérard-Nault */ class Doctrine_Export_Schema -{ - /** - * build - * - * Build the schema string to be dumped to file - * - * @param string $array - * @return void - */ - public function build($array) - { - throw new Doctrine_Export_Exception('This functionality is implemented by the driver'); - } - - /** - * dump - * - * Dump the array to the schema file - * - * @param string $array - * @param string $schema - * @return void - */ - public function dump($array, $schema) - { - $data = $this->build($array); - - file_put_contents($schema, $data); - } - +{ /** * buildSchema * @@ -171,11 +142,8 @@ class Doctrine_Export_Schema */ public function exportSchema($schema, $format, $directory, $models = array()) { - $className = 'Doctrine_Export_Schema_'.ucwords($format); + $array = $this->buildSchema($directory, $models); - $export = new $className(); - $array = $export->buildSchema($directory, $models); - - return $export->dump($array, $schema); + Doctrine_Parser::dump($array, $format, $schema); } } \ No newline at end of file diff --git a/lib/Doctrine/Export/Schema/Xml.php b/lib/Doctrine/Export/Schema/Xml.php deleted file mode 100644 index d5d90493e..000000000 --- a/lib/Doctrine/Export/Schema/Xml.php +++ /dev/null @@ -1,46 +0,0 @@ -. - */ - -/** - * class Doctrine_Export_Schema_Xml - * - * @package Doctrine - * @category Object Relational Mapping - * @link www.phpdoctrine.com - * @license http://www.opensource.org/licenses/lgpl-license.php LGPL - * @version $Revision: 1838 $ - * @author Nicolas Bérard-Nault - */ -class Doctrine_Export_Schema_Xml extends Doctrine_Export_Schema -{ - /** - * build - * - * Build the schema xml string to be dumped to file - * - * @param string $array - * @return void - */ - public function build($array) - { - return Doctrine_Parser::dump($array, 'yml'); - } -} \ No newline at end of file diff --git a/lib/Doctrine/Export/Schema/Yml.php b/lib/Doctrine/Export/Schema/Yml.php deleted file mode 100644 index 557c23d54..000000000 --- a/lib/Doctrine/Export/Schema/Yml.php +++ /dev/null @@ -1,46 +0,0 @@ -. - */ - -/** - * class Doctrine_Export_Schema_Yml - * - * @package Doctrine - * @category Object Relational Mapping - * @link www.phpdoctrine.com - * @license http://www.opensource.org/licenses/lgpl-license.php LGPL - * @version $Revision: 1838 $ - * @author Nicolas Bérard-Nault - */ -class Doctrine_Export_Schema_Yml extends Doctrine_Export_Schema -{ - /** - * build - * - * Build the schema yml string to be dumped to file - * - * @param string $array - * @return void - */ - public function build($array) - { - return Doctrine_Parser::dump($array, 'yml'); - } -} \ No newline at end of file diff --git a/lib/Doctrine/Import/Schema.php b/lib/Doctrine/Import/Schema.php index 66858494b..0eaf70783 100644 --- a/lib/Doctrine/Import/Schema.php +++ b/lib/Doctrine/Import/Schema.php @@ -41,34 +41,7 @@ class Doctrine_Import_Schema { public $relations = array(); - /** - * Parse the schema and return it in an array - * - * @param string $schema - * @access public - */ - public function parseSchema($schema) - { - throw new Doctrine_Import_Exception('This functionality is implemented by the driver'); - } - /** - * parse - * - * Function to do the actual parsing of the file - * - * @param string $schema - * @return void - * @author Jonathan H. Wage - */ - public function parse($schema) - { - $class = get_class($this); - $type = strtolower(str_replace('Doctrine_Import_Schema_', '', $class)); - - return Doctrine_Parser::load($schema, $type); - } - /** * importSchema * @@ -82,19 +55,15 @@ class Doctrine_Import_Schema */ public function importSchema($schema, $format, $directory, $models = array()) { - $className = 'Doctrine_Import_Schema_'.ucwords($format); - - $import = new $className(); - $builder = new Doctrine_Import_Builder(); $builder->setTargetPath($directory); $array = array(); foreach ((array) $schema AS $s) { - $array = array_merge($array, $import->parseSchema($s)); + $array = array_merge($array, $this->parseSchema($s, $format)); } - $import->buildRelationships($array); + $this->buildRelationships($array); foreach ($array as $name => $properties) { if (!empty($models) && !in_array($properties['className'], $models)) { @@ -107,11 +76,59 @@ class Doctrine_Import_Schema $columns = $properties['columns']; - $relations = isset($import->relations[$options['className']]) ? $import->relations[$options['className']]:array(); + $relations = isset($this->relations[$options['className']]) ? $this->relations[$options['className']]:array(); $builder->buildRecord($options, $columns, $relations); } - } + } + + /** + * parseSchema + * + * A method to parse a Yml Schema and translate it into a property array. + * The function returns that property array. + * + * @param string $schema Path to the file containing the XML schema + * @return array + */ + public function parseSchema($schema, $type) + { + $array = Doctrine_Parser::load($schema, $type); + + $build = array(); + + foreach ($array as $className => $table) { + $columns = array(); + + $className = isset($table['className']) ? (string) $table['className']:(string) $className; + $tableName = isset($table['tableName']) ? (string) $table['tableName']:(string) $className; + + foreach ($table['columns'] as $columnName => $field) { + + $colDesc = array(); + $colDesc['name'] = isset($field['name']) ? (string) $field['name']:$columnName; + $colDesc['type'] = isset($field['type']) ? (string) $field['type']:null; + $colDesc['ptype'] = isset($field['ptype']) ? (string) $field['ptype']:(string) $colDesc['type']; + $colDesc['length'] = isset($field['length']) ? (int) $field['length']:null; + $colDesc['fixed'] = isset($field['fixed']) ? (int) $field['fixed']:null; + $colDesc['unsigned'] = isset($field['unsigned']) ? (bool) $field['unsigned']:null; + $colDesc['primary'] = isset($field['primary']) ? (bool) (isset($field['primary']) && $field['primary']):null; + $colDesc['default'] = isset($field['default']) ? (string) $field['default']:null; + $colDesc['notnull'] = isset($field['notnull']) ? (bool) (isset($field['notnull']) && $field['notnull']):null; + $colDesc['autoinc'] = isset($field['autoinc']) ? (bool) (isset($field['autoinc']) && $field['autoinc']):null; + + $columns[(string) $colDesc['name']] = $colDesc; + } + + $build[$className]['tableName'] = $tableName; + $build[$className]['className'] = $className; + + $build[$className]['columns'] = $columns; + $build[$className]['relations'] = isset($table['relations']) ? $table['relations']:array(); + } + + return $build; + } public function buildRelationships($array) { diff --git a/lib/Doctrine/Import/Schema/Xml.php b/lib/Doctrine/Import/Schema/Xml.php deleted file mode 100644 index d87a0b25c..000000000 --- a/lib/Doctrine/Import/Schema/Xml.php +++ /dev/null @@ -1,86 +0,0 @@ -. - */ - -/** - * class Doctrine_Import_Xml - * - * Different methods to import a XML schema. The logic behind using two different - * methods is simple. Some people will like the idea of producing Doctrine_Record - * objects directly, which is totally fine. But in fast and growing application, - * table definitions tend to be a little bit more volatile. importArr() can be used - * to output a table definition in a PHP file. This file can then be stored - * independantly from the object itself. - * - * @package Doctrine - * @category Object Relational Mapping - * @link www.phpdoctrine.com - * @license http://www.opensource.org/licenses/lgpl-license.php LGPL - * @version $Revision: 1838 $ - * @author Nicolas Bérard-Nault - * @author Jonathan H. Wage - */ -class Doctrine_Import_Schema_Xml extends Doctrine_Import_Schema -{ - /** - * parseSchema - * - * A method to parse a XML Schema and translate it into a property array. - * The function returns that property array. - * - * @param string $schema Path to the file containing the XML schema - * @return array - */ - public function parseSchema($schema) - { - $xmlObj = $this->parse($schema); - - foreach ($xmlObj->tables as $table) { - $columns = array(); - - // Go through all columns... - foreach ($table->columns as $column) { - $colDesc = array( - 'name' => (string) $column->name, - 'type' => (string) $column->type, - 'ptype' => (string) $column->type, - 'length' => (int) $column->length, - 'fixed' => (int) $column->fixed, - 'unsigned' => (bool) $column->unsigned, - 'primary' => (bool) (isset($column->primary) && $column->primary), - 'default' => (string) $column->default, - 'notnull' => (bool) (isset($column->notnull) && $column->notnull), - 'autoinc' => (bool) (isset($column->autoincrement) && $column->autoincrement), - ); - - $columns[(string) $column->name] = $colDesc; - } - - $class = $table->class ? (string) $table->class:(string) $table->name; - - $tables[(string) $table->name]['name'] = (string) $table->name; - $tables[(string) $table->name]['class'] = (string) $class; - - $tables[(string) $table->name]['columns'] = $columns; - } - - return $tables; - } -} \ No newline at end of file diff --git a/lib/Doctrine/Import/Schema/Yml.php b/lib/Doctrine/Import/Schema/Yml.php deleted file mode 100644 index 7e0d32c5a..000000000 --- a/lib/Doctrine/Import/Schema/Yml.php +++ /dev/null @@ -1,87 +0,0 @@ -. - */ - -/** - * class Doctrine_Import_Schema_Yml - * - * Different methods to import a YML schema. The logic behind using two different - * methods is simple. Some people will like the idea of producing Doctrine_Record - * objects directly, which is totally fine. But in fast and growing application, - * table definitions tend to be a little bit more volatile. importArr() can be used - * to output a table definition in a PHP file. This file can then be stored - * independantly from the object itself. - * - * @package Doctrine - * @category Object Relational Mapping - * @link www.phpdoctrine.com - * @license http://www.opensource.org/licenses/lgpl-license.php LGPL - * @version $Revision: 1838 $ - * @author Nicolas Bérard-Nault - * @author Jonathan H. Wage - */ -class Doctrine_Import_Schema_Yml extends Doctrine_Import_Schema -{ - /** - * parseSchema - * - * A method to parse a Yml Schema and translate it into a property array. - * The function returns that property array. - * - * @param string $schema Path to the file containing the XML schema - * @return array - */ - public function parseSchema($schema) - { - $array = $this->parse($schema); - - foreach ($array as $className => $table) { - $columns = array(); - - $className = isset($table['className']) ? (string) $table['className']:(string) $className; - $tableName = isset($table['tableName']) ? (string) $table['tableName']:(string) $className; - - foreach ($table['columns'] as $columnName => $field) { - - $colDesc = array(); - $colDesc['name'] = isset($field['name']) ? (string) $field['name']:$columnName; - $colDesc['type'] = isset($field['type']) ? (string) $field['type']:null; - $colDesc['ptype'] = isset($field['ptype']) ? (string) $field['ptype']:(string) $colDesc['type']; - $colDesc['length'] = isset($field['length']) ? (int) $field['length']:null; - $colDesc['fixed'] = isset($field['fixed']) ? (int) $field['fixed']:null; - $colDesc['unsigned'] = isset($field['unsigned']) ? (bool) $field['unsigned']:null; - $colDesc['primary'] = isset($field['primary']) ? (bool) (isset($field['primary']) && $field['primary']):null; - $colDesc['default'] = isset($field['default']) ? (string) $field['default']:null; - $colDesc['notnull'] = isset($field['notnull']) ? (bool) (isset($field['notnull']) && $field['notnull']):null; - $colDesc['autoinc'] = isset($field['autoinc']) ? (bool) (isset($field['autoinc']) && $field['autoinc']):null; - - $columns[(string) $colDesc['name']] = $colDesc; - } - - $tables[$className]['tableName'] = $tableName; - $tables[$className]['className'] = $className; - - $tables[$className]['columns'] = $columns; - $tables[$className]['relations'] = isset($table['relations']) ? $table['relations']:array(); - } - - return $tables; - } -} \ No newline at end of file diff --git a/lib/Doctrine/Parser/Xml.php b/lib/Doctrine/Parser/Xml.php index 789a3b660..84c3ae7c6 100644 --- a/lib/Doctrine/Parser/Xml.php +++ b/lib/Doctrine/Parser/Xml.php @@ -67,18 +67,48 @@ class Doctrine_Parser_Xml extends Doctrine_Parser public function loadData($path) { - if ( !file_exists($path) OR !is_writeable($path) ) { - throw new Doctrine_Parser_Exception('Xml file '. $path .' could not be read'); - } - - if ( ! ($xmlString = file_get_contents($path))) { - throw new Doctrine_Parser_Exception('Xml file '. $path . ' is empty'); - } - - if (!file_exists($path) OR !is_readable($path) OR !($xmlString = file_get_contents($path))) { + if (file_exists($path) && is_readable($path)) { + $xmlString = file_get_contents($path); + } else { $xmlString = $path; } - return simplexml_load_string($xmlString); + $simpleXml = simplexml_load_string($xmlString); + + return $this->prepareData($simpleXml); + } + + public function prepareData($simpleXml) + { + if ($simpleXml instanceof SimpleXMLElement) { + $children = $simpleXml->children(); + $return = null; + } + + foreach ($children as $element => $value) { + if ($value instanceof SimpleXMLElement) { + $values = (array)$value->children(); + + if (count($values) > 0) { + $return[$element] = $this->prepareData($value); + } else { + if (!isset($return[$element])) { + $return[$element] = (string)$value; + } else { + if (!is_array($return[$element])) { + $return[$element] = array($return[$element], (string)$value); + } else { + $return[$element][] = (string)$value; + } + } + } + } + } + + if (is_array($return)) { + return $return; + } else { + return $false; + } } } \ No newline at end of file diff --git a/lib/Doctrine/Resource.php b/lib/Doctrine/Resource.php new file mode 100644 index 000000000..729000087 --- /dev/null +++ b/lib/Doctrine/Resource.php @@ -0,0 +1,5 @@ +resourceUrl = $resourceUrl; + } + + public function execute($dql = null) + { + $request = array(); + + if ($dql === null) { + $request['parts'] = $this->parts; + } else { + $request['dql'] = $dql; + } + + $request['format'] = $this->format; + + + $ch = curl_init(); + curl_setopt($ch, CURLOPT_URL, $this->resourceUrl); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); + curl_setopt($ch, CURLOPT_POST, 1); + + curl_setopt($ch, CURLOPT_POSTFIELDS, $request); + $data = curl_exec($ch); + + return Doctrine_Parser::load($data, $this->format); + } + + public function setFormat($format) + { + $this->format = $format; + + return $this; + } + + /** + * addSelect + * adds fields to the SELECT part of the query + * + * @param string $select Query SELECT part + * @return Doctrine_Query + */ + public function addSelect($select) + { + return $this->parseQueryPart('select', $select, true); + } + /** + * addFrom + * adds fields to the FROM part of the query + * + * @param string $from Query FROM part + * @return Doctrine_Query + */ + public function addFrom($from) + { + return $this->parseQueryPart('from', $from, true); + } + /** + * addWhere + * adds conditions to the WHERE part of the query + * + * @param string $where Query WHERE part + * @param mixed $params an array of parameters or a simple scalar + * @return Doctrine_Query + */ + public function addWhere($where, $params = array()) + { + if (is_array($params)) { + $this->_params['where'] = array_merge($this->_params['where'], $params); + } else { + $this->_params['where'][] = $params; + } + return $this->parseQueryPart('where', $where, true); + } + /** + * whereIn + * adds IN condition to the query WHERE part + * + * @param string $expr + * @param mixed $params an array of parameters or a simple scalar + * @return Doctrine_Query + */ + public function whereIn($expr, $params = array()) + { + $params = (array) $params; + $a = array(); + foreach ($params as $k => $value) { + if ($value instanceof Doctrine_Expression) { + $value = $value->getSql(); + unset($params[$k]); + } else { + $value = '?'; + } + $a[] = $value; + } + + $this->_params['where'] = array_merge($this->_params['where'], $params); + + $where = $expr . ' IN (' . implode(', ', $a) . ')'; + + return $this->parseQueryPart('where', $where, true); + } + /** + * addGroupBy + * adds fields to the GROUP BY part of the query + * + * @param string $groupby Query GROUP BY part + * @return Doctrine_Query + */ + public function addGroupBy($groupby) + { + return $this->parseQueryPart('groupby', $groupby, true); + } + /** + * addHaving + * adds conditions to the HAVING part of the query + * + * @param string $having Query HAVING part + * @param mixed $params an array of parameters or a simple scalar + * @return Doctrine_Query + */ + public function addHaving($having, $params = array()) + { + if (is_array($params)) { + $this->_params['having'] = array_merge($this->_params['having'], $params); + } else { + $this->_params['having'][] = $params; + } + return $this->parseQueryPart('having', $having, true); + } + /** + * addOrderBy + * adds fields to the ORDER BY part of the query + * + * @param string $orderby Query ORDER BY part + * @return Doctrine_Query + */ + public function addOrderBy($orderby) + { + return $this->parseQueryPart('orderby', $orderby, true); + } + /** + * select + * sets the SELECT part of the query + * + * @param string $select Query SELECT part + * @return Doctrine_Query + */ + public function select($select) + { + return $this->parseQueryPart('select', $select); + } + /** + * distinct + * Makes the query SELECT DISTINCT. + * + * @param bool $flag Whether or not the SELECT is DISTINCT (default true). + * @return Doctrine_Query + */ + public function distinct($flag = true) + { + $this->parts['distinct'] = (bool) $flag; + + return $this; + } + + /** + * forUpdate + * Makes the query SELECT FOR UPDATE. + * + * @param bool $flag Whether or not the SELECT is FOR UPDATE (default true). + * @return Doctrine_Query + */ + public function forUpdate($flag = true) + { + $this->parts[self::FOR_UPDATE] = (bool) $flag; + + return $this; + } + /** + * delete + * sets the query type to DELETE + * + * @return Doctrine_Query + */ + public function delete() + { + $this->type = self::DELETE; + + return $this; + } + /** + * update + * sets the UPDATE part of the query + * + * @param string $update Query UPDATE part + * @return Doctrine_Query + */ + public function update($update) + { + $this->type = self::UPDATE; + + return $this->parseQueryPart('from', $update); + } + /** + * set + * sets the SET part of the query + * + * @param string $update Query UPDATE part + * @return Doctrine_Query + */ + public function set($key, $value, $params = null) + { + if (is_array($key)) { + foreach ($key as $k => $v) { + $this->set($k, '?', array($v)); + } + } else { + if ($params !== null) { + if (is_array($params)) { + $this->_params['set'] = array_merge($this->_params['set'], $params); + } else { + $this->_params['set'][] = $params; + } + } + return $this->parseQueryPart('set', $key . ' = ' . $value, true); + } + } + /** + * from + * sets the FROM part of the query + * + * @param string $from Query FROM part + * @return Doctrine_Query + */ + public function from($from) + { + return $this->parseQueryPart('from', $from); + } + /** + * innerJoin + * appends an INNER JOIN to the FROM part of the query + * + * @param string $join Query INNER JOIN + * @return Doctrine_Query + */ + public function innerJoin($join) + { + return $this->parseQueryPart('from', 'INNER JOIN ' . $join, true); + } + /** + * leftJoin + * appends a LEFT JOIN to the FROM part of the query + * + * @param string $join Query LEFT JOIN + * @return Doctrine_Query + */ + public function leftJoin($join) + { + return $this->parseQueryPart('from', 'LEFT JOIN ' . $join, true); + } + /** + * groupBy + * sets the GROUP BY part of the query + * + * @param string $groupby Query GROUP BY part + * @return Doctrine_Query + */ + public function groupBy($groupby) + { + return $this->parseQueryPart('groupby', $groupby); + } + /** + * where + * sets the WHERE part of the query + * + * @param string $join Query WHERE part + * @param mixed $params an array of parameters or a simple scalar + * @return Doctrine_Query + */ + public function where($where, $params = array()) + { + $this->_params['where'] = array(); + if (is_array($params)) { + $this->_params['where'] = $params; + } else { + $this->_params['where'][] = $params; + } + + return $this->parseQueryPart('where', $where); + } + /** + * having + * sets the HAVING part of the query + * + * @param string $having Query HAVING part + * @param mixed $params an array of parameters or a simple scalar + * @return Doctrine_Query + */ + public function having($having, $params = array()) + { + $this->_params['having'] = array(); + if (is_array($params)) { + $this->_params['having'] = $params; + } else { + $this->_params['having'][] = $params; + } + + return $this->parseQueryPart('having', $having); + } + /** + * orderBy + * sets the ORDER BY part of the query + * + * @param string $orderby Query ORDER BY part + * @return Doctrine_Query + */ + public function orderBy($orderby) + { + return $this->parseQueryPart('orderby', $orderby); + } + /** + * limit + * sets the Query query limit + * + * @param integer $limit limit to be used for limiting the query results + * @return Doctrine_Query + */ + public function limit($limit) + { + return $this->parseQueryPart('limit', $limit); + } + /** + * offset + * sets the Query query offset + * + * @param integer $offset offset to be used for paginating the query + * @return Doctrine_Query + */ + public function offset($offset) + { + return $this->parseQueryPart('offset', $offset); + } + + /** + * parseQueryPart + * parses given DQL query part + * + * @param string $queryPartName the name of the query part + * @param string $queryPart query part to be parsed + * @return Doctrine_Query this object + */ + public function parseQueryPart($queryPartName, $queryPart) + { + $this->parts[$queryPartName][] = $queryPart; + + return $this; + } +} \ No newline at end of file diff --git a/lib/Doctrine/Resource/Server.php b/lib/Doctrine/Resource/Server.php new file mode 100644 index 000000000..f7fec564b --- /dev/null +++ b/lib/Doctrine/Resource/Server.php @@ -0,0 +1,40 @@ +query($request['dql']); + } else { + $result = $this->buildDql($request['parts']); + } + + $data = array(); + foreach ($result as $recordKey => $record) { + $array = $record->toArray(); + + $recordKey = get_class($record). '_' .($recordKey + 1); + + foreach ($array as $valueKey => $value) { + $data[get_class($record)][$recordKey][$valueKey] = $value; + } + } + + $format = isset($request['format']) ? $request['format']:'xml'; + + return Doctrine_Parser::dump($data, $format); + } + + public function buildDql($parts) + { + + } + + public function run() + { + $request = $_REQUEST; + + echo $this->execute($request); + } +} \ No newline at end of file diff --git a/tests/Export/Schema/XmlTestCase.php b/tests/Export/Schema/XmlTestCase.php deleted file mode 100644 index 8756b171e..000000000 --- a/tests/Export/Schema/XmlTestCase.php +++ /dev/null @@ -1,35 +0,0 @@ -. - */ - -/** - * Doctrine_Export_Schema_Xml_TestCase - * - * @package Doctrine - * @author Konsta Vesterinen - * @license http://www.opensource.org/licenses/lgpl-license.php LGPL - * @category Object Relational Mapping - * @link www.phpdoctrine.com - * @since 1.0 - * @version $Revision$ - */ -class Doctrine_Export_Schema_Xml_TestCase extends Doctrine_UnitTestCase -{ -} diff --git a/tests/Export/Schema/YmlTestCase.php b/tests/Export/Schema/YmlTestCase.php deleted file mode 100644 index 89d975042..000000000 --- a/tests/Export/Schema/YmlTestCase.php +++ /dev/null @@ -1,35 +0,0 @@ -. - */ - -/** - * Doctrine_Export_Schema_Yml_TestCase - * - * @package Doctrine - * @author Konsta Vesterinen - * @license http://www.opensource.org/licenses/lgpl-license.php LGPL - * @category Object Relational Mapping - * @link www.phpdoctrine.com - * @since 1.0 - * @version $Revision$ - */ -class Doctrine_Export_Schema_Yml_TestCase extends Doctrine_UnitTestCase -{ -} diff --git a/tests/Export/SchemaTestCase.php b/tests/Export/SchemaTestCase.php new file mode 100644 index 000000000..e172220d3 --- /dev/null +++ b/tests/Export/SchemaTestCase.php @@ -0,0 +1,67 @@ +. + */ + +/** + * Doctrine_Export_Schema_TestCase + * + * @package Doctrine + * @author Konsta Vesterinen + * @license http://www.opensource.org/licenses/lgpl-license.php LGPL + * @category Object Relational Mapping + * @link www.phpdoctrine.com + * @since 1.0 + * @version $Revision$ + */ +class Doctrine_Export_Schema_TestCase extends Doctrine_UnitTestCase +{ + public $tables = array('Entity', + 'EntityReference', + 'EntityAddress', + 'Email', + 'Phonenumber', + 'Groupuser', + 'Group', + 'User', + 'Album', + 'Song', + 'Element', + 'Error', + 'Description', + 'Address', + 'Account', + 'Task', + 'Resource', + 'Assignment', + 'ResourceType', + 'ResourceReference'); + + public function testYmlExport() + { + $export = new Doctrine_Export_Schema(); + $export->exportSchema('schema.yml', 'yml', dirname(dirname(dirname(__FILE__))) . DIRECTORY_SEPARATOR . 'models', $this->tables); + } + + public function testXmlExport() + { + $export = new Doctrine_Export_Schema(); + $export->exportSchema('schema.xml', 'xml', dirname(dirname(dirname(__FILE__))) . DIRECTORY_SEPARATOR . 'models', $this->tables); + } +} diff --git a/tests/Import/Schema/XmlTestCase.php b/tests/Import/Schema/XmlTestCase.php deleted file mode 100644 index 5216df890..000000000 --- a/tests/Import/Schema/XmlTestCase.php +++ /dev/null @@ -1,52 +0,0 @@ -. - */ - -/** - * Doctrine_Import_Schema_Xml_TestCase - * - * @package Doctrine - * @author Konsta Vesterinen - * @license http://www.opensource.org/licenses/lgpl-license.php LGPL - * @category Object Relational Mapping - * @link www.phpdoctrine.com - * @since 1.0 - * @version $Revision$ - */ -class Doctrine_Import_Schema_Xml_TestCase extends Doctrine_UnitTestCase -{ - public function testXmlImport() - { - $import = new Doctrine_Import_Schema_Xml(); - $import->importSchema('schema.xml', 'classes'); - - if ( ! file_exists('classes/User.class.php')) { - $this->fail(); - } else { - unlink('classes/User.class.php'); - } - - if ( ! file_exists('classes/Group.class.php')) { - $this->fail(); - } else { - unlink('classes/Group.class.php'); - } - } -} diff --git a/tests/Import/Schema/YmlTestCase.php b/tests/Import/SchemaTestCase.php similarity index 72% rename from tests/Import/Schema/YmlTestCase.php rename to tests/Import/SchemaTestCase.php index b202c2118..78cf8e74f 100644 --- a/tests/Import/Schema/YmlTestCase.php +++ b/tests/Import/SchemaTestCase.php @@ -20,7 +20,7 @@ */ /** - * Doctrine_Import_Schema_Yml_TestCase + * Doctrine_Import_Schema_TestCase * * @package Doctrine * @author Konsta Vesterinen @@ -30,7 +30,7 @@ * @since 1.0 * @version $Revision$ */ -class Doctrine_Import_Schema_Yml_TestCase extends Doctrine_UnitTestCase +class Doctrine_Import_Schema_TestCase extends Doctrine_UnitTestCase { public function testYmlImport() { @@ -49,4 +49,22 @@ class Doctrine_Import_Schema_Yml_TestCase extends Doctrine_UnitTestCase unlink('classes/Group.class.php'); } } + + public function testXmlImport() + { + $import = new Doctrine_Import_Schema(); + $import->importSchema('schema.xml', 'xml', 'classes'); + + if ( ! file_exists('classes/User.class.php')) { + $this->fail(); + } else { + unlink('classes/User.class.php'); + } + + if ( ! file_exists('classes/Group.class.php')) { + $this->fail(); + } else { + unlink('classes/Group.class.php'); + } + } } diff --git a/tests/run.php b/tests/run.php index 7b1ea34ab..476fcc4b7 100644 --- a/tests/run.php +++ b/tests/run.php @@ -79,9 +79,6 @@ foreach($models as $key => $file) { } } } -//require_once dirname(__FILE__) . '/../models/location.php'; -//require_once dirname(__FILE__) . '/../models/Blog.php'; -//require_once dirname(__FILE__) . '/classes.php'; require_once dirname(__FILE__) . '/Test.php'; require_once dirname(__FILE__) . '/UnitTestCase.php'; @@ -90,7 +87,6 @@ error_reporting(E_ALL | E_STRICT); $test = new GroupTest('Doctrine Framework Unit Tests'); - //TICKET test cases $tickets = new GroupTest('Tickets tests'); $tickets->addTestCase(new Doctrine_Ticket_Njero_TestCase()); @@ -306,11 +302,6 @@ $test->addTestCase(new Doctrine_RawSql_TestCase()); $test->addTestCase(new Doctrine_NewCore_TestCase()); -//$test->addTestCase(new Doctrine_Import_Schema_Xml_TestCase()); -//$test->addTestCase(new Doctrine_Export_Schema_Xml_TestCase()); -$test->addTestCase(new Doctrine_Import_Schema_Yml_TestCase()); -$test->addTestCase(new Doctrine_Export_Schema_Yml_TestCase()); - $test->addTestCase(new Doctrine_Template_TestCase()); //$test->addTestCase(new Doctrine_Import_Builder_TestCase()); @@ -339,6 +330,10 @@ $test->addTestCase(new Doctrine_Query_ApplyInheritance_TestCase()); $test->addTestCase(new Doctrine_Migration_TestCase()); +$test->addTestCase(new Doctrine_Import_Schema_TestCase()); + +$test->addTestCase(new Doctrine_Export_Schema_TestCase()); + class CliReporter extends HtmlReporter{ public function paintHeader(){ echo "Doctrine UnitTests\n"; diff --git a/tests/schema.xml b/tests/schema.xml index f57b66b17..8c1c1cb21 100755 --- a/tests/schema.xml +++ b/tests/schema.xml @@ -1,42 +1,2 @@ - - - - - user - User - - - id - integer - true - true - - - username - string - 20 - true - - - - - - group - Group - - - id - integer - true - true - - - name - string - 20 - true - - - - - \ No newline at end of file + +accountAccountinteger2011idinteger2147483647entity_idinteger2147483647amount
addressAddressinteger2011id
string200address
EntityAddressaddress_iduser_idmanyidaddress_idmany
albumAlbuminteger2011idinteger2147483647user_idstring20nameidalbum_idmanyuser_ididoneassignmentAssignmentinteger2011idinteger2147483647task_idinteger2147483647resource_idresource_ididonetask_ididonedescriptionDescriptioninteger2011idstring3000descriptionstring32file_md5elementElementinteger2011idstring100nameinteger2147483647parent_idElementidparent_idmanyElementparent_ididoneemailEmailinteger2011id
11string150address
entityEntity11integer20idstring50name1string20loginnamestring16passwordinteger1typeinteger11createdinteger11updatedinteger2147483647email_idemail_ididoneidentity_idmanyidentity_idoneEntityReferenceentity1entity2manyidentity1manyentity_addressEntityAddress1integer2147483647user_id1integer2147483647address_id
address_ididone
user_ididone
entity_referenceEntityReference1integer2147483647entity11integer2147483647entity2entity1idoneentity1idoneentity1idoneerrorErrorstring200messageinteger11code1string32file_md5file_md5file_md5oneentityGroup11integer20idstring50name1string20loginnamestring16passwordinteger1typeinteger11createdinteger11updatedinteger2147483647email_idemail_ididoneidentity_idmanyidentity_idoneEntityReferenceentity1entity2manyGroupusergroup_iduser_idmanyidentity1manyidgroup_idmanygroupuserGroupuserinteger2011idinteger2147483647addedinteger2147483647group_idinteger2147483647user_idgroup_ididoneuser_ididonephonenumberPhonenumberinteger2011idstring20phonenumberinteger2147483647entity_identity_ididoneentity_ididoneentity_ididoneresource_referenceResourceReferenceinteger2011idinteger2147483647type_idinteger2147483647resource_idresource_ididoneresourcetype_ididoneresourceResourceinteger2011idstring100nameAssignmentTaskresource_idtask_idmanyResourceReferenceResourceTyperesource_idtype_idmanyidresource_idmanyidresource_idmanyresource_typeResourceTypeinteger2011idstring100typeResourceReferenceResourceresourcetype_idresource_idmanyidresourcetype_idmanysongSonginteger2011idinteger2147483647album_idstring20genre<type>string</type><length>30</length><name>title</name>album_ididonetaskTaskinteger2011idstring100nameinteger2147483647parent_idAssignmentResourcetask_idresource_idmanyTaskidparent_idmanyidtask_idmanyentityUser11integer20idstring50name1string20loginnamestring16passwordinteger1typeinteger11createdinteger11updatedinteger2147483647email_idemail_ididoneidentity_idmanyidentity_idoneEntityReferenceentity1entity2many
EntityAddressuser_idaddress_idmany
iduser_idmanyiduser_idmanyGroupuseruser_idgroup_idmanyidentity1manyiduser_idmanyiduser_idmany
diff --git a/tests/schema.yml b/tests/schema.yml index 2a0654a81..0900824a0 100644 --- a/tests/schema.yml +++ b/tests/schema.yml @@ -1,58 +1,630 @@ --- -User: - tableName: user - className: User - columns: - id: +Account: + tableName: account + className: Account + columns: + id: type: integer + length: 20 autoincrement: true - username: + primary: true + name: id + entity_id: + type: integer + length: 2147483647 + name: entity_id + amount: + type: integer + length: 2147483647 + name: amount +Address: + tableName: address + className: Address + columns: + id: + type: integer + length: 20 + autoincrement: true + primary: true + name: id + address: type: string + length: 200 + name: address + relations: + User: + refClass: EntityAddress + local: address_id + foreign: user_id + type: many + EntityAddress: + local: id + foreign: address_id + type: many +Album: + tableName: album + className: Album + columns: + id: + type: integer + length: 20 + autoincrement: true + primary: true + name: id + user_id: + type: integer + length: 2147483647 + name: user_id + name: + type: string + length: 20 + name: name + relations: + Song: + local: id + foreign: album_id + type: many + User: + local: user_id + foreign: id + type: one +Assignment: + tableName: assignment + className: Assignment + columns: + id: + type: integer + length: 20 + autoincrement: true + primary: true + name: id + task_id: + type: integer + length: 2147483647 + name: task_id + resource_id: + type: integer + length: 2147483647 + name: resource_id +Description: + tableName: description + className: Description + columns: + id: + type: integer + length: 20 + autoincrement: true + primary: true + name: id + description: + type: string + length: 3000 + name: description + file_md5: + type: string + length: 32 + name: file_md5 +Element: + tableName: element + className: Element + columns: + id: + type: integer + length: 20 + autoincrement: true + primary: true + name: id + name: + type: string + length: 100 + name: name + parent_id: + type: integer + length: 2147483647 + name: parent_id + relations: + Child: + class: Element + local: id + foreign: parent_id + type: many + Parent: + class: Element + local: parent_id + foreign: id + type: one +Email: + tableName: email + className: Email + columns: + id: + type: integer + length: 20 + autoincrement: true + primary: true + name: id + address: + email: true + unique: true + type: string + length: 150 + name: address +Entity: + tableName: entity + className: Entity + columns: + id: + autoincrement: true + primary: true + type: integer + length: 20 + name: id + name: + type: string + length: 50 + name: name + loginname: + unique: true + type: string + length: 20 + name: loginname + password: + type: string + length: 16 + name: password + type: + type: integer + length: 1 + name: type + created: + type: integer length: 11 - relations: - Groups: - class: Group - refClass: UserGroup + name: created + updated: + type: integer + length: 11 + name: updated + email_id: + type: integer + length: 2147483647 + name: email_id + relations: + Email: + local: email_id + foreign: id + type: one + Phonenumber: + local: id + foreign: entity_id + type: many + Account: + local: id + foreign: entity_id + type: one + Entity: + refClass: EntityReference + local: entity1 + foreign: entity2 + type: many + EntityReference: + local: id + foreign: entity1 + type: many +EntityAddress: + tableName: entity_address + className: EntityAddress + columns: + user_id: + primary: true + type: integer + length: 2147483647 + name: user_id + address_id: + primary: true + type: integer + length: 2147483647 + name: address_id + relations: + Address: + local: address_id + foreign: id + type: one +EntityReference: + tableName: entity_reference + className: EntityReference + columns: + entity1: + primary: true + type: integer + length: 2147483647 + name: entity1 + entity2: + primary: true + type: integer + length: 2147483647 + name: entity2 + relations: + Entity: + local: entity1 + foreign: id + type: one +Error: + tableName: error + className: Error + columns: + message: + type: string + length: 200 + name: message + code: + type: integer + length: 11 + name: code + file_md5: + primary: true + type: string + length: 32 + name: file_md5 + relations: + Description: + local: file_md5 + foreign: file_md5 + type: one +Group: + tableName: entity + className: Group + columns: + id: + autoincrement: true + primary: true + type: integer + length: 20 + name: id + name: + type: string + length: 50 + name: name + loginname: + unique: true + type: string + length: 20 + name: loginname + password: + type: string + length: 16 + name: password + type: + type: integer + length: 1 + name: type + created: + type: integer + length: 11 + name: created + updated: + type: integer + length: 11 + name: updated + email_id: + type: integer + length: 2147483647 + name: email_id + relations: + Email: + local: email_id + foreign: id + type: one + Phonenumber: + local: id + foreign: entity_id + type: many + Account: + local: id + foreign: entity_id + type: one + Entity: + refClass: EntityReference + local: entity1 + foreign: entity2 + type: many + User: + refClass: Groupuser + local: group_id + foreign: user_id + type: many + EntityReference: + local: id + foreign: entity1 + type: many + Groupuser: + local: id + foreign: group_id + type: many +Groupuser: + tableName: groupuser + className: Groupuser + columns: + id: + type: integer + length: 20 + autoincrement: true + primary: true + name: id + added: + type: integer + length: 2147483647 + name: added + group_id: + type: integer + length: 2147483647 + name: group_id + user_id: + type: integer + length: 2147483647 + name: user_id + relations: + Group: + local: group_id + foreign: id + type: one + User: + local: user_id + foreign: id + type: one +Phonenumber: + tableName: phonenumber + className: Phonenumber + columns: + id: + type: integer + length: 20 + autoincrement: true + primary: true + name: id + phonenumber: + type: string + length: 20 + name: phonenumber + entity_id: + type: integer + length: 2147483647 + name: entity_id + relations: + Entity: + local: entity_id + foreign: id + type: one + Group: + local: entity_id + foreign: id + type: one + User: + local: entity_id + foreign: id + type: one +ResourceReference: + tableName: resource_reference + className: ResourceReference + columns: + id: + type: integer + length: 20 + autoincrement: true + primary: true + name: id + type_id: + type: integer + length: 2147483647 + name: type_id + resource_id: + type: integer + length: 2147483647 + name: resource_id +Resource: + tableName: resource + className: Resource + columns: + id: + type: integer + length: 20 + autoincrement: true + primary: true + name: id + name: + type: string + length: 100 + name: name + relations: + TaskAlias: + refClass: Assignment + class: Task + local: resource_id + foreign: task_id + type: many + Type: + refClass: ResourceReference + class: ResourceType + local: resource_id + foreign: type_id + type: many + Assignment: + local: id + foreign: resource_id + type: many + ResourceReference: + local: id + foreign: resource_id + type: many +ResourceType: + tableName: resource_type + className: ResourceType + columns: + id: + type: integer + length: 20 + autoincrement: true + primary: true + name: id + type: + type: string + length: 100 + name: type + relations: + ResourceAlias: + refClass: ResourceReference + class: Resource + local: resourcetype_id + foreign: resource_id + type: many + ResourceReference: + local: id + foreign: resourcetype_id + type: many +Song: + tableName: song + className: Song + columns: + id: + type: integer + length: 20 + autoincrement: true + primary: true + name: id + album_id: + type: integer + length: 2147483647 + name: album_id + genre: + type: string + length: 20 + name: genre + title: + type: string + length: 30 + name: title + relations: + Album: + local: album_id + foreign: id + type: one +Task: + tableName: task + className: Task + columns: + id: + type: integer + length: 20 + autoincrement: true + primary: true + name: id + name: + type: string + length: 100 + name: name + parent_id: + type: integer + length: 2147483647 + name: parent_id + relations: + ResourceAlias: + refClass: Assignment + class: Resource + local: task_id + foreign: resource_id + type: many + Subtask: + class: Task + local: id + foreign: parent_id + type: many + Assignment: + local: id + foreign: task_id + type: many +User: + tableName: entity + className: User + columns: + id: + autoincrement: true + primary: true + type: integer + length: 20 + name: id + name: + type: string + length: 50 + name: name + loginname: + unique: true + type: string + length: 20 + name: loginname + password: + type: string + length: 16 + name: password + type: + type: integer + length: 1 + name: type + created: + type: integer + length: 11 + name: created + updated: + type: integer + length: 11 + name: updated + email_id: + type: integer + length: 2147483647 + name: email_id + relations: + Email: + local: email_id + foreign: id + type: one + Phonenumber: + local: id + foreign: entity_id + type: many + Account: + local: id + foreign: entity_id + type: one + Entity: + refClass: EntityReference + local: entity1 + foreign: entity2 + type: many + Address: + refClass: EntityAddress + local: user_id + foreign: address_id + type: many + Album: + local: id + foreign: user_id + type: many + Book: + local: id + foreign: user_id + type: many + Group: + refClass: Groupuser local: user_id foreign: group_id type: many - -UserGroup: - tableName: user_group - className: UserGroup - columns: - user_id: - type: int - length: 11 - primary: true - group_id: - type: int - length: 11 - primary: true - relations: - User: - foreign: id - local: user_id - type: one - Group: - foreign: id - local: group_id - type: one - -Group: - tableName: group - className: Group - columns: - id: - type: integer - autoincrement: true - name: - type: string - length: 255 - relations: - Users: - class: User - refClass: UserGroup - local: group_id + EntityReference: + local: id + foreign: entity1 + type: many + EntityAddress: + local: id foreign: user_id - type: many \ No newline at end of file + type: many + Groupuser: + local: id + foreign: user_id + type: many