Commit 34f4ee71 authored by romanb's avatar romanb

First tests for basic collection implementation. First experimental use of...

First tests for basic collection implementation. First experimental use of closures (Currently commented out, because the svn server makes a syntax check against 5.2.x).
parent 73ad0ac4
...@@ -30,7 +30,7 @@ interface Doctrine_DBAL_Driver ...@@ -30,7 +30,7 @@ interface Doctrine_DBAL_Driver
* Gets the SchemaManager that can be used to inspect and change the underlying * Gets the SchemaManager that can be used to inspect and change the underlying
* database schema of the platform this driver connects to. * database schema of the platform this driver connects to.
* *
* @return Doctrine::DBAL::SchemaManager * @return Doctrine\DBAL\SchemaManager
*/ */
public function getSchemaManager(Doctrine_DBAL_Connection $conn); public function getSchemaManager(Doctrine_DBAL_Connection $conn);
} }
......
...@@ -44,12 +44,12 @@ class Doctrine_DBAL_Driver_PDOMySql_Driver implements Doctrine_DBAL_Driver ...@@ -44,12 +44,12 @@ class Doctrine_DBAL_Driver_PDOMySql_Driver implements Doctrine_DBAL_Driver
public function getDatabasePlatform() public function getDatabasePlatform()
{ {
return new Doctrine_DatabasePlatform_MySqlPlatform(); return new Doctrine_DBAL_Platforms_MySqlPlatform();
} }
public function getSchemaManager(Doctrine_Connection $conn) public function getSchemaManager(Doctrine_DBAL_Connection $conn)
{ {
return new Doctrine_Schema_MySqlSchemaManager($conn); return new Doctrine_DBAL_Schema_MySqlSchemaManager($conn);
} }
} }
......
...@@ -31,12 +31,12 @@ class Doctrine_DBAL_Driver_PDOPgSql_Driver implements Doctrine_DBAL_Driver ...@@ -31,12 +31,12 @@ class Doctrine_DBAL_Driver_PDOPgSql_Driver implements Doctrine_DBAL_Driver
public function getDatabasePlatform() public function getDatabasePlatform()
{ {
return new Doctrine_DatabasePlatform_PostgreSqlPlatform(); return new Doctrine_DBAL_Platforms_PostgreSqlPlatform();
} }
public function getSchemaManager(Doctrine_Connection $conn) public function getSchemaManager(Doctrine_DBAL_Connection $conn)
{ {
return new Doctrine_Schema_PostgreSqlSchemaManager($conn); return new Doctrine_DBAL_Schema_PostgreSqlSchemaManager($conn);
} }
} }
......
...@@ -724,7 +724,7 @@ class Doctrine_DBAL_Platforms_MySqlPlatform extends Doctrine_DBAL_Platforms_Abst ...@@ -724,7 +724,7 @@ class Doctrine_DBAL_Platforms_MySqlPlatform extends Doctrine_DBAL_Platforms_Abst
// attach all primary keys // attach all primary keys
if (isset($options['primary']) && ! empty($options['primary'])) { if (isset($options['primary']) && ! empty($options['primary'])) {
$keyColumns = array_values($options['primary']); $keyColumns = array_values($options['primary']);
$keyColumns = array_map(array($this->_conn, 'quoteIdentifier'), $keyColumns); $keyColumns = array_map(array($this, 'quoteIdentifier'), $keyColumns);
$queryFields .= ', PRIMARY KEY(' . implode(', ', $keyColumns) . ')'; $queryFields .= ', PRIMARY KEY(' . implode(', ', $keyColumns) . ')';
} }
...@@ -751,9 +751,9 @@ class Doctrine_DBAL_Platforms_MySqlPlatform extends Doctrine_DBAL_Platforms_Abst ...@@ -751,9 +751,9 @@ class Doctrine_DBAL_Platforms_MySqlPlatform extends Doctrine_DBAL_Platforms_Abst
// get the type of the table // get the type of the table
if (isset($options['type'])) { if (isset($options['type'])) {
$type = $options['type']; $type = $options['type'];
} else { }/* else {
$type = $this->getAttribute(Doctrine::ATTR_DEFAULT_TABLE_TYPE); $type = $this->getAttribute(Doctrine::ATTR_DEFAULT_TABLE_TYPE);
} }*/
if ($type) { if ($type) {
$optionStrings[] = 'ENGINE = ' . $type; $optionStrings[] = 'ENGINE = ' . $type;
...@@ -1057,13 +1057,13 @@ class Doctrine_DBAL_Platforms_MySqlPlatform extends Doctrine_DBAL_Platforms_Abst ...@@ -1057,13 +1057,13 @@ class Doctrine_DBAL_Platforms_MySqlPlatform extends Doctrine_DBAL_Platforms_Abst
} }
/** @override */ /** @override */
public function getSmallIntDeclarationSql(array $field) public function getSmallIntTypeDeclarationSql(array $field)
{ {
return 'SMALLINT ' . $this->_getCommonIntegerTypeDeclarationSql($field); return 'SMALLINT ' . $this->_getCommonIntegerTypeDeclarationSql($field);
} }
/** @override */ /** @override */
public function getMediumIntDeclarationSql(array $field) public function getMediumIntTypeDeclarationSql(array $field)
{ {
return 'MEDIUMINT ' . $this->_getCommonIntegerTypeDeclarationSql($field); return 'MEDIUMINT ' . $this->_getCommonIntegerTypeDeclarationSql($field);
} }
...@@ -1072,23 +1072,23 @@ class Doctrine_DBAL_Platforms_MySqlPlatform extends Doctrine_DBAL_Platforms_Abst ...@@ -1072,23 +1072,23 @@ class Doctrine_DBAL_Platforms_MySqlPlatform extends Doctrine_DBAL_Platforms_Abst
protected function _getCommonIntegerTypeDeclarationSql(array $columnDef) protected function _getCommonIntegerTypeDeclarationSql(array $columnDef)
{ {
$default = $autoinc = ''; $default = $autoinc = '';
if ( ! empty($field['autoincrement'])) { if ( ! empty($columnDef['autoincrement'])) {
$autoinc = ' AUTO_INCREMENT'; $autoinc = ' AUTO_INCREMENT';
} elseif (array_key_exists('default', $field)) { } elseif (array_key_exists('default', $columnDef)) {
if ($field['default'] === '') { if ($columnDef['default'] === '') {
$field['default'] = empty($field['notnull']) ? null : 0; $columnDef['default'] = empty($columnDef['notnull']) ? null : 0;
} }
if (is_null($field['default'])) { if (is_null($columnDef['default'])) {
$default = ' DEFAULT NULL'; $default = ' DEFAULT NULL';
} else { } else {
$default = ' DEFAULT '.$this->quote($field['default']); $default = ' DEFAULT '.$this->quote($columnDef['default']);
} }
} elseif (empty($field['notnull'])) { } elseif (empty($columnDef['notnull'])) {
$default = ' DEFAULT NULL'; $default = ' DEFAULT NULL';
} }
$notnull = (isset($field['notnull']) && $field['notnull']) ? ' NOT NULL' : ''; $notnull = (isset($columnDef['notnull']) && $columnDef['notnull']) ? ' NOT NULL' : '';
$unsigned = (isset($field['unsigned']) && $field['unsigned']) ? ' UNSIGNED' : ''; $unsigned = (isset($columnDef['unsigned']) && $columnDef['unsigned']) ? ' UNSIGNED' : '';
return $unsigned . $default . $notnull . $autoinc; return $unsigned . $default . $notnull . $autoinc;
} }
......
...@@ -172,7 +172,6 @@ abstract class Doctrine_DBAL_Schema_AbstractSchemaManager ...@@ -172,7 +172,6 @@ abstract class Doctrine_DBAL_Schema_AbstractSchemaManager
} }
/** /**
* dropTable
* drop an existing table * drop an existing table
* *
* @param string $table name of table that should be dropped from the database * @param string $table name of table that should be dropped from the database
......
...@@ -65,7 +65,7 @@ class Doctrine_ORM_Internal_Hydration_ObjectDriver ...@@ -65,7 +65,7 @@ class Doctrine_ORM_Internal_Hydration_ObjectDriver
// check needed because of mixed results. // check needed because of mixed results.
// is_object instead of is_array because is_array is slow on large arrays. // is_object instead of is_array because is_array is slow on large arrays.
if (is_object($coll)) { if (is_object($coll)) {
$coll->end(); $coll->last();
return $coll->key(); return $coll->key();
} else { } else {
end($coll); end($coll);
...@@ -121,7 +121,7 @@ class Doctrine_ORM_Internal_Hydration_ObjectDriver ...@@ -121,7 +121,7 @@ class Doctrine_ORM_Internal_Hydration_ObjectDriver
$classMetadata1 = $this->_metadataMap[spl_object_hash($entity1)]; $classMetadata1 = $this->_metadataMap[spl_object_hash($entity1)];
$classMetadata2 = $this->_metadataMap[spl_object_hash($entity2)]; $classMetadata2 = $this->_metadataMap[spl_object_hash($entity2)];
$indexValue = $classMetadata2->getReflectionProperty($indexField)->getValue($entity2); $indexValue = $classMetadata2->getReflectionProperty($indexField)->getValue($entity2);
$classMetadata1->getReflectionProperty($property)->getValue($entity1)->add($entity2, $indexValue); $classMetadata1->getReflectionProperty($property)->getValue($entity1)->set($indexValue, $entity2);
} }
/** /**
...@@ -196,7 +196,7 @@ class Doctrine_ORM_Internal_Hydration_ObjectDriver ...@@ -196,7 +196,7 @@ class Doctrine_ORM_Internal_Hydration_ObjectDriver
public function addElementToIndexedCollection($coll, $entity, $keyField) public function addElementToIndexedCollection($coll, $entity, $keyField)
{ {
$coll->add($entity, $this->getFieldValue($entity, $keyField)); $coll->set($entity, $this->getFieldValue($keyField, $entity));
} }
public function addElementToCollection($coll, $entity) public function addElementToCollection($coll, $entity)
...@@ -216,7 +216,7 @@ class Doctrine_ORM_Internal_Hydration_ObjectDriver ...@@ -216,7 +216,7 @@ class Doctrine_ORM_Internal_Hydration_ObjectDriver
*/ */
public function updateResultPointer(&$resultPointers, &$coll, $index, $dqlAlias, $oneToOne) public function updateResultPointer(&$resultPointers, &$coll, $index, $dqlAlias, $oneToOne)
{ {
if ($coll === /*$this->_nullObject*/null) { if ($coll === null) {
echo "HERE!"; echo "HERE!";
unset($resultPointers[$dqlAlias]); // Ticket #1228 unset($resultPointers[$dqlAlias]); // Ticket #1228
return; return;
...@@ -232,7 +232,7 @@ class Doctrine_ORM_Internal_Hydration_ObjectDriver ...@@ -232,7 +232,7 @@ class Doctrine_ORM_Internal_Hydration_ObjectDriver
$resultPointers[$dqlAlias] =& $coll[key($coll)]; $resultPointers[$dqlAlias] =& $coll[key($coll)];
} else if ($coll instanceof Doctrine_ORM_Collection) { } else if ($coll instanceof Doctrine_ORM_Collection) {
if (count($coll) > 0) { if (count($coll) > 0) {
$resultPointers[$dqlAlias] = $coll->getLast(); $resultPointers[$dqlAlias] = $coll->last();
} }
} else { } else {
$resultPointers[$dqlAlias] = $coll; $resultPointers[$dqlAlias] = $coll;
......
...@@ -105,19 +105,18 @@ class Doctrine_ORM_Internal_Hydration_StandardHydrator extends Doctrine_ORM_Inte ...@@ -105,19 +105,18 @@ class Doctrine_ORM_Internal_Hydration_StandardHydrator extends Doctrine_ORM_Inte
$rootEntityName = $this->_queryComponents[$rootAlias]['metadata']->getClassName(); $rootEntityName = $this->_queryComponents[$rootAlias]['metadata']->getClassName();
// if only one class is involved we can make our lives easier // if only one class is involved we can make our lives easier
$isSimpleQuery = count($this->_queryComponents) <= 1; $isSimpleQuery = count($this->_queryComponents) <= 1;
// Lookup map to quickly discover/lookup existing records in the result // Lookup map to quickly discover/lookup existing entities in the result
// It's the identifier "memory" // It's the identifier "memory"
$identifierMap = array(); $identifierMap = array();
// Holds for each class a pointer to the last previously seen element in the result set // Holds for each class a pointer to the last previously seen element in the result set
$resultPointers = array(); $resultPointers = array();
// holds the values of the identifier/primary key fields of components, // Holds the values of the identifier/primary key fields of entities,
// separated by a pipe '|' and grouped by component alias (r, u, i, ... whatever) // separated by a pipe '|' and grouped by DQL class alias (r, u, i, ... whatever)
// the $idTemplate is a prepared template. $id is set to a fresh template when // The $idTemplate is a prepared template. $id is set to a fresh template when
// starting to process a row. // starting to process a row.
$id = array(); $id = array();
$idTemplate = array(); $idTemplate = array();
// Holds the resulting hydrated data structure
if ($parserResult->isMixedQuery() || $hydrationMode == Doctrine_ORM_Query::HYDRATE_SCALAR) { if ($parserResult->isMixedQuery() || $hydrationMode == Doctrine_ORM_Query::HYDRATE_SCALAR) {
$result = array(); $result = array();
} else { } else {
......
...@@ -343,11 +343,6 @@ class Doctrine_ORM_Mapping_ClassMetadata ...@@ -343,11 +343,6 @@ class Doctrine_ORM_Mapping_ClassMetadata
$this->_tableName = $this->_entityName; $this->_tableName = $this->_entityName;
$this->_rootEntityName = $entityName; $this->_rootEntityName = $entityName;
$this->_reflectionClass = new ReflectionClass($entityName); $this->_reflectionClass = new ReflectionClass($entityName);
$reflectionProps = $this->_reflectionClass->getProperties();
foreach ($reflectionProps as $prop) {
$prop->setAccessible(true);
$this->_reflectionProperties[$prop->getName()] = $prop;
}
} }
/** /**
...@@ -652,6 +647,11 @@ class Doctrine_ORM_Mapping_ClassMetadata ...@@ -652,6 +647,11 @@ class Doctrine_ORM_Mapping_ClassMetadata
$this->_isIdentifierComposite = true; $this->_isIdentifierComposite = true;
} }
} }
// Store ReflectionProperty of mapped field
$refProp = $this->_reflectionClass->getProperty($mapping['fieldName']);
$refProp->setAccessible(true);
$this->_reflectionProperties[$mapping['fieldName']] = $refProp;
} }
private function _validateAndCompleteClassMapping(array &$mapping) private function _validateAndCompleteClassMapping(array &$mapping)
...@@ -1270,6 +1270,11 @@ class Doctrine_ORM_Mapping_ClassMetadata ...@@ -1270,6 +1270,11 @@ class Doctrine_ORM_Mapping_ClassMetadata
} }
$this->_associationMappings[$sourceFieldName] = $assocMapping; $this->_associationMappings[$sourceFieldName] = $assocMapping;
$this->_registerMappingIfInverse($assocMapping); $this->_registerMappingIfInverse($assocMapping);
// Store ReflectionProperty of mapped field
$refProp = $this->_reflectionClass->getProperty($sourceFieldName);
$refProp->setAccessible(true);
$this->_reflectionProperties[$sourceFieldName] = $refProp;
} }
/** /**
......
...@@ -50,9 +50,6 @@ class Doctrine_ORM_Mapping_Driver_AnnotationDriver { ...@@ -50,9 +50,6 @@ class Doctrine_ORM_Mapping_Driver_AnnotationDriver {
} }
foreach ($annotClass->getProperties() as $property) { foreach ($annotClass->getProperties() as $property) {
if ($property->hasAnnotation('DoctrineTransient')) {
continue;
}
$mapping = array(); $mapping = array();
$mapping['fieldName'] = $property->getName(); $mapping['fieldName'] = $property->getName();
if ($columnAnnot = $property->getAnnotation('DoctrineColumn')) { if ($columnAnnot = $property->getAnnotation('DoctrineColumn')) {
...@@ -90,8 +87,6 @@ class Doctrine_ORM_Mapping_Driver_AnnotationDriver { ...@@ -90,8 +87,6 @@ class Doctrine_ORM_Mapping_Driver_AnnotationDriver {
$mapping['joinTable'] = $manyToManyAnnot->joinTable; $mapping['joinTable'] = $manyToManyAnnot->joinTable;
$mapping['mappedBy'] = $manyToManyAnnot->mappedBy; $mapping['mappedBy'] = $manyToManyAnnot->mappedBy;
$metadata->mapManyToMany($mapping); $metadata->mapManyToMany($mapping);
} else {
throw new Doctrine_ORM_Exceptions_MappingException($className);
} }
} }
} }
...@@ -112,9 +107,16 @@ final class DoctrineDiscriminatorColumn extends Annotation { ...@@ -112,9 +107,16 @@ final class DoctrineDiscriminatorColumn extends Annotation {
} }
final class DoctrineDiscriminatorMap extends Annotation {} final class DoctrineDiscriminatorMap extends Annotation {}
final class DoctrineSubClasses extends Annotation {} final class DoctrineSubClasses extends Annotation {}
final class DoctrineTransient extends Annotation {}
final class DoctrineId extends Annotation {} final class DoctrineId extends Annotation {}
final class DoctrineIdGenerator extends Annotation {} final class DoctrineIdGenerator extends Annotation {}
final class DoctrineVersion extends Annotation {}
final class DoctrineJoinColumn extends Annotation {
public $name;
public $type;
public $length;
public $onDelete;
public $onUpdate;
}
final class DoctrineColumn extends Annotation { final class DoctrineColumn extends Annotation {
public $type; public $type;
public $length; public $length;
......
...@@ -101,7 +101,6 @@ abstract class Doctrine_ORM_Persisters_AbstractEntityPersister ...@@ -101,7 +101,6 @@ abstract class Doctrine_ORM_Persisters_AbstractEntityPersister
* Updates an entity. * Updates an entity.
* *
* @param object $entity The entity to update. * @param object $entity The entity to update.
* @return void
*/ */
public function update($entity) public function update($entity)
{ {
...@@ -110,30 +109,12 @@ abstract class Doctrine_ORM_Persisters_AbstractEntityPersister ...@@ -110,30 +109,12 @@ abstract class Doctrine_ORM_Persisters_AbstractEntityPersister
$id = array_combine($this->_classMetadata->getIdentifierFieldNames(), $id = array_combine($this->_classMetadata->getIdentifierFieldNames(),
$this->_em->getUnitOfWork()->getEntityIdentifier($entity)); $this->_em->getUnitOfWork()->getEntityIdentifier($entity));
$this->_conn->update($this->_classMetadata->getTableName(), $updateData, $id); $this->_conn->update($this->_classMetadata->getTableName(), $updateData, $id);
/*$dataChangeSet = $entity->_getDataChangeSet();
$referenceChangeSet = $entity->_getReferenceChangeSet();
foreach ($referenceChangeSet as $field => $change) {
$assocMapping = $entity->getClass()->getAssociationMapping($field);
if ($assocMapping instanceof Doctrine_Association_OneToOneMapping) {
if ($assocMapping->isInverseSide()) {
continue; // ignore inverse side
}
// ... null out the foreign key
}
//...
}
*/
//TODO: perform update
} }
/** /**
* Deletes an entity. * Deletes an entity.
* *
* @param object $entity The entity to delete. * @param object $entity The entity to delete.
* @return void
*/ */
public function delete($entity) public function delete($entity)
{ {
...@@ -143,38 +124,9 @@ abstract class Doctrine_ORM_Persisters_AbstractEntityPersister ...@@ -143,38 +124,9 @@ abstract class Doctrine_ORM_Persisters_AbstractEntityPersister
} }
/** /**
* Inserts a row into a table.
* *
* @todo This method could be used to allow mapping to secondary table(s). * @return <type>
* @see http://www.oracle.com/technology/products/ias/toplink/jpa/resources/toplink-jpa-annotations.html#SecondaryTable
*/ */
protected function _insertRow($tableName, array $data)
{
$this->_conn->insert($tableName, $data);
}
/**
* Deletes rows of a table.
*
* @todo This method could be used to allow mapping to secondary table(s).
* @see http://www.oracle.com/technology/products/ias/toplink/jpa/resources/toplink-jpa-annotations.html#SecondaryTable
*/
protected function _deleteRow($tableName, array $identifierToMatch)
{
$this->_conn->delete($tableName, $identifierToMatch);
}
/**
* Deletes rows of a table.
*
* @todo This method could be used to allow mapping to secondary table(s).
* @see http://www.oracle.com/technology/products/ias/toplink/jpa/resources/toplink-jpa-annotations.html#SecondaryTable
*/
protected function _updateRow($tableName, array $data, array $identifierToMatch)
{
$this->_conn->update($tableName, $data, $identifierToMatch);
}
public function getClassMetadata() public function getClassMetadata()
{ {
return $this->_classMetadata; return $this->_classMetadata;
...@@ -258,7 +210,6 @@ abstract class Doctrine_ORM_Persisters_AbstractEntityPersister ...@@ -258,7 +210,6 @@ abstract class Doctrine_ORM_Persisters_AbstractEntityPersister
//echo "NOT TO-ONE OR INVERSE!"; //echo "NOT TO-ONE OR INVERSE!";
continue; continue;
} }
//echo "HERE!!!";
foreach ($assocMapping->getSourceToTargetKeyColumns() as $sourceColumn => $targetColumn) { foreach ($assocMapping->getSourceToTargetKeyColumns() as $sourceColumn => $targetColumn) {
//TODO: throw exc if field not set //TODO: throw exc if field not set
$otherClass = $this->_em->getClassMetadata($assocMapping->getTargetEntityName()); $otherClass = $this->_em->getClassMetadata($assocMapping->getTargetEntityName());
...@@ -283,7 +234,4 @@ abstract class Doctrine_ORM_Persisters_AbstractEntityPersister ...@@ -283,7 +234,4 @@ abstract class Doctrine_ORM_Persisters_AbstractEntityPersister
$result[$discColumn['name']] = array_search($this->_entityName, $discMap); $result[$discColumn['name']] = array_search($this->_entityName, $discMap);
} }
} }
abstract protected function _doUpdate(Doctrine_ORM_Entity $entity);
abstract protected function _doInsert(Doctrine_ORM_Entity $entity);
} }
...@@ -226,12 +226,12 @@ class Doctrine_ORM_Query extends Doctrine_ORM_Query_Abstract ...@@ -226,12 +226,12 @@ class Doctrine_ORM_Query extends Doctrine_ORM_Query_Abstract
} }
/** /**
* Executes the query and populates the data set. * Executes the query.
* *
* @param string $params Parameters to be sent to query. * @param string $params Parameters to be sent to query.
* @param integer $hydrationMode Doctrine processing mode to be used during hydration process. * @param integer $hydrationMode Doctrine processing mode to be used during hydration process.
* One of the Doctrine::HYDRATE_* constants. * One of the Doctrine::HYDRATE_* constants.
* @return Doctrine_Collection The root collection * @return mixed
*/ */
public function execute($params = array(), $hydrationMode = null) public function execute($params = array(), $hydrationMode = null)
{ {
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
/** /**
* This class is just an intermediate implementation for refactoring purposes * This class is just an intermediate implementation for refactoring purposes
* and will be replaced by the ParserResult class of the new DQL parser branch. * and will be replaced by the ParserResult class of the new DQL parser.
* *
*/ */
class Doctrine_ORM_Query_ParserResultDummy class Doctrine_ORM_Query_ParserResultDummy
......
...@@ -57,13 +57,13 @@ abstract class Doctrine_ORM_Query_SqlExecutor_Abstract implements Serializable ...@@ -57,13 +57,13 @@ abstract class Doctrine_ORM_Query_SqlExecutor_Abstract implements Serializable
* @param Doctrine_Connection $conn The database connection that is used to execute the queries. * @param Doctrine_Connection $conn The database connection that is used to execute the queries.
* @param array $params The parameters. * @param array $params The parameters.
*/ */
abstract public function execute(Doctrine_Connection $conn, array $params); abstract public function execute(Doctrine_DBAL_Connection $conn, array $params);
/** /**
* Factory method. * Factory method.
* Creates an appropriate sql executor for the given AST. * Creates an appropriate sql executor for the given AST.
* *
* @param Doctrine_ORM_Query_Production $AST The root node of the AST. * @param Doctrine_ORM_Query_AST $AST The root node of the AST.
* @return Doctrine_ORM_Query_SqlExecutor_Abstract The executor that is suitable for the given AST. * @return Doctrine_ORM_Query_SqlExecutor_Abstract The executor that is suitable for the given AST.
*/ */
public static function create(Doctrine_ORM_Query_AST $AST) public static function create(Doctrine_ORM_Query_AST $AST)
......
...@@ -25,7 +25,7 @@ ...@@ -25,7 +25,7 @@
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL * @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @author Roman Borschel <roman@code-factory.org> * @author Roman Borschel <roman@code-factory.org>
* @version $Revision$ * @version $Revision$
* @link www.phpdoctrine.org * @link www.doctrine-project.org
* @since 2.0 * @since 2.0
*/ */
class Doctrine_ORM_Query_SqlExecutor_SingleSelect extends Doctrine_ORM_Query_SqlExecutor_Abstract class Doctrine_ORM_Query_SqlExecutor_SingleSelect extends Doctrine_ORM_Query_SqlExecutor_Abstract
...@@ -36,7 +36,7 @@ class Doctrine_ORM_Query_SqlExecutor_SingleSelect extends Doctrine_ORM_Query_Sql ...@@ -36,7 +36,7 @@ class Doctrine_ORM_Query_SqlExecutor_SingleSelect extends Doctrine_ORM_Query_Sql
$this->_sqlStatements = $AST->buildSql(); $this->_sqlStatements = $AST->buildSql();
} }
public function execute(Doctrine_Connection $conn, array $params) public function execute(Doctrine_DBAL_Connection $conn, array $params)
{ {
return $conn->execute($this->_sqlStatements, $params); return $conn->execute($this->_sqlStatements, $params);
} }
......
...@@ -453,16 +453,11 @@ class Doctrine_ORM_UnitOfWork ...@@ -453,16 +453,11 @@ class Doctrine_ORM_UnitOfWork
*/ */
private function _getCommitOrder(array $entityChangeSet = null) private function _getCommitOrder(array $entityChangeSet = null)
{ {
//TODO: Once these 3 arrays are indexed by classname we can do this:
// Either way... do we need to care about duplicates?
/*$classesInChangeSet = array_merge(
array_keys($this->_newEntities),
array_keys($this->_dirtyEntities),
array_keys($this->_deletedEntities)
);*/
if (is_null($entityChangeSet)) { if (is_null($entityChangeSet)) {
$entityChangeSet = array_merge($this->_newEntities, $this->_dirtyEntities, $this->_deletedEntities); $entityChangeSet = array_merge(
$this->_newEntities,
$this->_dirtyEntities,
$this->_deletedEntities);
} }
/* if (count($entityChangeSet) == 1) { /* if (count($entityChangeSet) == 1) {
...@@ -470,6 +465,9 @@ class Doctrine_ORM_UnitOfWork ...@@ -470,6 +465,9 @@ class Doctrine_ORM_UnitOfWork
* } * }
*/ */
// TODO: We can cache computed commit orders in the metadata cache!
// Check cache at this point here!
// See if there are any new classes in the changeset, that are not in the // See if there are any new classes in the changeset, that are not in the
// commit order graph yet (dont have a node). // commit order graph yet (dont have a node).
$newNodes = array(); $newNodes = array();
...@@ -1242,6 +1240,17 @@ class Doctrine_ORM_UnitOfWork ...@@ -1242,6 +1240,17 @@ class Doctrine_ORM_UnitOfWork
} }
return false; return false;
} }
/**
* Calculates the size of the UnitOfWork. The size of the UnitOfWork is the
* number of entities in the identity map.
*/
public function size()
{
$count = 0;
foreach ($this->_identityMap as $entitySet) $count += count($entitySet);
return $count;
}
} }
......
...@@ -7,6 +7,7 @@ if (!defined('PHPUnit_MAIN_METHOD')) { ...@@ -7,6 +7,7 @@ if (!defined('PHPUnit_MAIN_METHOD')) {
require_once 'lib/DoctrineTestInit.php'; require_once 'lib/DoctrineTestInit.php';
// Suites // Suites
require_once 'Common/AllTests.php';
require_once 'Dbal/AllTests.php'; require_once 'Dbal/AllTests.php';
require_once 'Orm/AllTests.php'; require_once 'Orm/AllTests.php';
...@@ -21,6 +22,7 @@ class AllTests ...@@ -21,6 +22,7 @@ class AllTests
{ {
$suite = new Doctrine_TestSuite('Doctrine Tests'); $suite = new Doctrine_TestSuite('Doctrine Tests');
$suite->addTest(Common_AllTests::suite());
$suite->addTest(Dbal_AllTests::suite()); $suite->addTest(Dbal_AllTests::suite());
$suite->addTest(Orm_AllTests::suite()); $suite->addTest(Orm_AllTests::suite());
......
<?php
if (!defined('PHPUnit_MAIN_METHOD')) {
define('PHPUnit_MAIN_METHOD', 'Common_AllTests::main');
}
require_once 'lib/DoctrineTestInit.php';
// Suites
require_once 'Common/Collections/AllTests.php';
class Common_AllTests
{
public static function main()
{
PHPUnit_TextUI_TestRunner::run(self::suite());
}
public static function suite()
{
$suite = new Doctrine_TestSuite('Doctrine Common Tests');
$suite->addTest(Common_Collections_AllTests::suite());
return $suite;
}
}
if (PHPUnit_MAIN_METHOD == 'Common_AllTests::main') {
Common_AllTests::main();
}
\ No newline at end of file
<?php
if (!defined('PHPUnit_MAIN_METHOD')) {
define('PHPUnit_MAIN_METHOD', 'Common_Collections_AllTests::main');
}
require_once 'lib/DoctrineTestInit.php';
// Tests
require_once 'Common/Collections/CollectionTest.php';
class Common_Collections_AllTests
{
public static function main()
{
PHPUnit_TextUI_TestRunner::run(self::suite());
}
public static function suite()
{
$suite = new Doctrine_TestSuite('Doctrine Common Collections Tests');
$suite->addTestSuite('Common_Collections_CollectionTest');
return $suite;
}
}
if (PHPUnit_MAIN_METHOD == 'Common_Collections_AllTests::main') {
Common_Collections_AllTests::main();
}
\ No newline at end of file
<?php
#namespace Doctrine\Tests\Common\Collections;
require_once 'lib/DoctrineTestInit.php';
/**
* Collection tests.
*
* @author robo
* @since 2.0
*/
class Common_Collections_CollectionTest extends Doctrine_TestCase {
private $_coll;
protected function setUp() {
$this->_coll = new Doctrine_Common_Collections_Collection;
}
/*public function testExists() {
$this->_coll->add("one");
$this->_coll->add("two");
$exists = $this->_coll->exists(function($key, $element) { return $element == "one"; });
$this->assertTrue($exists);
$exists = $this->_coll->exists(function($key, $element) { return $element == "other"; });
$this->assertFalse($exists);
}
public function testMap() {
$this->_coll->add(1);
$this->_coll->add(2);
$res = $this->_coll->map(function ($e) { return $e * 2; });
$this->assertEquals(array(2, 4), $res->unwrap());
}
public function testFilter() {
$this->_coll->add(1);
$this->_coll->add("foo");
$this->_coll->add(3);
$res = $this->_coll->filter(function ($e) { return is_numeric($e); });
$this->assertEquals(array(0 => 1, 2 => 3), $res->unwrap());
}*/
}
...@@ -12,6 +12,7 @@ require_once 'Orm/Ticket/AllTests.php'; ...@@ -12,6 +12,7 @@ require_once 'Orm/Ticket/AllTests.php';
require_once 'Orm/Entity/AllTests.php'; require_once 'Orm/Entity/AllTests.php';
require_once 'Orm/Associations/AllTests.php'; require_once 'Orm/Associations/AllTests.php';
require_once 'Orm/Mapping/AllTests.php'; require_once 'Orm/Mapping/AllTests.php';
require_once 'Orm/Functional/AllTests.php';
// Tests // Tests
require_once 'Orm/UnitOfWorkTest.php'; require_once 'Orm/UnitOfWorkTest.php';
...@@ -41,6 +42,7 @@ class Orm_AllTests ...@@ -41,6 +42,7 @@ class Orm_AllTests
$suite->addTest(Orm_Ticket_AllTests::suite()); $suite->addTest(Orm_Ticket_AllTests::suite());
$suite->addTest(Orm_Associations_AllTests::suite()); $suite->addTest(Orm_Associations_AllTests::suite());
$suite->addTest(Orm_Mapping_AllTests::suite()); $suite->addTest(Orm_Mapping_AllTests::suite());
$suite->addTest(Orm_Functional_AllTests::suite());
return $suite; return $suite;
} }
......
...@@ -8,13 +8,14 @@ require_once 'lib/DoctrineTestInit.php'; ...@@ -8,13 +8,14 @@ require_once 'lib/DoctrineTestInit.php';
* @author robo * @author robo
*/ */
class Orm_Functional_BasicCRUDTest extends Doctrine_OrmFunctionalTestCase { class Orm_Functional_BasicCRUDTest extends Doctrine_OrmFunctionalTestCase {
public function testSingleEntityCRUD() { public function testSingleEntityCRUD() {
$em = $this->_getEntityManager(); $em = $this->_em;
$exporter = new Doctrine_ORM_Export_ClassExporter($em); $exporter = new Doctrine_ORM_Export_ClassExporter($this->_em);
$exporter->exportClasses(array( $exporter->exportClasses(array(
$em->getClassMetadata('CmsUser'), $this->_em->getClassMetadata('CmsUser'),
$em->getClassMetadata('CmsPhonenumber') $this->_em->getClassMetadata('CmsPhonenumber')
)); ));
// Create // Create
...@@ -46,11 +47,20 @@ class Orm_Functional_BasicCRUDTest extends Doctrine_OrmFunctionalTestCase { ...@@ -46,11 +47,20 @@ class Orm_Functional_BasicCRUDTest extends Doctrine_OrmFunctionalTestCase {
$this->assertTrue($em->getUnitOfWork()->isRegisteredRemoved($user)); $this->assertTrue($em->getUnitOfWork()->isRegisteredRemoved($user));
$em->flush(); $em->flush();
$this->assertFalse($em->getUnitOfWork()->isRegisteredRemoved($user)); $this->assertFalse($em->getUnitOfWork()->isRegisteredRemoved($user));
} }
public function testMore() { public function testMore() {
echo PHP_EOL . "SECOND" . PHP_EOL;
/*$user = new CmsUser;
$user->name = 'jon';
$user->*/
$ph = new CmsPhonenumber;
$ph->phonenumber = 123456;
$this->_em->save($ph);
$this->_em->flush();
} }
} }
...@@ -134,7 +134,10 @@ class ClassMetadataFactoryTestSubject extends Doctrine_ORM_Mapping_ClassMetadata ...@@ -134,7 +134,10 @@ class ClassMetadataFactoryTestSubject extends Doctrine_ORM_Mapping_ClassMetadata
/* Test classes */ /* Test classes */
class CMFTest_Entity1 {} class CMFTest_Entity1 {
protected $name;
protected $other;
}
class CMFTest_Entity2 extends CMFTest_Entity1 {} class CMFTest_Entity2 extends CMFTest_Entity1 {}
class CMFTest_Entity3 extends CMFTest_Entity2 {} class CMFTest_Entity3 extends CMFTest_Entity2 {}
...@@ -10,7 +10,7 @@ class Orm_Mapping_ClassMetadataTest extends Doctrine_OrmTestCase ...@@ -10,7 +10,7 @@ class Orm_Mapping_ClassMetadataTest extends Doctrine_OrmTestCase
$cm = new Doctrine_ORM_Mapping_ClassMetadata('CmsUser'); $cm = new Doctrine_ORM_Mapping_ClassMetadata('CmsUser');
// Test initial state // Test initial state
$this->assertTrue(count($cm->getReflectionProperties()) > 0); $this->assertTrue(count($cm->getReflectionProperties()) == 0);
$this->assertTrue($cm->getReflectionClass() instanceof ReflectionClass); $this->assertTrue($cm->getReflectionClass() instanceof ReflectionClass);
$this->assertEquals('CmsUser', $cm->getClassName()); $this->assertEquals('CmsUser', $cm->getClassName());
$this->assertEquals('CmsUser', $cm->getRootClassName()); $this->assertEquals('CmsUser', $cm->getRootClassName());
...@@ -22,8 +22,8 @@ class Orm_Mapping_ClassMetadataTest extends Doctrine_OrmTestCase ...@@ -22,8 +22,8 @@ class Orm_Mapping_ClassMetadataTest extends Doctrine_OrmTestCase
$cm->setParentClasses(array("UserParent")); $cm->setParentClasses(array("UserParent"));
$cm->setCustomRepositoryClass("UserRepository"); $cm->setCustomRepositoryClass("UserRepository");
$cm->setDiscriminatorColumn(array('name' => 'disc', 'type' => 'integer')); $cm->setDiscriminatorColumn(array('name' => 'disc', 'type' => 'integer'));
$cm->mapOneToOne(array('fieldName' => 'foo', 'targetEntity' => 'Bar', 'mappedBy' => 'foo')); $cm->mapOneToOne(array('fieldName' => 'phonenumbers', 'targetEntity' => 'Bar', 'mappedBy' => 'foo'));
$this->assertTrue($cm->getAssociationMapping('foo') instanceof Doctrine_ORM_Mapping_OneToOneMapping); $this->assertTrue($cm->getAssociationMapping('phonenumbers') instanceof Doctrine_ORM_Mapping_OneToOneMapping);
$this->assertEquals(1, count($cm->getAssociationMappings())); $this->assertEquals(1, count($cm->getAssociationMappings()));
$serialized = serialize($cm); $serialized = serialize($cm);
...@@ -38,10 +38,10 @@ class Orm_Mapping_ClassMetadataTest extends Doctrine_OrmTestCase ...@@ -38,10 +38,10 @@ class Orm_Mapping_ClassMetadataTest extends Doctrine_OrmTestCase
$this->assertEquals(array('UserParent'), $cm->getParentClasses()); $this->assertEquals(array('UserParent'), $cm->getParentClasses());
$this->assertEquals('UserRepository', $cm->getCustomRepositoryClass()); $this->assertEquals('UserRepository', $cm->getCustomRepositoryClass());
$this->assertEquals(array('name' => 'disc', 'type' => 'integer'), $cm->getDiscriminatorColumn()); $this->assertEquals(array('name' => 'disc', 'type' => 'integer'), $cm->getDiscriminatorColumn());
$this->assertTrue($cm->getAssociationMapping('foo') instanceof Doctrine_ORM_Mapping_OneToOneMapping); $this->assertTrue($cm->getAssociationMapping('phonenumbers') instanceof Doctrine_ORM_Mapping_OneToOneMapping);
$this->assertEquals(1, count($cm->getAssociationMappings())); $this->assertEquals(1, count($cm->getAssociationMappings()));
$oneOneMapping = $cm->getAssociationMapping('foo'); $oneOneMapping = $cm->getAssociationMapping('phonenumbers');
$this->assertEquals('foo', $oneOneMapping->getSourceFieldName()); $this->assertEquals('phonenumbers', $oneOneMapping->getSourceFieldName());
$this->assertEquals('Bar', $oneOneMapping->getTargetEntityName()); $this->assertEquals('Bar', $oneOneMapping->getTargetEntityName());
} }
......
...@@ -18,5 +18,6 @@ ...@@ -18,5 +18,6 @@
<var name="db_username" value="foo" /> <var name="db_username" value="foo" />
<var name="db_password" value="bar" /> <var name="db_password" value="bar" />
<var name="db_name" value="doctrinetests" /> <var name="db_name" value="doctrinetests" />
<var name="db_port" value="3306"/>
</php> </php>
</phpunit> </phpunit>
\ No newline at end of file
...@@ -8,6 +8,8 @@ ...@@ -8,6 +8,8 @@
*/ */
class Doctrine_OrmFunctionalTestCase extends Doctrine_OrmTestCase class Doctrine_OrmFunctionalTestCase extends Doctrine_OrmTestCase
{ {
protected $_em;
/** /**
* The currently loaded model names of the fixtures for the testcase. * The currently loaded model names of the fixtures for the testcase.
*/ */
...@@ -103,13 +105,18 @@ class Doctrine_OrmFunctionalTestCase extends Doctrine_OrmTestCase ...@@ -103,13 +105,18 @@ class Doctrine_OrmFunctionalTestCase extends Doctrine_OrmTestCase
foreach (array_reverse($this->_loadedFixtures) as $table) { foreach (array_reverse($this->_loadedFixtures) as $table) {
$conn->exec("DELETE FROM " . $table); $conn->exec("DELETE FROM " . $table);
} }
$this->_em->clear();
} }
protected function setUp() protected function setUp()
{ {
if ( ! isset($this->sharedFixture['conn'])) { if ( ! isset($this->sharedFixture['conn'])) {
echo " --- CREATE CONNECTION ----";
$this->sharedFixture['conn'] = Doctrine_TestUtil::getConnection(); $this->sharedFixture['conn'] = Doctrine_TestUtil::getConnection();
} }
if ( ! $this->_em) {
$this->_em = $this->_getEntityManager();
}
} }
protected function _getEntityManager($config = null, $eventManager = null) { protected function _getEntityManager($config = null, $eventManager = null) {
......
...@@ -13,8 +13,13 @@ class Doctrine_OrmFunctionalTestSuite extends Doctrine_OrmTestSuite ...@@ -13,8 +13,13 @@ class Doctrine_OrmFunctionalTestSuite extends Doctrine_OrmTestSuite
{ {
protected function setUp() protected function setUp()
{ {
if ( ! isset($this->sharedFixture['conn'])) {
$this->sharedFixture['conn'] = Doctrine_TestUtil::getConnection();
}
} }
protected function tearDown() protected function tearDown()
{} {
$this->sharedFixture = null;
}
} }
\ No newline at end of file
...@@ -7,13 +7,14 @@ class Doctrine_TestUtil ...@@ -7,13 +7,14 @@ class Doctrine_TestUtil
public static function getConnection() public static function getConnection()
{ {
if (isset($GLOBALS['db_type'], $GLOBALS['db_username'], $GLOBALS['db_password'], if (isset($GLOBALS['db_type'], $GLOBALS['db_username'], $GLOBALS['db_password'],
$GLOBALS['db_host'], $GLOBALS['db_name'])) { $GLOBALS['db_host'], $GLOBALS['db_name'], $GLOBALS['db_port'])) {
$params = array( $params = array(
'driver' => $GLOBALS['db_type'], 'driver' => $GLOBALS['db_type'],
'user' => $GLOBALS['db_username'], 'user' => $GLOBALS['db_username'],
'password' => $GLOBALS['db_password'], 'password' => $GLOBALS['db_password'],
'host' => $GLOBALS['db_host'], 'host' => $GLOBALS['db_host'],
'database' => $GLOBALS['db_name'] 'dbname' => $GLOBALS['db_name'],
'port' => $GLOBALS['db_port']
); );
} else { } else {
$params = array( $params = array(
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment