From a4216926792a45ffc834ccfbb31bf1a58274b9e0 Mon Sep 17 00:00:00 2001 From: romanb Date: Thu, 21 May 2009 19:18:14 +0000 Subject: [PATCH] [2.0] Fixed Query Cache (+testcase) and some E_STRICT errors. --- .../DBAL/Platforms/AbstractPlatform.php | 2 +- lib/Doctrine/ORM/AbstractQuery.php | 13 ++-- lib/Doctrine/ORM/DynamicProxyGenerator.php | 16 +++-- .../Internal/Hydration/AbstractHydrator.php | 6 +- .../ORM/Internal/Hydration/ArrayHydrator.php | 6 +- .../ORM/Internal/Hydration/ObjectHydrator.php | 11 ++-- .../ORM/Mapping/AssociationMapping.php | 2 +- lib/Doctrine/ORM/NativeQuery.php | 15 ++--- lib/Doctrine/ORM/PersistentCollection.php | 3 +- lib/Doctrine/ORM/Query.php | 59 ++++++++----------- lib/Doctrine/ORM/Query/AbstractResult.php | 6 +- lib/Doctrine/ORM/Query/Parser.php | 19 ++---- lib/Doctrine/ORM/Query/ParserResult.php | 37 ++---------- lib/Doctrine/ORM/Query/QueryResult.php | 2 + lib/Doctrine/ORM/Query/SqlWalker.php | 14 +---- lib/Doctrine/ORM/Tools/SchemaTool.php | 1 - lib/Doctrine/ORM/UnitOfWork.php | 33 ++++++----- tests/Doctrine/Tests/Mocks/ConnectionMock.php | 2 +- .../Tests/ORM/Functional/AllTests.php | 1 + .../Tests/ORM/Functional/NativeQueryTest.php | 2 +- .../Tests/ORM/Functional/QueryCacheTest.php | 57 ++++++++++++++++++ .../Tests/ORM/Hydration/ArrayHydratorTest.php | 36 +++++------ .../ORM/Hydration/ObjectHydratorTest.php | 36 +++++------ .../ORM/Hydration/ResultSetMappingTest.php | 7 +-- .../ORM/Hydration/ScalarHydratorTest.php | 2 +- .../Hydration/SingleScalarHydratorTest.php | 2 +- .../Doctrine/Tests/OrmFunctionalTestCase.php | 6 ++ tests/Doctrine/Tests/OrmTestCase.php | 11 ++++ 28 files changed, 217 insertions(+), 190 deletions(-) create mode 100644 tests/Doctrine/Tests/ORM/Functional/QueryCacheTest.php diff --git a/lib/Doctrine/DBAL/Platforms/AbstractPlatform.php b/lib/Doctrine/DBAL/Platforms/AbstractPlatform.php index 7b47f61be..ab36cb631 100644 --- a/lib/Doctrine/DBAL/Platforms/AbstractPlatform.php +++ b/lib/Doctrine/DBAL/Platforms/AbstractPlatform.php @@ -948,7 +948,7 @@ abstract class AbstractPlatform * * @todo Throw exception by default? */ - public function getDropSequenceSql() + public function getDropSequenceSql($sequenceName) { throw DoctrineException::updateMe('Drop sequence not supported by this driver.'); } diff --git a/lib/Doctrine/ORM/AbstractQuery.php b/lib/Doctrine/ORM/AbstractQuery.php index 3d6e49a0b..1ea44140f 100644 --- a/lib/Doctrine/ORM/AbstractQuery.php +++ b/lib/Doctrine/ORM/AbstractQuery.php @@ -188,7 +188,8 @@ abstract class AbstractQuery * * @param array $params */ - public function setParams(array $params = array()) { + public function setParams(array $params = array()) + { $this->_params = $params; } @@ -256,9 +257,9 @@ abstract class AbstractQuery * * @return Doctrine_Cache_Interface Cache driver */ - public function getResultCache() + public function getResultCacheDriver() { - if ($this->_resultCache instanceof \Doctrine\ORM\Cache\Cache) { + if ($this->_resultCache) { return $this->_resultCache; } else { return $this->_em->getConfiguration()->getResultCacheImpl(); @@ -471,10 +472,8 @@ abstract class AbstractQuery $params = $this->getParams($params); - // Check result cache (Only for SELECT queries) - if ($this->_resultCache && $this->_type === self::SELECT) { - $cacheDriver = $this->getResultCacheDriver(); - + // Check result cache + if ($cacheDriver = $this->getResultCacheDriver()) { // Calculate hash for DQL query. $hash = md5($this->getDql() . var_export($params, true)); $cached = ($this->_expireResultCache) ? false : $cacheDriver->fetch($hash); diff --git a/lib/Doctrine/ORM/DynamicProxyGenerator.php b/lib/Doctrine/ORM/DynamicProxyGenerator.php index 76047fdf8..9187024a3 100644 --- a/lib/Doctrine/ORM/DynamicProxyGenerator.php +++ b/lib/Doctrine/ORM/DynamicProxyGenerator.php @@ -22,18 +22,26 @@ namespace Doctrine\ORM; /** - * The DynamicProxyGenerator is used to generate proxy objects for entities. - * For that purpose he generates proxy class files on the fly as needed. + * The DynamicProxyGenerator is used to generate proxy objects for entities at runtime. * * @author Roman Borschel * @since 2.0 */ class DynamicProxyGenerator { + /** The namspace for the generated proxy classes. */ private static $_ns = 'Doctrine\Generated\Proxies\\'; - private $_cacheDir = '/Users/robo/dev/php/tmp/gen/'; + private $_cacheDir; private $_em; - + + /** + * Initializes a new instance of the DynamicProxyGenerator class that is + * connected to the given EntityManager and stores proxy class files in + * the given cache directory. + * + * @param EntityManager $em + * @param string $cacheDir + */ public function __construct(EntityManager $em, $cacheDir = null) { $this->_em = $em; diff --git a/lib/Doctrine/ORM/Internal/Hydration/AbstractHydrator.php b/lib/Doctrine/ORM/Internal/Hydration/AbstractHydrator.php index 4916e2dbd..7aa9f9a5b 100644 --- a/lib/Doctrine/ORM/Internal/Hydration/AbstractHydrator.php +++ b/lib/Doctrine/ORM/Internal/Hydration/AbstractHydrator.php @@ -180,7 +180,7 @@ abstract class AbstractHydrator $cache[$key]['fieldName'] = $this->_rsm->scalarMappings[$key]; $cache[$key]['isScalar'] = true; } else if (isset($this->_rsm->fieldMappings[$key])) { - $classMetadata = $this->_rsm->getOwningClass($key); + $classMetadata = $this->_em->getClassMetadata($this->_rsm->getOwningClass($key)); $fieldName = $this->_rsm->fieldMappings[$key]; $classMetadata = $this->_lookupDeclaringClass($classMetadata, $fieldName); $cache[$key]['fieldName'] = $fieldName; @@ -252,7 +252,7 @@ abstract class AbstractHydrator $cache[$key]['fieldName'] = $this->_rsm->scalarMappings[$key]; $cache[$key]['isScalar'] = true; } else { - $classMetadata = $this->_rsm->getOwningClass($key); + $classMetadata = $this->_em->getClassMetadata($this->_rsm->getOwningClass($key)); $fieldName = $this->_rsm->fieldMappings[$key]; $classMetadata = $this->_lookupDeclaringClass($classMetadata, $fieldName); $cache[$key]['fieldName'] = $fieldName; @@ -306,7 +306,7 @@ abstract class AbstractHydrator */ private function _lookupDeclaringClass($class, $fieldName) { - if ($class->hasField($fieldName)) { + if (isset($class->reflFields[$fieldName])) { return $class; } diff --git a/lib/Doctrine/ORM/Internal/Hydration/ArrayHydrator.php b/lib/Doctrine/ORM/Internal/Hydration/ArrayHydrator.php index 84830c213..3746f13ce 100644 --- a/lib/Doctrine/ORM/Internal/Hydration/ArrayHydrator.php +++ b/lib/Doctrine/ORM/Internal/Hydration/ArrayHydrator.php @@ -45,7 +45,7 @@ class ArrayHydrator extends AbstractHydrator $this->_resultPointers = array(); $this->_idTemplate = array(); $this->_resultCounter = 0; - foreach ($this->_rsm->getAliasMap() as $dqlAlias => $class) { + foreach ($this->_rsm->getAliasMap() as $dqlAlias => $className) { $this->_identifierMap[$dqlAlias] = array(); $this->_resultPointers[$dqlAlias] = array(); $this->_idTemplate[$dqlAlias] = ''; @@ -99,9 +99,9 @@ class ArrayHydrator extends AbstractHydrator // Get a reference to the right element in the result tree. // This element will get the associated element attached. if ($this->_rsm->isMixed && isset($this->_rootAliases[$parent])) { - $key = key(reset($this->_resultPointers)); + $first = reset($this->_resultPointers); // TODO: Exception if $key === null ? - $baseElement =& $this->_resultPointers[$parent][$key]; + $baseElement =& $this->_resultPointers[$parent][key($first)]; } else if (isset($this->_resultPointers[$parent])) { $baseElement =& $this->_resultPointers[$parent]; } else { diff --git a/lib/Doctrine/ORM/Internal/Hydration/ObjectHydrator.php b/lib/Doctrine/ORM/Internal/Hydration/ObjectHydrator.php index e6c57a821..51e738f9b 100644 --- a/lib/Doctrine/ORM/Internal/Hydration/ObjectHydrator.php +++ b/lib/Doctrine/ORM/Internal/Hydration/ObjectHydrator.php @@ -68,10 +68,11 @@ class ObjectHydrator extends AbstractHydrator $this->_resultCounter = 0; $this->_fetchedAssociations = array(); - foreach ($this->_rsm->aliasMap as $dqlAlias => $class) { + foreach ($this->_rsm->aliasMap as $dqlAlias => $className) { $this->_identifierMap[$dqlAlias] = array(); $this->_resultPointers[$dqlAlias] = array(); $this->_idTemplate[$dqlAlias] = ''; + $class = $this->_em->getClassMetadata($className); if ( ! isset($this->_ce[$class->name])) { $this->_ce[$class->name] = $class; @@ -88,7 +89,7 @@ class ObjectHydrator extends AbstractHydrator } } - // Remember which classes are "fetch joined" + // Remember which associations are "fetch joined" if (isset($this->_rsm->relationMap[$dqlAlias])) { $assoc = $this->_rsm->relationMap[$dqlAlias]; $this->_fetchedAssociations[$assoc->sourceEntityName][$assoc->sourceFieldName] = true; @@ -314,7 +315,7 @@ class ObjectHydrator extends AbstractHydrator // Hydrate the entity data found in the current row. foreach ($rowData as $dqlAlias => $data) { $index = false; - $entityName = $this->_rsm->aliasMap[$dqlAlias]->name; + $entityName = $this->_rsm->aliasMap[$dqlAlias]; if (isset($this->_rsm->parentAliasMap[$dqlAlias])) { // It's a joined result @@ -326,9 +327,9 @@ class ObjectHydrator extends AbstractHydrator // Get a reference to the right element in the result tree. // This element will get the associated element attached. if ($this->_rsm->isMixed && isset($this->_rootAliases[$parent])) { - $key = key(reset($this->_resultPointers)); + $first = reset($this->_resultPointers); // TODO: Exception if $key === null ? - $baseElement = $this->_resultPointers[$parent][$key]; + $baseElement = $this->_resultPointers[$parent][key($first)]; } else if (isset($this->_resultPointers[$parent])) { $baseElement = $this->_resultPointers[$parent]; } else { diff --git a/lib/Doctrine/ORM/Mapping/AssociationMapping.php b/lib/Doctrine/ORM/Mapping/AssociationMapping.php index f6121bf20..6bce92d63 100644 --- a/lib/Doctrine/ORM/Mapping/AssociationMapping.php +++ b/lib/Doctrine/ORM/Mapping/AssociationMapping.php @@ -382,5 +382,5 @@ abstract class AssociationMapping * @param $entity * @param $entityManager */ - /*abstract*/ public function load($entity, $em) {} + /*abstract public function load($entity, $em) {}*/ } \ No newline at end of file diff --git a/lib/Doctrine/ORM/NativeQuery.php b/lib/Doctrine/ORM/NativeQuery.php index 3b138ff61..32ac43d9f 100644 --- a/lib/Doctrine/ORM/NativeQuery.php +++ b/lib/Doctrine/ORM/NativeQuery.php @@ -24,8 +24,8 @@ namespace Doctrine\ORM; /** * Represents a native SQL query. * - * @since 2.0 * @author Roman Borschel + * @since 2.0 */ class NativeQuery extends AbstractQuery { @@ -55,7 +55,7 @@ class NativeQuery extends AbstractQuery /** * Gets the SQL query. * - * @return mixed The built sql query or an array of all sql queries. + * @return mixed The built SQL query or an array of all SQL queries. * @override */ public function getSql() @@ -67,18 +67,11 @@ class NativeQuery extends AbstractQuery * Executes the query. * * @param array $params - * @return Statement The Statement handle. + * @return Statement The Statement handle. * @override */ protected function _doExecute(array $params) { - // Assignments for Enums - //$this->_setEnumParams($this->_parserResult->getEnumParams()); - - // Converting parameters - $params = $this->_prepareParams($params); - - // Executing the query and returning statement - return $this->_em->getConnection()->execute($this->_sql, $params); + return $this->_em->getConnection()->execute($this->_sql, $this->_prepareParams($params)); } } \ No newline at end of file diff --git a/lib/Doctrine/ORM/PersistentCollection.php b/lib/Doctrine/ORM/PersistentCollection.php index be67e143c..76f7c718d 100644 --- a/lib/Doctrine/ORM/PersistentCollection.php +++ b/lib/Doctrine/ORM/PersistentCollection.php @@ -116,7 +116,8 @@ final class PersistentCollection extends \Doctrine\Common\Collections\Collection * @var boolean */ private $_isDirty = false; - + + /** Whether the collection has already been initialized. */ private $_initialized = false; /** diff --git a/lib/Doctrine/ORM/Query.php b/lib/Doctrine/ORM/Query.php index 93526f708..1b9e95905 100644 --- a/lib/Doctrine/ORM/Query.php +++ b/lib/Doctrine/ORM/Query.php @@ -66,19 +66,19 @@ class Query extends AbstractQuery protected $_parserResult; /** - * @var Doctrine_Cache_Interface The cache driver used for caching queries. + * @var CacheDriver The cache driver used for caching queries. */ - //protected $_queryCache; + protected $_queryCache; /** * @var boolean Boolean value that indicates whether or not expire the query cache. */ - //protected $_expireQueryCache = false; + protected $_expireQueryCache = false; /** * @var int Query Cache lifetime. */ - //protected $_queryCacheTTL; + protected $_queryCacheTTL; // End of Caching Stuff @@ -130,7 +130,7 @@ class Query extends AbstractQuery protected function _doExecute(array $params) { // If there is a CacheDriver associated to cache queries... - if ($queryCache = $this->_em->getConfiguration()->getQueryCacheImpl()) { + if ($queryCache = $this->getQueryCacheDriver()) { // Calculate hash for dql query. $hash = md5($this->getDql() . 'DOCTRINE_QUERY_CACHE_SALT'); $cached = ($this->_expireQueryCache) ? false : $queryCache->fetch($hash); @@ -138,10 +138,10 @@ class Query extends AbstractQuery if ($cached === false) { // Cache miss. $executor = $this->parse()->getSqlExecutor(); - $queryCache->save($hash, $this->_parserResult->toCachedForm(), null); + $queryCache->save($hash, serialize($this->_parserResult), null); } else { // Cache hit. - $this->_parserResult = CacheHandler::fromCachedQuery($this, $cached); + $this->_parserResult = unserialize($cached); $executor = $this->_parserResult->getSqlExecutor(); } } else { @@ -149,7 +149,7 @@ class Query extends AbstractQuery } // Assignments for Enums - $this->_setEnumParams($this->_parserResult->getEnumParams()); + //$this->_setEnumParams($this->_parserResult->getEnumParams()); // Converting parameters $params = $this->_prepareParams($params); @@ -168,32 +168,26 @@ class Query extends AbstractQuery * @param Doctrine_Cache_Interface|null $driver Cache driver * @return Doctrine_ORM_Query */ - /*public function setQueryCache($queryCache) + public function setQueryCacheDriver($queryCache) { - if ($queryCache !== null && ! ($queryCache instanceof \Doctrine\ORM\Cache\Cache)) { - throw DoctrineException::updateMe( - 'Method setResultCache() accepts only an instance of Doctrine_ORM_Cache_Interface or null.' - ); - } - $this->_queryCache = $queryCache; - return $this; - }*/ + } /** - * Returns the cache driver used for caching queries. + * Returns the cache driver used for query caching. * - * @return Doctrine_Cache_Interface Cache driver + * @return CacheDriver The cache driver used for query caching or NULL, if this + * Query does not use query caching. */ - /*public function getQueryCache() + public function getQueryCacheDriver() { - if ($this->_queryCache instanceof \Doctrine\ORM\Cache\Cache) { + if ($this->_queryCache) { return $this->_queryCache; } else { - return $this->_em->getConnection()->getQueryCacheDriver(); + return $this->_em->getConfiguration()->getQueryCacheImpl(); } - }*/ + } /** * Defines how long the query cache will be active before expire. @@ -201,26 +195,25 @@ class Query extends AbstractQuery * @param integer $timeToLive How long the cache entry is valid * @return Doctrine_ORM_Query */ - /*public function setQueryCacheLifetime($timeToLive) + public function setQueryCacheLifetime($timeToLive) { if ($timeToLive !== null) { $timeToLive = (int) $timeToLive; } - $this->_queryCacheTTL = $timeToLive; return $this; - }*/ + } /** * Retrieves the lifetime of resultset cache. * * @return int */ - /*public function getQueryCacheLifetime() + public function getQueryCacheLifetime() { return $this->_queryCacheTTL; - }*/ + } /** * Defines if the query cache is active or not. @@ -228,22 +221,22 @@ class Query extends AbstractQuery * @param boolean $expire Whether or not to force query cache expiration. * @return Doctrine_ORM_Query */ - /*public function setExpireQueryCache($expire = true) + public function setExpireQueryCache($expire = true) { - $this->_expireQueryCache = (bool) $expire; + $this->_expireQueryCache = $expire; return $this; - }*/ + } /** * Retrieves if the query cache is active or not. * * @return bool */ - /*public function getExpireQueryCache() + public function getExpireQueryCache() { return $this->_expireQueryCache; - }*/ + } /** * @override diff --git a/lib/Doctrine/ORM/Query/AbstractResult.php b/lib/Doctrine/ORM/Query/AbstractResult.php index 781298638..250940a96 100644 --- a/lib/Doctrine/ORM/Query/AbstractResult.php +++ b/lib/Doctrine/ORM/Query/AbstractResult.php @@ -44,17 +44,17 @@ abstract class AbstractResult /** * @var array Enum params. */ - protected $_enumParams = array(); + //protected $_enumParams = array(); /** * Returns the enum parameters. * * @return mixed Enum parameters. */ - public function getEnumParams() + /*public function getEnumParams() { return $this->_enumParams; - } + }*/ /** * Returns this object in serialized format, revertable using fromCached*. diff --git a/lib/Doctrine/ORM/Query/Parser.php b/lib/Doctrine/ORM/Query/Parser.php index a1e5882e8..15ad49144 100644 --- a/lib/Doctrine/ORM/Query/Parser.php +++ b/lib/Doctrine/ORM/Query/Parser.php @@ -40,8 +40,6 @@ use Doctrine\ORM\Query\Exec; */ class Parser { - const SCALAR_QUERYCOMPONENT_ALIAS = 'dctrn'; - /** Maps registered string function names to class names. */ private static $_STRING_FUNCTIONS = array( 'concat' => 'Doctrine\ORM\Query\AST\Functions\ConcatFunction', @@ -87,14 +85,14 @@ class Parser /** * A scanner object. * - * @var Doctrine_ORM_Query_Scanner + * @var Doctrine\ORM\Query\Lexer */ private $_lexer; /** * The Parser Result object. * - * @var Doctrine_ORM_Query_ParserResult + * @var Doctrine\ORM\Query\ParserResult */ private $_parserResult; @@ -131,8 +129,7 @@ class Parser $this->_em = $query->getEntityManager(); $this->_lexer = new Lexer($query->getDql()); $this->_parserResult = new ParserResult; - $this->_parserResult->setEntityManager($this->_em); - //$this->free(true); + //$this->_parserResult->setEntityManager($this->_em); } /** @@ -495,7 +492,6 @@ class Parser $identVariable = $this->_lexer->token['value']; $this->match('.'); } else { - //$identVariable = $this->_parserResult->getDefaultQueryComponentAlias(); throw new DoctrineException("Missing alias qualifier."); } $this->match(Lexer::T_IDENTIFIER); @@ -571,8 +567,7 @@ class Parser 'scalar' => null, ); $this->_queryComponents[$deleteClause->getAliasIdentificationVariable()] = $queryComponent; - //$this->_parserResult->setDefaultQueryComponentAlias($deleteClause->getAliasIdentificationVariable()); - //$this->_declaredClasses[$deleteClause->getAliasIdentificationVariable()] = $classMetadata; + return $deleteClause; } @@ -611,11 +606,6 @@ class Parser $identificationVariableDeclarations[] = $this->_IdentificationVariableDeclaration(); $firstRangeDecl = $identificationVariableDeclarations[0]->getRangeVariableDeclaration(); - /*if ($firstRangeDecl->getAliasIdentificationVariable()) { - $this->_parserResult->setDefaultQueryComponentAlias($firstRangeDecl->getAliasIdentificationVariable()); - } else { - $this->_parserResult->setDefaultQueryComponentAlias($firstRangeDecl->getAbstractSchemaName()); - }*/ while ($this->_lexer->isNextToken(',')) { $this->match(','); @@ -787,7 +777,6 @@ class Parser // Verify that the association exists, if yes update the ParserResult // with the new component. - //$parentComp = $this->_parserResult->getQueryComponent($joinPathExpression->getIdentificationVariable()); $parentClass = $this->_queryComponents[$joinPathExpression->getIdentificationVariable()]['metadata']; $assocField = $joinPathExpression->getAssociationField(); if ( ! $parentClass->hasAssociation($assocField)) { diff --git a/lib/Doctrine/ORM/Query/ParserResult.php b/lib/Doctrine/ORM/Query/ParserResult.php index 636a8768d..5a6b4faee 100644 --- a/lib/Doctrine/ORM/Query/ParserResult.php +++ b/lib/Doctrine/ORM/Query/ParserResult.php @@ -22,7 +22,8 @@ namespace Doctrine\ORM\Query; /** - * Doctrine_ORM_Query_ParserResult + * Encapsulates the resulting components from a DQL query parsing process that + * can be serialized. * * @author Guilherme Blanco * @author Janne Vanhala @@ -31,15 +32,9 @@ namespace Doctrine\ORM\Query; * @since 2.0 * @version $Revision$ */ -class ParserResult extends AbstractResult +class ParserResult { - /** - * The EntityManager. - * - * @var Doctrine_EntityManager - */ - protected $_em; - + protected $_sqlExecutor; protected $_resultSetMapping; public function __construct() @@ -67,33 +62,13 @@ class ParserResult extends AbstractResult { $this->_resultSetMapping = $rsm; } - - /** - * Sets the Entity Manager. - * - * @param Doctrine_EntityManager $em The Entity Manager. - */ - public function setEntityManager($em) - { - $this->_em = $em; - } - - /** - * Gets the Entity Manager. - * - * @return Doctrine_EntityManager - */ - public function getEntityManager() - { - return $this->_em; - } /** * @nodoc */ public function setSqlExecutor(\Doctrine\ORM\Query\Exec\AbstractExecutor $executor) { - $this->_data = $executor; + $this->_sqlExecutor = $executor; } /** @@ -101,6 +76,6 @@ class ParserResult extends AbstractResult */ public function getSqlExecutor() { - return $this->_data; + return $this->_sqlExecutor; } } \ No newline at end of file diff --git a/lib/Doctrine/ORM/Query/QueryResult.php b/lib/Doctrine/ORM/Query/QueryResult.php index 67054c072..7f5b899c9 100644 --- a/lib/Doctrine/ORM/Query/QueryResult.php +++ b/lib/Doctrine/ORM/Query/QueryResult.php @@ -33,6 +33,8 @@ namespace Doctrine\ORM\Query; */ class QueryResult extends AbstractResult { + protected $_data; + /** * Returns cached resultset. * diff --git a/lib/Doctrine/ORM/Query/SqlWalker.php b/lib/Doctrine/ORM/Query/SqlWalker.php index 050d9a207..98634388c 100644 --- a/lib/Doctrine/ORM/Query/SqlWalker.php +++ b/lib/Doctrine/ORM/Query/SqlWalker.php @@ -69,12 +69,6 @@ class SqlWalker $this->_em = $query->getEntityManager(); $this->_parserResult = $parserResult; $this->_queryComponents = $queryComponents; - - // In a mixed query we start alias counting for scalars with 1 since - // index 0 will hold the object. - /*if ($parserResult->isMixedQuery()) { - $this->_scalarResultCounter = 1; - }*/ } /** @@ -120,10 +114,10 @@ class SqlWalker foreach ($this->_selectedClasses as $dqlAlias => $class) { if ($this->_queryComponents[$dqlAlias]['relation'] === null) { - $this->_resultSetMapping->addEntityResult($class, $dqlAlias); + $this->_resultSetMapping->addEntityResult($class->name, $dqlAlias); } else { $this->_resultSetMapping->addJoinedEntityResult( - $class, $dqlAlias, + $class->name, $dqlAlias, $this->_queryComponents[$dqlAlias]['parent'], $this->_queryComponents[$dqlAlias]['relation'] ); @@ -691,9 +685,7 @@ class SqlWalker public function walkUpdateItem($updateItem) { $sql = ''; - $dqlAlias = $updateItem->getIdentificationVariable() ? - $updateItem->getIdentificationVariable() : - $this->_parserResult->getDefaultQueryComponentAlias(); + $dqlAlias = $updateItem->getIdentificationVariable(); $qComp = $this->_queryComponents[$dqlAlias]; if ($this->_useSqlTableAliases) { diff --git a/lib/Doctrine/ORM/Tools/SchemaTool.php b/lib/Doctrine/ORM/Tools/SchemaTool.php index 820764477..9eb69ae66 100644 --- a/lib/Doctrine/ORM/Tools/SchemaTool.php +++ b/lib/Doctrine/ORM/Tools/SchemaTool.php @@ -82,7 +82,6 @@ class SchemaTool $foreignKeyConstraints = array(); // FK SQL statements. Appended to $sql at the end. $sequences = array(); // Sequence SQL statements. Appended to $sql at the end. - // First we create the tables foreach ($classes as $class) { if (isset($processedClasses[$class->name])) { continue; diff --git a/lib/Doctrine/ORM/UnitOfWork.php b/lib/Doctrine/ORM/UnitOfWork.php index b4a7fe446..d81626533 100644 --- a/lib/Doctrine/ORM/UnitOfWork.php +++ b/lib/Doctrine/ORM/UnitOfWork.php @@ -47,7 +47,7 @@ use Doctrine\ORM\EntityManager; class UnitOfWork implements PropertyChangedListener { /** - * An Entity is in managed state when it has a primary key/identifier (and + * An entity is in managed state when it has a primary key/identifier (and * therefore persistent state) and is managed by an EntityManager * (registered in the identity map). * In MANAGED state the entity is associated with an EntityManager that manages @@ -56,20 +56,20 @@ class UnitOfWork implements PropertyChangedListener const STATE_MANAGED = 1; /** - * An Entity is new if it does not yet have an identifier/primary key + * An entity is new if it does not yet have an identifier/primary key * and is not (yet) managed by an EntityManager. */ const STATE_NEW = 2; /** - * A detached Entity is an instance with a persistent identity that is not + * A detached entity is an instance with a persistent identity that is not * (or no longer) associated with an EntityManager (and a UnitOfWork). - * This means its no longer in the identity map. + * This means it is no longer in the identity map. */ const STATE_DETACHED = 3; /** - * A removed Entity instance is an instance with a persistent identity, + * A removed entity instance is an instance with a persistent identity, * associated with an EntityManager, whose persistent state has been * deleted (or is scheduled for deletion). */ @@ -657,8 +657,10 @@ class UnitOfWork implements PropertyChangedListener } /** - * Registers a new entity. + * Registers a new entity. The entity will be scheduled for insertion. + * If the entity already has an identifier, it will be added to the identity map. * + * @param object $entity * @todo Rename to scheduleForInsert(). */ public function registerNew($entity) @@ -682,9 +684,9 @@ class UnitOfWork implements PropertyChangedListener } /** - * Checks whether an entity is registered as new on the unit of work. + * Checks whether an entity is registered as new on this unit of work. * - * @param Doctrine\ORM\Entity $entity + * @param object $entity * @return boolean * @todo Rename to isScheduledForInsert(). */ @@ -696,7 +698,7 @@ class UnitOfWork implements PropertyChangedListener /** * Registers a dirty entity. * - * @param Doctrine\ORM\Entity $entity + * @param object $entity * @todo Rename to scheduleForUpdate(). */ public function registerDirty($entity) @@ -788,8 +790,8 @@ class UnitOfWork implements PropertyChangedListener /** * Enter description here... * - * @param Doctrine\ORM\Entity $entity - * @return unknown + * @param object $entity + * @return boolean * @todo Rename to isScheduled() */ public function isEntityRegistered($entity) @@ -807,7 +809,7 @@ class UnitOfWork implements PropertyChangedListener * the identity map with the name of the root entity class. So calling detachAll() * with a class name that is not the name of a root entity has no effect. * - * @return integer The number of detached entities. + * @return integer The number of detached entities. */ public function detachAll($entityName = null) { @@ -834,7 +836,7 @@ class UnitOfWork implements PropertyChangedListener * Note that entities in a hierarchy are registered with the class name of * the root entity. * - * @param Doctrine\ORM\Entity $entity The entity to register. + * @param object $entity The entity to register. * @return boolean TRUE if the registration was successful, FALSE if the identity of * the entity in question is already managed. */ @@ -861,7 +863,7 @@ class UnitOfWork implements PropertyChangedListener * Gets the state of an entity within the current unit of work. * * @param object $entity - * @return int + * @return int The entity state. */ public function getEntityState($entity) { @@ -938,8 +940,7 @@ class UnitOfWork implements PropertyChangedListener } /** - * Checks whether an entity is registered in the identity map of the - * UnitOfWork. + * Checks whether an entity is registered in the identity map of this UnitOfWork. * * @param object $entity * @return boolean diff --git a/tests/Doctrine/Tests/Mocks/ConnectionMock.php b/tests/Doctrine/Tests/Mocks/ConnectionMock.php index cea142640..58f5f7cd0 100644 --- a/tests/Doctrine/Tests/Mocks/ConnectionMock.php +++ b/tests/Doctrine/Tests/Mocks/ConnectionMock.php @@ -43,7 +43,7 @@ class ConnectionMock extends \Doctrine\DBAL\Connection /** * @override */ - public function fetchOne($sql) + public function fetchOne($statement, array $params = array(), $colnum = 0) { return $this->_fetchOneResult; } diff --git a/tests/Doctrine/Tests/ORM/Functional/AllTests.php b/tests/Doctrine/Tests/ORM/Functional/AllTests.php index 9409abc2c..51ff5cf80 100644 --- a/tests/Doctrine/Tests/ORM/Functional/AllTests.php +++ b/tests/Doctrine/Tests/ORM/Functional/AllTests.php @@ -24,6 +24,7 @@ class AllTests $suite->addTestSuite('Doctrine\Tests\ORM\Functional\SingleTableInheritanceTest'); $suite->addTestSuite('Doctrine\Tests\ORM\Functional\ClassTableInheritanceTest'); $suite->addTestSuite('Doctrine\Tests\ORM\Functional\DetachedEntityTest'); + $suite->addTestSuite('Doctrine\Tests\ORM\Functional\QueryCacheTest'); return $suite; } diff --git a/tests/Doctrine/Tests/ORM/Functional/NativeQueryTest.php b/tests/Doctrine/Tests/ORM/Functional/NativeQueryTest.php index a65cb68fe..d2ce890ae 100644 --- a/tests/Doctrine/Tests/ORM/Functional/NativeQueryTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/NativeQueryTest.php @@ -29,7 +29,7 @@ class NativeQueryTest extends \Doctrine\Tests\OrmFunctionalTestCase $this->_em->flush(); $rsm = new ResultSetMapping; - $rsm->addEntityResult($this->_em->getClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'), 'u'); + $rsm->addEntityResult('Doctrine\Tests\Models\CMS\CmsUser', 'u'); $rsm->addFieldResult('u', 'id', 'id'); $rsm->addFieldResult('u', 'name', 'name'); diff --git a/tests/Doctrine/Tests/ORM/Functional/QueryCacheTest.php b/tests/Doctrine/Tests/ORM/Functional/QueryCacheTest.php new file mode 100644 index 000000000..6e8e251d0 --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Functional/QueryCacheTest.php @@ -0,0 +1,57 @@ +useModelSet('cms'); + parent::setUp(); + } + + public function testQueryCache() + { + $user = new CmsUser; + $user->name = 'Roman'; + $user->username = 'romanb'; + $user->status = 'dev'; + $this->_em->save($user); + $this->_em->flush(); + + + $query = $this->_em->createQuery('select ux from Doctrine\Tests\Models\CMS\CmsUser ux'); + $cache = new ArrayCache; + $query->setQueryCacheDriver($cache); + $this->assertEquals(0, $cache->count()); + + $users = $query->getResultList(); + + $this->assertEquals(1, $cache->count()); + $this->assertTrue($cache->contains(md5('select ux from Doctrine\Tests\Models\CMS\CmsUser uxDOCTRINE_QUERY_CACHE_SALT'))); + $this->assertEquals(1, count($users)); + $this->assertEquals('Roman', $users[0]->name); + + $this->_em->clear(); + + $query2 = $this->_em->createQuery('select ux from Doctrine\Tests\Models\CMS\CmsUser ux'); + $query2->setQueryCacheDriver($cache); + + $users = $query2->getResultList(); + + $this->assertEquals(1, $cache->count()); + $this->assertTrue($cache->contains(md5('select ux from Doctrine\Tests\Models\CMS\CmsUser uxDOCTRINE_QUERY_CACHE_SALT'))); + $this->assertEquals(1, count($users)); + $this->assertEquals('Roman', $users[0]->name); + } +} + diff --git a/tests/Doctrine/Tests/ORM/Hydration/ArrayHydratorTest.php b/tests/Doctrine/Tests/ORM/Hydration/ArrayHydratorTest.php index eba448e09..e30c2aa41 100644 --- a/tests/Doctrine/Tests/ORM/Hydration/ArrayHydratorTest.php +++ b/tests/Doctrine/Tests/ORM/Hydration/ArrayHydratorTest.php @@ -15,7 +15,7 @@ class ArrayHydratorTest extends HydrationTest public function testNewHydrationSimpleEntityQuery() { $rsm = new ResultSetMapping; - $rsm->addEntityResult($this->_em->getClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'), 'u'); + $rsm->addEntityResult('Doctrine\Tests\Models\CMS\CmsUser', 'u'); $rsm->addFieldResult('u', 'u__id', 'id'); $rsm->addFieldResult('u', 'u__name', 'name'); @@ -51,8 +51,8 @@ class ArrayHydratorTest extends HydrationTest public function testNewHydrationSimpleMultipleRootEntityQuery() { $rsm = new ResultSetMapping; - $rsm->addEntityResult($this->_em->getClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'), 'u'); - $rsm->addEntityResult($this->_em->getClassMetadata('Doctrine\Tests\Models\CMS\CmsArticle'), 'a'); + $rsm->addEntityResult('Doctrine\Tests\Models\CMS\CmsUser', 'u'); + $rsm->addEntityResult('Doctrine\Tests\Models\CMS\CmsArticle', 'a'); $rsm->addFieldResult('u', 'u__id', 'id'); $rsm->addFieldResult('u', 'u__name', 'name'); $rsm->addFieldResult('a', 'a__id', 'id'); @@ -102,9 +102,9 @@ class ArrayHydratorTest extends HydrationTest public function testNewHydrationMixedQueryFetchJoin() { $rsm = new ResultSetMapping; - $rsm->addEntityResult($this->_em->getClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'), 'u'); + $rsm->addEntityResult('Doctrine\Tests\Models\CMS\CmsUser', 'u'); $rsm->addJoinedEntityResult( - $this->_em->getClassMetadata('Doctrine\Tests\Models\CMS\CmsPhonenumber'), + 'Doctrine\Tests\Models\CMS\CmsPhonenumber', 'p', 'u', $this->_em->getClassMetadata('Doctrine\Tests\Models\CMS\CmsUser')->getAssociationMapping('phonenumbers') @@ -169,7 +169,7 @@ class ArrayHydratorTest extends HydrationTest public function testNewHydrationMixedQueryNormalJoin() { $rsm = new ResultSetMapping; - $rsm->addEntityResult($this->_em->getClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'), 'u'); + $rsm->addEntityResult('Doctrine\Tests\Models\CMS\CmsUser', 'u'); $rsm->addFieldResult('u', 'u__id', 'id'); $rsm->addFieldResult('u', 'u__status', 'status'); $rsm->addScalarResult('sclr0', 'numPhones'); @@ -214,9 +214,9 @@ class ArrayHydratorTest extends HydrationTest public function testNewHydrationMixedQueryFetchJoinCustomIndex() { $rsm = new ResultSetMapping; - $rsm->addEntityResult($this->_em->getClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'), 'u'); + $rsm->addEntityResult('Doctrine\Tests\Models\CMS\CmsUser', 'u'); $rsm->addJoinedEntityResult( - $this->_em->getClassMetadata('Doctrine\Tests\Models\CMS\CmsPhonenumber'), + 'Doctrine\Tests\Models\CMS\CmsPhonenumber', 'p', 'u', $this->_em->getClassMetadata('Doctrine\Tests\Models\CMS\CmsUser')->getAssociationMapping('phonenumbers') @@ -289,15 +289,15 @@ class ArrayHydratorTest extends HydrationTest public function testNewHydrationMixedQueryMultipleFetchJoin() { $rsm = new ResultSetMapping; - $rsm->addEntityResult($this->_em->getClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'), 'u'); + $rsm->addEntityResult('Doctrine\Tests\Models\CMS\CmsUser', 'u'); $rsm->addJoinedEntityResult( - $this->_em->getClassMetadata('Doctrine\Tests\Models\CMS\CmsPhonenumber'), + 'Doctrine\Tests\Models\CMS\CmsPhonenumber', 'p', 'u', $this->_em->getClassMetadata('Doctrine\Tests\Models\CMS\CmsUser')->getAssociationMapping('phonenumbers') ); $rsm->addJoinedEntityResult( - $this->_em->getClassMetadata('Doctrine\Tests\Models\CMS\CmsArticle'), + 'Doctrine\Tests\Models\CMS\CmsArticle', 'a', 'u', $this->_em->getClassMetadata('Doctrine\Tests\Models\CMS\CmsUser')->getAssociationMapping('articles') @@ -409,21 +409,21 @@ class ArrayHydratorTest extends HydrationTest { $rsm = new ResultSetMapping; - $rsm->addEntityResult($this->_em->getClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'), 'u'); + $rsm->addEntityResult('Doctrine\Tests\Models\CMS\CmsUser', 'u'); $rsm->addJoinedEntityResult( - $this->_em->getClassMetadata('Doctrine\Tests\Models\CMS\CmsPhonenumber'), + 'Doctrine\Tests\Models\CMS\CmsPhonenumber', 'p', 'u', $this->_em->getClassMetadata('Doctrine\Tests\Models\CMS\CmsUser')->getAssociationMapping('phonenumbers') ); $rsm->addJoinedEntityResult( - $this->_em->getClassMetadata('Doctrine\Tests\Models\CMS\CmsArticle'), + 'Doctrine\Tests\Models\CMS\CmsArticle', 'a', 'u', $this->_em->getClassMetadata('Doctrine\Tests\Models\CMS\CmsUser')->getAssociationMapping('articles') ); $rsm->addJoinedEntityResult( - $this->_em->getClassMetadata('Doctrine\Tests\Models\CMS\CmsComment'), + 'Doctrine\Tests\Models\CMS\CmsComment', 'c', 'a', $this->_em->getClassMetadata('Doctrine\Tests\Models\CMS\CmsArticle')->getAssociationMapping('comments') @@ -566,9 +566,9 @@ class ArrayHydratorTest extends HydrationTest public function testNewHydrationEntityQueryCustomResultSetOrder() { $rsm = new ResultSetMapping; - $rsm->addEntityResult($this->_em->getClassMetadata('Doctrine\Tests\Models\Forum\ForumCategory'), 'c'); + $rsm->addEntityResult('Doctrine\Tests\Models\Forum\ForumCategory', 'c'); $rsm->addJoinedEntityResult( - $this->_em->getClassMetadata('Doctrine\Tests\Models\Forum\ForumBoard'), + 'Doctrine\Tests\Models\Forum\ForumBoard', 'b', 'c', $this->_em->getClassMetadata('Doctrine\Tests\Models\Forum\ForumCategory')->getAssociationMapping('boards') @@ -633,7 +633,7 @@ class ArrayHydratorTest extends HydrationTest public function testResultIteration() { $rsm = new ResultSetMapping; - $rsm->addEntityResult($this->_em->getClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'), 'u'); + $rsm->addEntityResult('Doctrine\Tests\Models\CMS\CmsUser', 'u'); $rsm->addFieldResult('u', 'u__id', 'id'); $rsm->addFieldResult('u', 'u__name', 'name'); diff --git a/tests/Doctrine/Tests/ORM/Hydration/ObjectHydratorTest.php b/tests/Doctrine/Tests/ORM/Hydration/ObjectHydratorTest.php index be5976164..af3a68346 100644 --- a/tests/Doctrine/Tests/ORM/Hydration/ObjectHydratorTest.php +++ b/tests/Doctrine/Tests/ORM/Hydration/ObjectHydratorTest.php @@ -15,7 +15,7 @@ class ObjectHydratorTest extends HydrationTest public function testNewHydrationSimpleEntityQuery() { $rsm = new ResultSetMapping; - $rsm->addEntityResult($this->_em->getClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'), 'u'); + $rsm->addEntityResult('Doctrine\Tests\Models\CMS\CmsUser', 'u'); $rsm->addFieldResult('u', 'u__id', 'id'); $rsm->addFieldResult('u', 'u__name', 'name'); @@ -52,8 +52,8 @@ class ObjectHydratorTest extends HydrationTest public function testNewHydrationSimpleMultipleRootEntityQuery() { $rsm = new ResultSetMapping; - $rsm->addEntityResult($this->_em->getClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'), 'u'); - $rsm->addEntityResult($this->_em->getClassMetadata('Doctrine\Tests\Models\CMS\CmsArticle'), 'a'); + $rsm->addEntityResult('Doctrine\Tests\Models\CMS\CmsUser', 'u'); + $rsm->addEntityResult('Doctrine\Tests\Models\CMS\CmsArticle', 'a'); $rsm->addFieldResult('u', 'u__id', 'id'); $rsm->addFieldResult('u', 'u__name', 'name'); $rsm->addFieldResult('a', 'a__id', 'id'); @@ -108,9 +108,9 @@ class ObjectHydratorTest extends HydrationTest public function testNewHydrationMixedQueryFetchJoin() { $rsm = new ResultSetMapping; - $rsm->addEntityResult($this->_em->getClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'), 'u'); + $rsm->addEntityResult('Doctrine\Tests\Models\CMS\CmsUser', 'u'); $rsm->addJoinedEntityResult( - $this->_em->getClassMetadata('Doctrine\Tests\Models\CMS\CmsPhonenumber'), + 'Doctrine\Tests\Models\CMS\CmsPhonenumber', 'p', 'u', $this->_em->getClassMetadata('Doctrine\Tests\Models\CMS\CmsUser')->getAssociationMapping('phonenumbers') @@ -182,7 +182,7 @@ class ObjectHydratorTest extends HydrationTest public function testNewHydrationMixedQueryNormalJoin() { $rsm = new ResultSetMapping; - $rsm->addEntityResult($this->_em->getClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'), 'u'); + $rsm->addEntityResult('Doctrine\Tests\Models\CMS\CmsUser', 'u'); $rsm->addFieldResult('u', 'u__id', 'id'); $rsm->addFieldResult('u', 'u__status', 'status'); $rsm->addScalarResult('sclr0', 'numPhones'); @@ -229,9 +229,9 @@ class ObjectHydratorTest extends HydrationTest public function testNewHydrationMixedQueryFetchJoinCustomIndex() { $rsm = new ResultSetMapping; - $rsm->addEntityResult($this->_em->getClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'), 'u'); + $rsm->addEntityResult('Doctrine\Tests\Models\CMS\CmsUser', 'u'); $rsm->addJoinedEntityResult( - $this->_em->getClassMetadata('Doctrine\Tests\Models\CMS\CmsPhonenumber'), + 'Doctrine\Tests\Models\CMS\CmsPhonenumber', 'p', 'u', $this->_em->getClassMetadata('Doctrine\Tests\Models\CMS\CmsUser')->getAssociationMapping('phonenumbers') @@ -308,15 +308,15 @@ class ObjectHydratorTest extends HydrationTest public function testNewHydrationMixedQueryMultipleFetchJoin() { $rsm = new ResultSetMapping; - $rsm->addEntityResult($this->_em->getClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'), 'u'); + $rsm->addEntityResult('Doctrine\Tests\Models\CMS\CmsUser', 'u'); $rsm->addJoinedEntityResult( - $this->_em->getClassMetadata('Doctrine\Tests\Models\CMS\CmsPhonenumber'), + 'Doctrine\Tests\Models\CMS\CmsPhonenumber', 'p', 'u', $this->_em->getClassMetadata('Doctrine\Tests\Models\CMS\CmsUser')->getAssociationMapping('phonenumbers') ); $rsm->addJoinedEntityResult( - $this->_em->getClassMetadata('Doctrine\Tests\Models\CMS\CmsArticle'), + 'Doctrine\Tests\Models\CMS\CmsArticle', 'a', 'u', $this->_em->getClassMetadata('Doctrine\Tests\Models\CMS\CmsUser')->getAssociationMapping('articles') @@ -423,21 +423,21 @@ class ObjectHydratorTest extends HydrationTest public function testNewHydrationMixedQueryMultipleDeepMixedFetchJoin() { $rsm = new ResultSetMapping; - $rsm->addEntityResult($this->_em->getClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'), 'u'); + $rsm->addEntityResult('Doctrine\Tests\Models\CMS\CmsUser', 'u'); $rsm->addJoinedEntityResult( - $this->_em->getClassMetadata('Doctrine\Tests\Models\CMS\CmsPhonenumber'), + 'Doctrine\Tests\Models\CMS\CmsPhonenumber', 'p', 'u', $this->_em->getClassMetadata('Doctrine\Tests\Models\CMS\CmsUser')->getAssociationMapping('phonenumbers') ); $rsm->addJoinedEntityResult( - $this->_em->getClassMetadata('Doctrine\Tests\Models\CMS\CmsArticle'), + 'Doctrine\Tests\Models\CMS\CmsArticle', 'a', 'u', $this->_em->getClassMetadata('Doctrine\Tests\Models\CMS\CmsUser')->getAssociationMapping('articles') ); $rsm->addJoinedEntityResult( - $this->_em->getClassMetadata('Doctrine\Tests\Models\CMS\CmsComment'), + 'Doctrine\Tests\Models\CMS\CmsComment', 'c', 'a', $this->_em->getClassMetadata('Doctrine\Tests\Models\CMS\CmsArticle')->getAssociationMapping('comments') @@ -574,9 +574,9 @@ class ObjectHydratorTest extends HydrationTest public function testNewHydrationEntityQueryCustomResultSetOrder() { $rsm = new ResultSetMapping; - $rsm->addEntityResult($this->_em->getClassMetadata('Doctrine\Tests\Models\Forum\ForumCategory'), 'c'); + $rsm->addEntityResult('Doctrine\Tests\Models\Forum\ForumCategory', 'c'); $rsm->addJoinedEntityResult( - $this->_em->getClassMetadata('Doctrine\Tests\Models\Forum\ForumBoard'), + 'Doctrine\Tests\Models\Forum\ForumBoard', 'b', 'c', $this->_em->getClassMetadata('Doctrine\Tests\Models\Forum\ForumCategory')->getAssociationMapping('boards') @@ -643,7 +643,7 @@ class ObjectHydratorTest extends HydrationTest public function testResultIteration() { $rsm = new ResultSetMapping; - $rsm->addEntityResult($this->_em->getClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'), 'u'); + $rsm->addEntityResult('Doctrine\Tests\Models\CMS\CmsUser', 'u'); $rsm->addFieldResult('u', 'u__id', 'id'); $rsm->addFieldResult('u', 'u__name', 'name'); diff --git a/tests/Doctrine/Tests/ORM/Hydration/ResultSetMappingTest.php b/tests/Doctrine/Tests/ORM/Hydration/ResultSetMappingTest.php index 58548f3a1..8f7d2930b 100644 --- a/tests/Doctrine/Tests/ORM/Hydration/ResultSetMappingTest.php +++ b/tests/Doctrine/Tests/ORM/Hydration/ResultSetMappingTest.php @@ -29,7 +29,7 @@ class ResultSetMappingTest extends \Doctrine\Tests\OrmTestCase public function testBasicResultSetMapping() { $this->_rsm->addEntityResult( - $this->_em->getClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'), + 'Doctrine\Tests\Models\CMS\CmsUser', 'u' ); $this->_rsm->addFieldResult('u', 'id', 'id'); @@ -42,10 +42,9 @@ class ResultSetMappingTest extends \Doctrine\Tests\OrmTestCase $this->assertFalse($this->_rsm->isScalarResult('username')); $this->assertFalse($this->_rsm->isScalarResult('name')); - $this->assertTrue($this->_rsm->getClass('u') instanceof ClassMetadata); + $this->assertTrue($this->_rsm->getClass('u') == 'Doctrine\Tests\Models\CMS\CmsUser'); $class = $this->_rsm->getOwningClass('id'); - $this->assertTrue($class instanceof ClassMetadata); - $this->assertEquals('Doctrine\Tests\Models\CMS\CmsUser', $class->name); + $this->assertTrue($class == 'Doctrine\Tests\Models\CMS\CmsUser'); $this->assertEquals('u', $this->_rsm->getEntityAlias('id')); $this->assertEquals('u', $this->_rsm->getEntityAlias('status')); diff --git a/tests/Doctrine/Tests/ORM/Hydration/ScalarHydratorTest.php b/tests/Doctrine/Tests/ORM/Hydration/ScalarHydratorTest.php index 96e755507..f0e6ba03f 100644 --- a/tests/Doctrine/Tests/ORM/Hydration/ScalarHydratorTest.php +++ b/tests/Doctrine/Tests/ORM/Hydration/ScalarHydratorTest.php @@ -15,7 +15,7 @@ class ScalarHydratorTest extends HydrationTest public function testNewHydrationSimpleEntityQuery() { $rsm = new ResultSetMapping; - $rsm->addEntityResult($this->_em->getClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'), 'u'); + $rsm->addEntityResult('Doctrine\Tests\Models\CMS\CmsUser', 'u'); $rsm->addFieldResult('u', 'u__id', 'id'); $rsm->addFieldResult('u', 'u__name', 'name'); diff --git a/tests/Doctrine/Tests/ORM/Hydration/SingleScalarHydratorTest.php b/tests/Doctrine/Tests/ORM/Hydration/SingleScalarHydratorTest.php index 65ea0a561..babc4442b 100644 --- a/tests/Doctrine/Tests/ORM/Hydration/SingleScalarHydratorTest.php +++ b/tests/Doctrine/Tests/ORM/Hydration/SingleScalarHydratorTest.php @@ -55,7 +55,7 @@ class SingleScalarHydratorTest extends HydrationTest public function testHydrateSingleScalar($name, $resultSet) { $rsm = new ResultSetMapping; - $rsm->addEntityResult($this->_em->getClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'), 'u'); + $rsm->addEntityResult('Doctrine\Tests\Models\CMS\CmsUser', 'u'); $rsm->addFieldResult('u', 'u__id', 'id'); $rsm->addFieldResult('u', 'u__name', 'name'); diff --git a/tests/Doctrine/Tests/OrmFunctionalTestCase.php b/tests/Doctrine/Tests/OrmFunctionalTestCase.php index 6fa101d16..8f88f2fbe 100644 --- a/tests/Doctrine/Tests/OrmFunctionalTestCase.php +++ b/tests/Doctrine/Tests/OrmFunctionalTestCase.php @@ -11,6 +11,8 @@ class OrmFunctionalTestCase extends OrmTestCase { /* The metadata cache shared between all functional tests. */ private static $_metadataCacheImpl = null; + /* The query cache shared between all functional tests. */ + private static $_queryCacheImpl = null; /** The EntityManager for this testcase. */ protected $_em; @@ -123,8 +125,12 @@ class OrmFunctionalTestCase extends OrmTestCase if (is_null(self::$_metadataCacheImpl)) { self::$_metadataCacheImpl = new \Doctrine\ORM\Cache\ArrayCache; } + if (is_null(self::$_queryCacheImpl)) { + self::$_queryCacheImpl = new \Doctrine\ORM\Cache\ArrayCache; + } $config = new \Doctrine\ORM\Configuration(); $config->setMetadataCacheImpl(self::$_metadataCacheImpl); + $config->setQueryCacheImpl(self::$_queryCacheImpl); $eventManager = new \Doctrine\Common\EventManager(); $conn = $this->sharedFixture['conn']; return \Doctrine\ORM\EntityManager::create($conn, $config, $eventManager); diff --git a/tests/Doctrine/Tests/OrmTestCase.php b/tests/Doctrine/Tests/OrmTestCase.php index e3e257b16..c56e0684d 100644 --- a/tests/Doctrine/Tests/OrmTestCase.php +++ b/tests/Doctrine/Tests/OrmTestCase.php @@ -9,6 +9,8 @@ class OrmTestCase extends DoctrineTestCase { /** The metadata cache that is shared between all ORM tests (except functional tests). */ private static $_metadataCacheImpl = null; + /** The query cache that is shared between all ORM tests (except functional tests). */ + private static $_queryCacheImpl = null; /** * Creates an EntityManager for testing purposes. @@ -24,6 +26,7 @@ class OrmTestCase extends DoctrineTestCase { $config = new \Doctrine\ORM\Configuration(); $config->setMetadataCacheImpl(self::getSharedMetadataCacheImpl()); + $config->setQueryCacheImpl(self::getSharedQueryCacheImpl()); $eventManager = new \Doctrine\Common\EventManager(); if ($conn === null) { $conn = array( @@ -43,4 +46,12 @@ class OrmTestCase extends DoctrineTestCase } return self::$_metadataCacheImpl; } + + private static function getSharedQueryCacheImpl() + { + if (self::$_queryCacheImpl === null) { + self::$_queryCacheImpl = new \Doctrine\ORM\Cache\ArrayCache; + } + return self::$_queryCacheImpl; + } }