mirror of
https://github.com/doctrine/orm.git
synced 2026-03-24 06:52:09 +01:00
Compare commits
51 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d679154fba | ||
|
|
7cf4337dc1 | ||
|
|
41cf2ce4b1 | ||
|
|
13b8d05def | ||
|
|
209d098672 | ||
|
|
53600484cd | ||
|
|
ac25d62a24 | ||
|
|
f7936bda70 | ||
|
|
78899cedac | ||
|
|
73fef2867f | ||
|
|
c883ff2644 | ||
|
|
7595025f26 | ||
|
|
8fb6f986dd | ||
|
|
6dbb368995 | ||
|
|
c39ad9250a | ||
|
|
8adc267d87 | ||
|
|
2a8dd72b33 | ||
|
|
e44289dbdb | ||
|
|
dbf1c4cdb9 | ||
|
|
aa0c89e45e | ||
|
|
f77a1c2c8b | ||
|
|
ab1835a9db | ||
|
|
e5950d5fe9 | ||
|
|
41f41d2bd8 | ||
|
|
da47aa3ea2 | ||
|
|
2f976ea03a | ||
|
|
e10d865b01 | ||
|
|
d91e633eff | ||
|
|
845d152604 | ||
|
|
01eb894c4e | ||
|
|
d668d50ca4 | ||
|
|
cecfac5222 | ||
|
|
d391e28ffb | ||
|
|
f94b405f6e | ||
|
|
be6890e5aa | ||
|
|
286eef1ca3 | ||
|
|
0aecff7f71 | ||
|
|
c73dae141f | ||
|
|
d535e1c2bc | ||
|
|
f6d41ad9ce | ||
|
|
60de86e678 | ||
|
|
a37aabb11f | ||
|
|
789ce1604f | ||
|
|
e058b47966 | ||
|
|
7d77373a71 | ||
|
|
b6896a04e5 | ||
|
|
45fbc058a9 | ||
|
|
1574d482fe | ||
|
|
fb85cdfce0 | ||
|
|
0b6b87912c | ||
|
|
212e1d6df6 |
@@ -92,8 +92,8 @@
|
||||
<dependencies>
|
||||
<php minimum_version="5.3.0" />
|
||||
<pear minimum_version="1.6.0" recommended_version="1.6.1" />
|
||||
<package name="DoctrineCommon" channel="pear.doctrine-project.org" minimum_version="${dependencies.common}" />
|
||||
<package name="DoctrineDBAL" channel="pear.doctrine-project.org" minimum_version="${dependencies.dbal}" />
|
||||
<package name="DoctrineCommon" channel="pear.doctrine-project.org" minimum_version="${dependencies.common}" maximum_version="2.2.99" />
|
||||
<package name="DoctrineDBAL" channel="pear.doctrine-project.org" minimum_version="${dependencies.dbal}" maximum_version="2.2.99" />
|
||||
<package name="Console" channel="pear.symfony.com" minimum_version="2.0.0" />
|
||||
<package name="Yaml" channel="pear.symfony.com" minimum_version="2.0.0" />
|
||||
</dependencies>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "doctrine/orm",
|
||||
"type": "library",
|
||||
"type": "library","version":"2.2.0",
|
||||
"description": "Object-Relational-Mapper for PHP",
|
||||
"keywords": ["orm", "database"],
|
||||
"homepage": "http://www.doctrine-project.org",
|
||||
@@ -14,8 +14,8 @@
|
||||
"require": {
|
||||
"php": ">=5.3.2",
|
||||
"ext-pdo": "*",
|
||||
"doctrine/common": "master-dev",
|
||||
"doctrine/dbal": "master-dev"
|
||||
"doctrine/common": ">=2.2.0,<2.2.99",
|
||||
"doctrine/dbal": ">=2.2.1,<2.2.99"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-0": { "Doctrine\\ORM": "lib/" }
|
||||
|
||||
@@ -209,6 +209,7 @@ abstract class AbstractHydrator
|
||||
|
||||
case (isset($this->_rsm->scalarMappings[$key])):
|
||||
$cache[$key]['fieldName'] = $this->_rsm->scalarMappings[$key];
|
||||
$cache[$key]['type'] = Type::getType($this->_rsm->typeMappings[$key]);
|
||||
$cache[$key]['isScalar'] = true;
|
||||
break;
|
||||
|
||||
@@ -231,6 +232,8 @@ abstract class AbstractHydrator
|
||||
}
|
||||
|
||||
if (isset($cache[$key]['isScalar'])) {
|
||||
$value = $cache[$key]['type']->convertToPHPValue($value, $this->_platform);
|
||||
|
||||
$rowData['scalars'][$cache[$key]['fieldName']] = $value;
|
||||
|
||||
continue;
|
||||
|
||||
@@ -359,7 +359,6 @@ class ObjectHydrator extends AbstractHydrator
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
$parentClass = $this->_ce[$this->_rsm->aliasMap[$parentAlias]];
|
||||
$oid = spl_object_hash($parentObject);
|
||||
$relationField = $this->_rsm->relationMap[$dqlAlias];
|
||||
@@ -368,6 +367,7 @@ class ObjectHydrator extends AbstractHydrator
|
||||
|
||||
// Check the type of the relation (many or single-valued)
|
||||
if ( ! ($relation['type'] & ClassMetadata::TO_ONE)) {
|
||||
$reflFieldValue = $reflField->getValue($parentObject);
|
||||
// PATH A: Collection-valued association
|
||||
if (isset($nonemptyComponents[$dqlAlias])) {
|
||||
$collKey = $oid . $relationField;
|
||||
@@ -408,9 +408,12 @@ class ObjectHydrator extends AbstractHydrator
|
||||
// Update result pointer
|
||||
$this->_resultPointers[$dqlAlias] = $reflFieldValue[$index];
|
||||
}
|
||||
} else if ( ! $reflField->getValue($parentObject)) {
|
||||
} else if ( ! $reflFieldValue) {
|
||||
$reflFieldValue = $this->_initRelatedCollection($parentObject, $parentClass, $relationField, $parentAlias);
|
||||
} else if ($reflFieldValue instanceof PersistentCollection && $reflFieldValue->isInitialized() === false) {
|
||||
$reflFieldValue->setInitialized(true);
|
||||
}
|
||||
|
||||
} else {
|
||||
// PATH B: Single-valued association
|
||||
$reflFieldValue = $reflField->getValue($parentObject);
|
||||
|
||||
@@ -291,7 +291,6 @@ class ClassMetadataFactory implements ClassMetadataFactoryInterface
|
||||
// Invoke driver
|
||||
try {
|
||||
$this->driver->loadMetadataForClass($className, $class);
|
||||
$this->wakeupReflection($class, $this->getReflectionService());
|
||||
} catch (ReflectionException $e) {
|
||||
throw MappingException::reflectionFailure($className, $e);
|
||||
}
|
||||
@@ -333,6 +332,7 @@ class ClassMetadataFactory implements ClassMetadataFactoryInterface
|
||||
$eventArgs = new \Doctrine\ORM\Event\LoadClassMetadataEventArgs($class, $this->em);
|
||||
$this->evm->dispatchEvent(Events::loadClassMetadata, $eventArgs);
|
||||
}
|
||||
$this->wakeupReflection($class, $this->getReflectionService());
|
||||
|
||||
$this->validateRuntimeMetadata($class, $parent);
|
||||
|
||||
|
||||
@@ -253,8 +253,15 @@ class ManyToManyPersister extends AbstractCollectionPersister
|
||||
{
|
||||
$uow = $this->_em->getUnitOfWork();
|
||||
|
||||
// shortcut for new entities
|
||||
if ($uow->getEntityState($element, UnitOfWork::STATE_NEW) == UnitOfWork::STATE_NEW) {
|
||||
// Shortcut for new entities
|
||||
$entityState = $uow->getEntityState($element, UnitOfWork::STATE_NEW);
|
||||
|
||||
if ($entityState === UnitOfWork::STATE_NEW) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Entity is scheduled for inclusion
|
||||
if ($entityState === UnitOfWork::STATE_MANAGED && $uow->isScheduledForInsert($element)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -275,7 +282,15 @@ class ManyToManyPersister extends AbstractCollectionPersister
|
||||
$uow = $this->_em->getUnitOfWork();
|
||||
|
||||
// shortcut for new entities
|
||||
if ($uow->getEntityState($element, UnitOfWork::STATE_NEW) == UnitOfWork::STATE_NEW) {
|
||||
$entityState = $uow->getEntityState($element, UnitOfWork::STATE_NEW);
|
||||
|
||||
if ($entityState === UnitOfWork::STATE_NEW) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// If Entity is scheduled for inclusion, it is not in this collection.
|
||||
// We can assure that because it would have return true before on array check
|
||||
if ($entityState === UnitOfWork::STATE_MANAGED && $uow->isScheduledForInsert($element)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -159,7 +159,14 @@ class OneToManyPersister extends AbstractCollectionPersister
|
||||
$uow = $this->_em->getUnitOfWork();
|
||||
|
||||
// shortcut for new entities
|
||||
if ($uow->getEntityState($element, UnitOfWork::STATE_NEW) == UnitOfWork::STATE_NEW) {
|
||||
$entityState = $uow->getEntityState($element, UnitOfWork::STATE_NEW);
|
||||
|
||||
if ($entityState === UnitOfWork::STATE_NEW) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Entity is scheduled for inclusion
|
||||
if ($entityState === UnitOfWork::STATE_MANAGED && $uow->isScheduledForInsert($element)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -168,7 +175,7 @@ class OneToManyPersister extends AbstractCollectionPersister
|
||||
// only works with single id identifier entities. Will throw an
|
||||
// exception in Entity Persisters if that is not the case for the
|
||||
// 'mappedBy' field.
|
||||
$id = current( $uow->getEntityIdentifier($coll->getOwner()) );
|
||||
$id = current( $uow->getEntityIdentifier($coll->getOwner()));
|
||||
|
||||
return $persister->exists($element, array($mapping['mappedBy'] => $id));
|
||||
}
|
||||
@@ -183,7 +190,15 @@ class OneToManyPersister extends AbstractCollectionPersister
|
||||
$uow = $this->_em->getUnitOfWork();
|
||||
|
||||
// shortcut for new entities
|
||||
if ($uow->getEntityState($element, UnitOfWork::STATE_NEW) == UnitOfWork::STATE_NEW) {
|
||||
$entityState = $uow->getEntityState($element, UnitOfWork::STATE_NEW);
|
||||
|
||||
if ($entityState === UnitOfWork::STATE_NEW) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// If Entity is scheduled for inclusion, it is not in this collection.
|
||||
// We can assure that because it would have return true before on array check
|
||||
if ($entityState === UnitOfWork::STATE_MANAGED && $uow->isScheduledForInsert($element)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -48,12 +48,13 @@ class SingleTablePersister extends AbstractEntityInheritancePersister
|
||||
|
||||
$columnList = parent::_getSelectColumnListSQL();
|
||||
|
||||
// Append discriminator column
|
||||
$discrColumn = $this->_class->discriminatorColumn['name'];
|
||||
$columnList .= ', ' . $discrColumn;
|
||||
|
||||
$rootClass = $this->_em->getClassMetadata($this->_class->rootEntityName);
|
||||
$tableAlias = $this->_getSQLTableAlias($rootClass->name);
|
||||
|
||||
// Append discriminator column
|
||||
$discrColumn = $this->_class->discriminatorColumn['name'];
|
||||
$columnList .= ', ' . $tableAlias . '.' . $discrColumn;
|
||||
|
||||
$resultColumnName = $this->_platform->getSQLResultCasing($discrColumn);
|
||||
|
||||
$this->_rsm->setDiscriminatorColumn('r', $resultColumnName);
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
<?php
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
@@ -21,10 +19,12 @@
|
||||
|
||||
namespace Doctrine\ORM\Proxy;
|
||||
|
||||
use Doctrine\Common\Persistence\Proxy as BaseProxy;
|
||||
|
||||
/**
|
||||
* Interface for proxy classes.
|
||||
*
|
||||
* @author Roman Borschel <roman@code-factory.org>
|
||||
* @since 2.0
|
||||
*/
|
||||
interface Proxy {}
|
||||
interface Proxy extends BaseProxy {}
|
||||
|
||||
@@ -21,7 +21,8 @@ namespace Doctrine\ORM\Proxy;
|
||||
|
||||
use Doctrine\ORM\EntityManager,
|
||||
Doctrine\ORM\Mapping\ClassMetadata,
|
||||
Doctrine\ORM\Mapping\AssociationMapping;
|
||||
Doctrine\ORM\Mapping\AssociationMapping,
|
||||
Doctrine\Common\Util\ClassUtils;
|
||||
|
||||
/**
|
||||
* This factory is used to create proxy objects for entities at runtime.
|
||||
@@ -41,6 +42,14 @@ class ProxyFactory
|
||||
/** The directory that contains all proxy classes. */
|
||||
private $_proxyDir;
|
||||
|
||||
/**
|
||||
* Used to match very simple id methods that don't need
|
||||
* to be proxied since the identifier is known.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
const PATTERN_MATCH_ID_METHOD = '((public\s)?(function\s{1,}%s\s?\(\)\s{1,})\s{0,}{\s{0,}return\s{0,}\$this->%s;\s{0,}})i';
|
||||
|
||||
/**
|
||||
* Initializes a new instance of the <tt>ProxyFactory</tt> class that is
|
||||
* connected to the given <tt>EntityManager</tt>.
|
||||
@@ -74,13 +83,12 @@ class ProxyFactory
|
||||
*/
|
||||
public function getProxy($className, $identifier)
|
||||
{
|
||||
$proxyClassName = str_replace('\\', '', $className) . 'Proxy';
|
||||
$fqn = $this->_proxyNamespace . '\\' . $proxyClassName;
|
||||
$fqn = ClassUtils::generateProxyClassName($className, $this->_proxyNamespace);
|
||||
|
||||
if (! class_exists($fqn, false)) {
|
||||
$fileName = $this->_proxyDir . DIRECTORY_SEPARATOR . $proxyClassName . '.php';
|
||||
$fileName = $this->getProxyFileName($className);
|
||||
if ($this->_autoGenerate) {
|
||||
$this->_generateProxyClass($this->_em->getClassMetadata($className), $proxyClassName, $fileName, self::$_proxyClassTemplate);
|
||||
$this->_generateProxyClass($this->_em->getClassMetadata($className), $fileName, self::$_proxyClassTemplate);
|
||||
}
|
||||
require $fileName;
|
||||
}
|
||||
@@ -94,6 +102,17 @@ class ProxyFactory
|
||||
return new $fqn($entityPersister, $identifier);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate the Proxy file name
|
||||
*
|
||||
* @param string $className
|
||||
* @return string
|
||||
*/
|
||||
private function getProxyFileName($className)
|
||||
{
|
||||
return $this->_proxyDir . DIRECTORY_SEPARATOR . '__CG__' . str_replace('\\', '', $className) . '.php';
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates proxy classes for all given classes.
|
||||
*
|
||||
@@ -112,9 +131,8 @@ class ProxyFactory
|
||||
continue;
|
||||
}
|
||||
|
||||
$proxyClassName = str_replace('\\', '', $class->name) . 'Proxy';
|
||||
$proxyFileName = $proxyDir . $proxyClassName . '.php';
|
||||
$this->_generateProxyClass($class, $proxyClassName, $proxyFileName, self::$_proxyClassTemplate);
|
||||
$proxyFileName = $this->getProxyFileName($class->name);
|
||||
$this->_generateProxyClass($class, $proxyFileName, self::$_proxyClassTemplate);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -122,11 +140,10 @@ class ProxyFactory
|
||||
* Generates a proxy class file.
|
||||
*
|
||||
* @param $class
|
||||
* @param $originalClassName
|
||||
* @param $proxyClassName
|
||||
* @param $file The path of the file to write to.
|
||||
*/
|
||||
private function _generateProxyClass($class, $proxyClassName, $fileName, $file)
|
||||
private function _generateProxyClass($class, $fileName, $file)
|
||||
{
|
||||
$methods = $this->_generateMethods($class);
|
||||
$sleepImpl = $this->_generateSleep($class);
|
||||
@@ -138,16 +155,19 @@ class ProxyFactory
|
||||
'<methods>', '<sleepImpl>', '<cloneImpl>'
|
||||
);
|
||||
|
||||
if(substr($class->name, 0, 1) == "\\") {
|
||||
$className = substr($class->name, 1);
|
||||
} else {
|
||||
$className = $class->name;
|
||||
}
|
||||
$className = ltrim($class->name, '\\');
|
||||
$proxyClassName = ClassUtils::generateProxyClassName($class->name, $this->_proxyNamespace);
|
||||
$parts = explode('\\', strrev($proxyClassName), 2);
|
||||
$proxyClassNamespace = strrev($parts[1]);
|
||||
$proxyClassName = strrev($parts[0]);
|
||||
|
||||
$replacements = array(
|
||||
$this->_proxyNamespace,
|
||||
$proxyClassName, $className,
|
||||
$methods, $sleepImpl, $cloneImpl
|
||||
$proxyClassNamespace,
|
||||
$proxyClassName,
|
||||
$className,
|
||||
$methods,
|
||||
$sleepImpl,
|
||||
$cloneImpl
|
||||
);
|
||||
|
||||
$file = str_replace($placeholders, $replacements, $file);
|
||||
@@ -230,6 +250,14 @@ class ProxyFactory
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the method is a short identifier getter.
|
||||
*
|
||||
* What does this mean? For proxy objects the identifier is already known,
|
||||
* however accessing the getter for this identifier usually triggers the
|
||||
* lazy loading, leading to a query that may not be necessary if only the
|
||||
* ID is interesting for the userland code (for example in views that
|
||||
* generate links to the entity, but do not display anything else).
|
||||
*
|
||||
* @param ReflectionMethod $method
|
||||
* @param ClassMetadata $class
|
||||
* @return bool
|
||||
@@ -237,7 +265,7 @@ class ProxyFactory
|
||||
private function isShortIdentifierGetter($method, $class)
|
||||
{
|
||||
$identifier = lcfirst(substr($method->getName(), 3));
|
||||
return (
|
||||
$cheapCheck = (
|
||||
$method->getNumberOfParameters() == 0 &&
|
||||
substr($method->getName(), 0, 3) == "get" &&
|
||||
in_array($identifier, $class->identifier, true) &&
|
||||
@@ -245,6 +273,18 @@ class ProxyFactory
|
||||
(($method->getEndLine() - $method->getStartLine()) <= 4)
|
||||
&& in_array($class->fieldMappings[$identifier]['type'], array('integer', 'bigint', 'smallint', 'string'))
|
||||
);
|
||||
|
||||
if ($cheapCheck) {
|
||||
$code = file($class->reflClass->getFileName());
|
||||
$code = trim(implode(" ", array_slice($code, $method->getStartLine() - 1, $method->getEndLine() - $method->getStartLine() + 1)));
|
||||
|
||||
$pattern = sprintf(self::PATTERN_MATCH_ID_METHOD, $method->getName(), $identifier);
|
||||
|
||||
if (preg_match($pattern, $code)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -318,6 +358,12 @@ class <proxyClassName> extends \<className> implements \Doctrine\ORM\Proxy\Proxy
|
||||
}
|
||||
}
|
||||
|
||||
/** @private */
|
||||
public function __isInitialized()
|
||||
{
|
||||
return $this->__isInitialized__;
|
||||
}
|
||||
|
||||
<methods>
|
||||
|
||||
public function __sleep()
|
||||
|
||||
@@ -71,6 +71,12 @@ class ResultSetMapping
|
||||
*/
|
||||
public $scalarMappings = array();
|
||||
|
||||
/**
|
||||
* @ignore
|
||||
* @var array Maps column names in the result set to the alias/field type to use in the mapped result.
|
||||
*/
|
||||
public $typeMappings = array();
|
||||
|
||||
/**
|
||||
* @ignore
|
||||
* @var array Maps entities in the result set to the alias name to use in the mapped result.
|
||||
@@ -296,12 +302,16 @@ class ResultSetMapping
|
||||
*
|
||||
* @param string $columnName The name of the column in the SQL result set.
|
||||
* @param string $alias The result alias with which the scalar result should be placed in the result structure.
|
||||
* @param string $type The column type
|
||||
*
|
||||
* @return ResultSetMapping This ResultSetMapping instance.
|
||||
*
|
||||
* @todo Rename: addScalar
|
||||
*/
|
||||
public function addScalarResult($columnName, $alias)
|
||||
public function addScalarResult($columnName, $alias, $type = null)
|
||||
{
|
||||
$this->scalarMappings[$columnName] = $alias;
|
||||
$this->typeMappings[$columnName] = $type ?: 'string';
|
||||
|
||||
if ( ! $this->isMixed && $this->fieldMappings) {
|
||||
$this->isMixed = true;
|
||||
|
||||
@@ -39,6 +39,11 @@ use Doctrine\DBAL\LockMode,
|
||||
*/
|
||||
class SqlWalker implements TreeWalker
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
const HINT_DISTINCT = 'doctrine.distinct';
|
||||
|
||||
/**
|
||||
* @var ResultSetMapping
|
||||
*/
|
||||
@@ -590,6 +595,10 @@ class SqlWalker implements TreeWalker
|
||||
$sql = 'SELECT ' . (($selectClause->isDistinct) ? 'DISTINCT ' : '');
|
||||
$sqlSelectExpressions = array_filter(array_map(array($this, 'walkSelectExpression'), $selectClause->selectExpressions));
|
||||
|
||||
if ($this->_query->getHint(Query::HINT_INTERNAL_ITERATION) == true && $selectClause->isDistinct) {
|
||||
$this->_query->setHint(self::HINT_DISTINCT, true);
|
||||
}
|
||||
|
||||
$addMetaColumns = ! $this->_query->getHint(Query::HINT_FORCE_PARTIAL_LOAD) &&
|
||||
$this->_query->getHydrationMode() == Query::HYDRATE_OBJECT
|
||||
||
|
||||
@@ -811,9 +820,10 @@ class SqlWalker implements TreeWalker
|
||||
|
||||
// Ensure we got the owning side, since it has all mapping info
|
||||
$assoc = ( ! $relation['isOwningSide']) ? $targetClass->associationMappings[$relation['mappedBy']] : $relation;
|
||||
|
||||
if ($this->_query->getHint(Query::HINT_INTERNAL_ITERATION) == true && $relation['type'] & ClassMetadata::TO_MANY) {
|
||||
throw QueryException::iterateWithFetchJoinNotAllowed($assoc);
|
||||
if ($this->_query->getHint(Query::HINT_INTERNAL_ITERATION) == true && (!$this->_query->getHint(self::HINT_DISTINCT) || isset($this->_selectedClasses[$joinedDqlAlias]))) {
|
||||
if ($relation['type'] == ClassMetadata::ONE_TO_MANY || $relation['type'] == ClassMetadata::MANY_TO_MANY) {
|
||||
throw QueryException::iterateWithFetchJoinNotAllowed($assoc);
|
||||
}
|
||||
}
|
||||
|
||||
if ($joinVarDecl->indexBy) {
|
||||
@@ -1084,8 +1094,10 @@ class SqlWalker implements TreeWalker
|
||||
|
||||
$col = $sqlTableAlias . '.' . $columnName;
|
||||
|
||||
$fieldType = $class->getTypeOfField($fieldName);
|
||||
|
||||
if (isset($class->fieldMappings[$fieldName]['requireSQLConversion'])) {
|
||||
$type = Type::getType($class->getTypeOfField($fieldName));
|
||||
$type = Type::getType($fieldType);
|
||||
$col = $type->convertToPHPValueSQL($col, $this->_conn->getDatabasePlatform());
|
||||
}
|
||||
|
||||
@@ -1094,7 +1106,7 @@ class SqlWalker implements TreeWalker
|
||||
$this->_scalarResultAliasMap[$resultAlias] = $columnAlias;
|
||||
|
||||
if ( ! $hidden) {
|
||||
$this->_rsm->addScalarResult($columnAlias, $resultAlias);
|
||||
$this->_rsm->addScalarResult($columnAlias, $resultAlias, $fieldType);
|
||||
$this->_scalarFields[$dqlAlias][$fieldName] = $columnAlias;
|
||||
}
|
||||
break;
|
||||
@@ -1118,7 +1130,8 @@ class SqlWalker implements TreeWalker
|
||||
$this->_scalarResultAliasMap[$resultAlias] = $columnAlias;
|
||||
|
||||
if ( ! $hidden) {
|
||||
$this->_rsm->addScalarResult($columnAlias, $resultAlias);
|
||||
// We cannot resolve field type here; assume 'string'.
|
||||
$this->_rsm->addScalarResult($columnAlias, $resultAlias, 'string');
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -1131,7 +1144,8 @@ class SqlWalker implements TreeWalker
|
||||
$this->_scalarResultAliasMap[$resultAlias] = $columnAlias;
|
||||
|
||||
if ( ! $hidden) {
|
||||
$this->_rsm->addScalarResult($columnAlias, $resultAlias);
|
||||
// We cannot resolve field type here; assume 'string'.
|
||||
$this->_rsm->addScalarResult($columnAlias, $resultAlias, 'string');
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
@@ -50,6 +50,7 @@ class QueryBuilder
|
||||
* @var array The array of DQL parts collected.
|
||||
*/
|
||||
private $_dqlParts = array(
|
||||
'distinct' => false,
|
||||
'select' => array(),
|
||||
'from' => array(),
|
||||
'join' => array(),
|
||||
@@ -346,7 +347,7 @@ class QueryBuilder
|
||||
* ->setParameters(array(
|
||||
* 'user_id1' => 1,
|
||||
* 'user_id2' => 2
|
||||
* ));
|
||||
));
|
||||
* </code>
|
||||
*
|
||||
* @param array $params The query parameters to set.
|
||||
@@ -503,6 +504,25 @@ class QueryBuilder
|
||||
return $this->add('select', new Expr\Select($selects), false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a DISTINCT flag to this query.
|
||||
*
|
||||
* <code>
|
||||
* $qb = $em->createQueryBuilder()
|
||||
* ->select('u')
|
||||
* ->distinct()
|
||||
* ->from('User', 'u');
|
||||
* </code>
|
||||
*
|
||||
* @param bool
|
||||
* @return QueryBuilder
|
||||
*/
|
||||
public function distinct($flag = true)
|
||||
{
|
||||
$this->_dqlParts['distinct'] = (bool) $flag;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds an item that is to be returned in the query result.
|
||||
*
|
||||
@@ -981,7 +1001,9 @@ class QueryBuilder
|
||||
|
||||
private function _getDQLForSelect()
|
||||
{
|
||||
$dql = 'SELECT' . $this->_getReducedDQLQueryPart('select', array('pre' => ' ', 'separator' => ', '));
|
||||
$dql = 'SELECT'
|
||||
. ($this->_dqlParts['distinct']===true ? ' DISTINCT' : '')
|
||||
. $this->_getReducedDQLQueryPart('select', array('pre' => ' ', 'separator' => ', '));
|
||||
|
||||
$fromParts = $this->getDQLPart('from');
|
||||
$joinParts = $this->getDQLPart('join');
|
||||
@@ -1090,4 +1112,4 @@ class QueryBuilder
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -191,6 +191,8 @@ public function <methodName>()
|
||||
|
||||
if ( ! $this->_isNew) {
|
||||
$this->_parseTokensInEntityFile(file_get_contents($path));
|
||||
} else {
|
||||
$this->_staticReflection[$metadata->name] = array('properties' => array(), 'methods' => array());
|
||||
}
|
||||
|
||||
if ($this->_backupExisting && file_exists($path)) {
|
||||
@@ -581,9 +583,32 @@ public function <methodName>()
|
||||
$table[] = 'name="' . $metadata->table['name'] . '"';
|
||||
}
|
||||
|
||||
if (isset($metadata->table['uniqueConstraints']) && $metadata->table['uniqueConstraints']) {
|
||||
$constraints = $this->_generateTableConstraints('UniqueConstraint', $metadata->table['uniqueConstraints']);
|
||||
$table[] = 'uniqueConstraints={' . $constraints . '}';
|
||||
}
|
||||
|
||||
if (isset($metadata->table['indexes']) && $metadata->table['indexes']) {
|
||||
$constraints = $this->_generateTableConstraints('Index', $metadata->table['indexes']);
|
||||
$table[] = 'indexes={' . $constraints . '}';
|
||||
}
|
||||
|
||||
return '@' . $this->_annotationsPrefix . 'Table(' . implode(', ', $table) . ')';
|
||||
}
|
||||
|
||||
private function _generateTableConstraints($constraintName, $constraints)
|
||||
{
|
||||
$annotations = array();
|
||||
foreach ($constraints as $name => $constraint) {
|
||||
$columns = array();
|
||||
foreach ($constraint['columns'] as $column) {
|
||||
$columns[] = '"' . $column . '"';
|
||||
}
|
||||
$annotations[] = '@' . $this->_annotationsPrefix . $constraintName . '(name="' . $name . '", columns={' . implode(', ', $columns) . '})';
|
||||
}
|
||||
return implode(', ', $annotations);
|
||||
}
|
||||
|
||||
private function _generateInheritanceAnnotation($metadata)
|
||||
{
|
||||
if ($metadata->inheritanceType != ClassMetadataInfo::INHERITANCE_TYPE_NONE) {
|
||||
@@ -1088,4 +1113,4 @@ public function <methodName>()
|
||||
throw new \InvalidArgumentException('Invalid provided IdGeneratorType: ' . $type);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
80
lib/Doctrine/ORM/Tools/Pagination/CountWalker.php
Normal file
80
lib/Doctrine/ORM/Tools/Pagination/CountWalker.php
Normal file
@@ -0,0 +1,80 @@
|
||||
<?php
|
||||
/**
|
||||
* Doctrine ORM
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to kontakt@beberlei.de so I can send you a copy immediately.
|
||||
*/
|
||||
|
||||
namespace Doctrine\ORM\Tools\Pagination;
|
||||
|
||||
use Doctrine\ORM\Query\TreeWalkerAdapter,
|
||||
Doctrine\ORM\Query\AST\SelectStatement,
|
||||
Doctrine\ORM\Query\AST\SelectExpression,
|
||||
Doctrine\ORM\Query\AST\PathExpression,
|
||||
Doctrine\ORM\Query\AST\AggregateExpression;
|
||||
|
||||
/**
|
||||
* Replaces the selectClause of the AST with a COUNT statement
|
||||
*
|
||||
* @category DoctrineExtensions
|
||||
* @package DoctrineExtensions\Paginate
|
||||
* @author David Abdemoulaie <dave@hobodave.com>
|
||||
* @copyright Copyright (c) 2010 David Abdemoulaie (http://hobodave.com/)
|
||||
* @license http://hobodave.com/license.txt New BSD License
|
||||
*/
|
||||
class CountWalker extends TreeWalkerAdapter
|
||||
{
|
||||
/**
|
||||
* Distinct mode hint name
|
||||
*/
|
||||
const HINT_DISTINCT = 'doctrine_paginator.distinct';
|
||||
|
||||
/**
|
||||
* Walks down a SelectStatement AST node, modifying it to retrieve a COUNT
|
||||
*
|
||||
* @param SelectStatement $AST
|
||||
* @return void
|
||||
*/
|
||||
public function walkSelectStatement(SelectStatement $AST)
|
||||
{
|
||||
$rootComponents = array();
|
||||
foreach ($this->_getQueryComponents() AS $dqlAlias => $qComp) {
|
||||
$isParent = array_key_exists('parent', $qComp)
|
||||
&& $qComp['parent'] === null
|
||||
&& $qComp['nestingLevel'] == 0
|
||||
;
|
||||
if ($isParent) {
|
||||
$rootComponents[] = array($dqlAlias => $qComp);
|
||||
}
|
||||
}
|
||||
if (count($rootComponents) > 1) {
|
||||
throw new \RuntimeException("Cannot count query which selects two FROM components, cannot make distinction");
|
||||
}
|
||||
$root = reset($rootComponents);
|
||||
$parentName = key($root);
|
||||
$parent = current($root);
|
||||
|
||||
$pathExpression = new PathExpression(
|
||||
PathExpression::TYPE_STATE_FIELD | PathExpression::TYPE_SINGLE_VALUED_ASSOCIATION, $parentName,
|
||||
$parent['metadata']->getSingleIdentifierFieldName()
|
||||
);
|
||||
$pathExpression->type = PathExpression::TYPE_STATE_FIELD;
|
||||
|
||||
$distinct = $this->_getQuery()->getHint(self::HINT_DISTINCT);
|
||||
$AST->selectClause->selectExpressions = array(
|
||||
new SelectExpression(
|
||||
new AggregateExpression('count', $pathExpression, $distinct), null
|
||||
)
|
||||
);
|
||||
|
||||
// ORDER BY is not needed, only increases query execution through unnecessary sorting.
|
||||
$AST->orderByClause = null;
|
||||
}
|
||||
}
|
||||
|
||||
115
lib/Doctrine/ORM/Tools/Pagination/LimitSubqueryWalker.php
Normal file
115
lib/Doctrine/ORM/Tools/Pagination/LimitSubqueryWalker.php
Normal file
@@ -0,0 +1,115 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Doctrine ORM
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE. This license can also be viewed
|
||||
* at http://hobodave.com/license.txt
|
||||
*
|
||||
* @category DoctrineExtensions
|
||||
* @package DoctrineExtensions\Paginate
|
||||
* @author David Abdemoulaie <dave@hobodave.com>
|
||||
* @copyright Copyright (c) 2010 David Abdemoulaie (http://hobodave.com/)
|
||||
* @license http://hobodave.com/license.txt New BSD License
|
||||
*/
|
||||
|
||||
namespace Doctrine\ORM\Tools\Pagination;
|
||||
|
||||
use Doctrine\DBAL\Types\Type,
|
||||
Doctrine\ORM\Query\TreeWalkerAdapter,
|
||||
Doctrine\ORM\Query\AST\SelectStatement,
|
||||
Doctrine\ORM\Query\AST\SelectExpression,
|
||||
Doctrine\ORM\Query\AST\PathExpression,
|
||||
Doctrine\ORM\Query\AST\AggregateExpression;
|
||||
|
||||
/**
|
||||
* Replaces the selectClause of the AST with a SELECT DISTINCT root.id equivalent
|
||||
*
|
||||
* @category DoctrineExtensions
|
||||
* @package DoctrineExtensions\Paginate
|
||||
* @author David Abdemoulaie <dave@hobodave.com>
|
||||
* @copyright Copyright (c) 2010 David Abdemoulaie (http://hobodave.com/)
|
||||
* @license http://hobodave.com/license.txt New BSD License
|
||||
*/
|
||||
class LimitSubqueryWalker extends TreeWalkerAdapter
|
||||
{
|
||||
/**
|
||||
* ID type hint
|
||||
*/
|
||||
const IDENTIFIER_TYPE = 'doctrine_paginator.id.type';
|
||||
|
||||
/**
|
||||
* @var int Counter for generating unique order column aliases
|
||||
*/
|
||||
private $_aliasCounter = 0;
|
||||
|
||||
/**
|
||||
* Walks down a SelectStatement AST node, modifying it to retrieve DISTINCT ids
|
||||
* of the root Entity
|
||||
*
|
||||
* @param SelectStatement $AST
|
||||
* @return void
|
||||
*/
|
||||
public function walkSelectStatement(SelectStatement $AST)
|
||||
{
|
||||
$parent = null;
|
||||
$parentName = null;
|
||||
$selectExpressions = array();
|
||||
|
||||
foreach ($this->_getQueryComponents() AS $dqlAlias => $qComp) {
|
||||
// preserve mixed data in query for ordering
|
||||
if (isset($qComp['resultVariable'])) {
|
||||
$selectExpressions[] = new SelectExpression($qComp['resultVariable'], $dqlAlias);
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($qComp['parent'] === null && $qComp['nestingLevel'] == 0) {
|
||||
$parent = $qComp;
|
||||
$parentName = $dqlAlias;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
$identifier = $parent['metadata']->getSingleIdentifierFieldName();
|
||||
$this->_getQuery()->setHint(
|
||||
self::IDENTIFIER_TYPE,
|
||||
Type::getType($parent['metadata']->getTypeOfField($identifier))
|
||||
);
|
||||
|
||||
$pathExpression = new PathExpression(
|
||||
PathExpression::TYPE_STATE_FIELD | PathExpression::TYPE_SINGLE_VALUED_ASSOCIATION,
|
||||
$parentName,
|
||||
$identifier
|
||||
);
|
||||
$pathExpression->type = PathExpression::TYPE_STATE_FIELD;
|
||||
|
||||
array_unshift($selectExpressions, new SelectExpression($pathExpression, '_dctrn_id'));
|
||||
$AST->selectClause->selectExpressions = $selectExpressions;
|
||||
|
||||
if (isset($AST->orderByClause)) {
|
||||
foreach ($AST->orderByClause->orderByItems as $item) {
|
||||
if ($item->expression instanceof PathExpression) {
|
||||
$pathExpression = new PathExpression(
|
||||
PathExpression::TYPE_STATE_FIELD | PathExpression::TYPE_SINGLE_VALUED_ASSOCIATION,
|
||||
$item->expression->identificationVariable,
|
||||
$item->expression->field
|
||||
);
|
||||
$pathExpression->type = PathExpression::TYPE_STATE_FIELD;
|
||||
$AST->selectClause->selectExpressions[] = new SelectExpression(
|
||||
$pathExpression,
|
||||
'_dctrn_ord' . $this->_aliasCounter++
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$AST->selectClause->isDistinct = true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
180
lib/Doctrine/ORM/Tools/Pagination/Paginator.php
Normal file
180
lib/Doctrine/ORM/Tools/Pagination/Paginator.php
Normal file
@@ -0,0 +1,180 @@
|
||||
<?php
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the LGPL. For more information, see
|
||||
* <http://www.doctrine-project.org>.
|
||||
*/
|
||||
|
||||
namespace Doctrine\ORM\Tools\Pagination;
|
||||
|
||||
use Doctrine\ORM\QueryBuilder;
|
||||
use Doctrine\ORM\Query;
|
||||
use Doctrine\ORM\NoResultException;
|
||||
use Doctrine\ORM\Tools\Pagination\WhereInWalker;
|
||||
use Doctrine\ORM\Tools\Pagination\CountWalker;
|
||||
use Countable;
|
||||
use IteratorAggregate;
|
||||
use ArrayIterator;
|
||||
|
||||
/**
|
||||
* Paginator
|
||||
*
|
||||
* The paginator can handle various complex scenarios with DQL.
|
||||
*
|
||||
* @author Pablo Díez <pablodip@gmail.com>
|
||||
* @author Benjamin Eberlei <kontakt@beberlei.de>
|
||||
* @license New BSD
|
||||
*/
|
||||
class Paginator implements \Countable, \IteratorAggregate
|
||||
{
|
||||
/**
|
||||
* @var Query
|
||||
*/
|
||||
private $query;
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
private $fetchJoinCollection;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
private $count;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param Query|QueryBuilder $query A Doctrine ORM query or query builder.
|
||||
* @param Boolean $fetchJoinCollection Whether the query joins a collection (true by default).
|
||||
*/
|
||||
public function __construct($query, $fetchJoinCollection = true)
|
||||
{
|
||||
if ($query instanceof QueryBuilder) {
|
||||
$query = $query->getQuery();
|
||||
}
|
||||
|
||||
$this->query = $query;
|
||||
$this->fetchJoinCollection = (Boolean) $fetchJoinCollection;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the query
|
||||
*
|
||||
* @return Query
|
||||
*/
|
||||
public function getQuery()
|
||||
{
|
||||
return $this->query;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether the query joins a collection.
|
||||
*
|
||||
* @return Boolean Whether the query joins a collection.
|
||||
*/
|
||||
public function getFetchJoinCollection()
|
||||
{
|
||||
return $this->fetchJoinCollection;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function count()
|
||||
{
|
||||
if ($this->count === null) {
|
||||
/* @var $countQuery Query */
|
||||
$countQuery = $this->cloneQuery($this->query);
|
||||
|
||||
if ( ! $countQuery->getHint(CountWalker::HINT_DISTINCT)) {
|
||||
$countQuery->setHint(CountWalker::HINT_DISTINCT, true);
|
||||
}
|
||||
|
||||
$countQuery->setHint(Query::HINT_CUSTOM_TREE_WALKERS, array('Doctrine\ORM\Tools\Pagination\CountWalker'));
|
||||
$countQuery->setFirstResult(null)->setMaxResults(null);
|
||||
|
||||
try {
|
||||
$data = $countQuery->getScalarResult();
|
||||
$data = array_map('current', $data);
|
||||
$this->count = array_sum($data);
|
||||
} catch(NoResultException $e) {
|
||||
$this->count = 0;
|
||||
}
|
||||
}
|
||||
return $this->count;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getIterator()
|
||||
{
|
||||
$offset = $this->query->getFirstResult();
|
||||
$length = $this->query->getMaxResults();
|
||||
|
||||
if ($this->fetchJoinCollection) {
|
||||
$subQuery = $this->cloneQuery($this->query);
|
||||
$subQuery->setHint(Query::HINT_CUSTOM_TREE_WALKERS, array('Doctrine\ORM\Tools\Pagination\LimitSubqueryWalker'))
|
||||
->setFirstResult($offset)
|
||||
->setMaxResults($length);
|
||||
|
||||
$ids = array_map('current', $subQuery->getScalarResult());
|
||||
|
||||
$whereInQuery = $this->cloneQuery($this->query);
|
||||
// don't do this for an empty id array
|
||||
if (count($ids) > 0) {
|
||||
$namespace = WhereInWalker::PAGINATOR_ID_ALIAS;
|
||||
|
||||
$whereInQuery->setHint(Query::HINT_CUSTOM_TREE_WALKERS, array('Doctrine\ORM\Tools\Pagination\WhereInWalker'));
|
||||
$whereInQuery->setHint(WhereInWalker::HINT_PAGINATOR_ID_COUNT, count($ids));
|
||||
$whereInQuery->setFirstResult(null)->setMaxResults(null);
|
||||
foreach ($ids as $i => $id) {
|
||||
$i++;
|
||||
$whereInQuery->setParameter("{$namespace}_{$i}", $id);
|
||||
}
|
||||
}
|
||||
|
||||
$result = $whereInQuery->getResult($this->query->getHydrationMode());
|
||||
} else {
|
||||
$result = $this->cloneQuery($this->query)
|
||||
->setMaxResults($length)
|
||||
->setFirstResult($offset)
|
||||
->getResult($this->query->getHydrationMode())
|
||||
;
|
||||
}
|
||||
return new \ArrayIterator($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clones a query.
|
||||
*
|
||||
* @param Query $query The query.
|
||||
*
|
||||
* @return Query The cloned query.
|
||||
*/
|
||||
private function cloneQuery(Query $query)
|
||||
{
|
||||
/* @var $cloneQuery Query */
|
||||
$cloneQuery = clone $query;
|
||||
$cloneQuery->setParameters($query->getParameters());
|
||||
foreach ($query->getHints() as $name => $value) {
|
||||
$cloneQuery->setHint($name, $value);
|
||||
}
|
||||
|
||||
return $cloneQuery;
|
||||
}
|
||||
}
|
||||
|
||||
142
lib/Doctrine/ORM/Tools/Pagination/WhereInWalker.php
Normal file
142
lib/Doctrine/ORM/Tools/Pagination/WhereInWalker.php
Normal file
@@ -0,0 +1,142 @@
|
||||
<?php
|
||||
/**
|
||||
* Doctrine ORM
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE. This license can also be viewed
|
||||
* at http://hobodave.com/license.txt
|
||||
*
|
||||
* @category DoctrineExtensions
|
||||
* @package DoctrineExtensions\Paginate
|
||||
* @author David Abdemoulaie <dave@hobodave.com>
|
||||
* @copyright Copyright (c) 2010 David Abdemoulaie (http://hobodave.com/)
|
||||
* @license http://hobodave.com/license.txt New BSD License
|
||||
*/
|
||||
|
||||
namespace Doctrine\ORM\Tools\Pagination;
|
||||
|
||||
use Doctrine\ORM\Query\AST\ArithmeticExpression,
|
||||
Doctrine\ORM\Query\AST\SimpleArithmeticExpression,
|
||||
Doctrine\ORM\Query\TreeWalkerAdapter,
|
||||
Doctrine\ORM\Query\AST\SelectStatement,
|
||||
Doctrine\ORM\Query\AST\PathExpression,
|
||||
Doctrine\ORM\Query\AST\InExpression,
|
||||
Doctrine\ORM\Query\AST\NullComparisonExpression,
|
||||
Doctrine\ORM\Query\AST\InputParameter,
|
||||
Doctrine\ORM\Query\AST\ConditionalPrimary,
|
||||
Doctrine\ORM\Query\AST\ConditionalTerm,
|
||||
Doctrine\ORM\Query\AST\ConditionalExpression,
|
||||
Doctrine\ORM\Query\AST\ConditionalFactor,
|
||||
Doctrine\ORM\Query\AST\WhereClause;
|
||||
|
||||
/**
|
||||
* Replaces the whereClause of the AST with a WHERE id IN (:foo_1, :foo_2) equivalent
|
||||
*
|
||||
* @category DoctrineExtensions
|
||||
* @package DoctrineExtensions\Paginate
|
||||
* @author David Abdemoulaie <dave@hobodave.com>
|
||||
* @copyright Copyright (c) 2010 David Abdemoulaie (http://hobodave.com/)
|
||||
* @license http://hobodave.com/license.txt New BSD License
|
||||
*/
|
||||
class WhereInWalker extends TreeWalkerAdapter
|
||||
{
|
||||
/**
|
||||
* ID Count hint name
|
||||
*/
|
||||
const HINT_PAGINATOR_ID_COUNT = 'doctrine.id.count';
|
||||
|
||||
/**
|
||||
* Primary key alias for query
|
||||
*/
|
||||
const PAGINATOR_ID_ALIAS = 'dpid';
|
||||
|
||||
/**
|
||||
* Replaces the whereClause in the AST
|
||||
*
|
||||
* Generates a clause equivalent to WHERE IN (:dpid_1, :dpid_2, ...)
|
||||
*
|
||||
* The parameter namespace (dpid) is defined by
|
||||
* the PAGINATOR_ID_ALIAS
|
||||
*
|
||||
* The total number of parameters is retrieved from
|
||||
* the HINT_PAGINATOR_ID_COUNT query hint
|
||||
*
|
||||
* @param SelectStatement $AST
|
||||
* @return void
|
||||
*/
|
||||
public function walkSelectStatement(SelectStatement $AST)
|
||||
{
|
||||
$rootComponents = array();
|
||||
foreach ($this->_getQueryComponents() AS $dqlAlias => $qComp) {
|
||||
$isParent = array_key_exists('parent', $qComp)
|
||||
&& $qComp['parent'] === null
|
||||
&& $qComp['nestingLevel'] == 0
|
||||
;
|
||||
if ($isParent) {
|
||||
$rootComponents[] = array($dqlAlias => $qComp);
|
||||
}
|
||||
}
|
||||
if (count($rootComponents) > 1) {
|
||||
throw new \RuntimeException("Cannot count query which selects two FROM components, cannot make distinction");
|
||||
}
|
||||
$root = reset($rootComponents);
|
||||
$parentName = key($root);
|
||||
$parent = current($root);
|
||||
|
||||
$pathExpression = new PathExpression(
|
||||
PathExpression::TYPE_STATE_FIELD, $parentName, $parent['metadata']->getSingleIdentifierFieldName()
|
||||
);
|
||||
$pathExpression->type = PathExpression::TYPE_STATE_FIELD;
|
||||
|
||||
$count = $this->_getQuery()->getHint(self::HINT_PAGINATOR_ID_COUNT);
|
||||
|
||||
if ($count > 0) {
|
||||
$arithmeticExpression = new ArithmeticExpression();
|
||||
$arithmeticExpression->simpleArithmeticExpression = new SimpleArithmeticExpression(
|
||||
array($pathExpression)
|
||||
);
|
||||
$expression = new InExpression($arithmeticExpression);
|
||||
$ns = self::PAGINATOR_ID_ALIAS;
|
||||
|
||||
for ($i = 1; $i <= $count; $i++) {
|
||||
$expression->literals[] = new InputParameter(":{$ns}_$i");
|
||||
}
|
||||
} else {
|
||||
$expression = new NullComparisonExpression($pathExpression);
|
||||
$expression->not = false;
|
||||
}
|
||||
|
||||
$conditionalPrimary = new ConditionalPrimary;
|
||||
$conditionalPrimary->simpleConditionalExpression = $expression;
|
||||
if ($AST->whereClause) {
|
||||
if ($AST->whereClause->conditionalExpression instanceof ConditionalTerm) {
|
||||
$AST->whereClause->conditionalExpression->conditionalFactors[] = $conditionalPrimary;
|
||||
} elseif ($AST->whereClause->conditionalExpression instanceof ConditionalPrimary) {
|
||||
$AST->whereClause->conditionalExpression = new ConditionalExpression(array(
|
||||
new ConditionalTerm(array(
|
||||
$AST->whereClause->conditionalExpression,
|
||||
$conditionalPrimary
|
||||
))
|
||||
));
|
||||
} elseif ($AST->whereClause->conditionalExpression instanceof ConditionalExpression) {
|
||||
$tmpPrimary = new ConditionalPrimary;
|
||||
$tmpPrimary->conditionalExpression = $AST->whereClause->conditionalExpression;
|
||||
$AST->whereClause->conditionalExpression = new ConditionalTerm(array(
|
||||
$tmpPrimary,
|
||||
$conditionalPrimary
|
||||
));
|
||||
}
|
||||
} else {
|
||||
$AST->whereClause = new WhereClause(
|
||||
new ConditionalExpression(array(
|
||||
new ConditionalTerm(array(
|
||||
$conditionalPrimary
|
||||
))
|
||||
))
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,6 +21,8 @@ namespace Doctrine\ORM\Tools;
|
||||
|
||||
use Doctrine\ORM\ORMException,
|
||||
Doctrine\DBAL\Types\Type,
|
||||
Doctrine\DBAL\Schema\Schema,
|
||||
Doctrine\DBAL\Schema\Visitor\RemoveNamespacedAssets,
|
||||
Doctrine\ORM\EntityManager,
|
||||
Doctrine\ORM\Mapping\ClassMetadata,
|
||||
Doctrine\ORM\Internal\CommitOrderCalculator,
|
||||
@@ -127,7 +129,7 @@ class SchemaTool
|
||||
$sm = $this->_em->getConnection()->getSchemaManager();
|
||||
$metadataSchemaConfig = $sm->createSchemaConfig();
|
||||
$metadataSchemaConfig->setExplicitForeignKeyIndexes(false);
|
||||
$schema = new \Doctrine\DBAL\Schema\Schema(array(), array(), $metadataSchemaConfig);
|
||||
$schema = new Schema(array(), array(), $metadataSchemaConfig);
|
||||
|
||||
$evm = $this->_em->getEventManager();
|
||||
|
||||
@@ -223,13 +225,13 @@ class SchemaTool
|
||||
|
||||
if (isset($class->table['indexes'])) {
|
||||
foreach ($class->table['indexes'] AS $indexName => $indexData) {
|
||||
$table->addIndex($indexData['columns'], $indexName);
|
||||
$table->addIndex($indexData['columns'], is_numeric($indexName) ? null : $indexName);
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($class->table['uniqueConstraints'])) {
|
||||
foreach ($class->table['uniqueConstraints'] AS $indexName => $indexData) {
|
||||
$table->addUniqueIndex($indexData['columns'], $indexName);
|
||||
$table->addUniqueIndex($indexData['columns'], is_numeric($indexName) ? null : $indexName);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -252,6 +254,10 @@ class SchemaTool
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! $this->_platform->supportsSchemas() && ! $this->_platform->canEmulateSchemas() ) {
|
||||
$schema->visit(new RemoveNamespacedAssets());
|
||||
}
|
||||
|
||||
if ($evm->hasListeners(ToolEvents::postGenerateSchema)) {
|
||||
$evm->dispatchEvent(ToolEvents::postGenerateSchema, new GenerateSchemaEventArgs($this->_em, $schema));
|
||||
}
|
||||
@@ -360,6 +366,10 @@ class SchemaTool
|
||||
$options['columnDefinition'] = $mapping['columnDefinition'];
|
||||
}
|
||||
|
||||
if (isset($mapping['options'])) {
|
||||
$options['customSchemaOptions'] = $mapping['options'];
|
||||
}
|
||||
|
||||
if ($class->isIdGeneratorIdentity() && $class->getIdentifierFieldNames() == array($mapping['fieldName'])) {
|
||||
$options['autoincrement'] = true;
|
||||
}
|
||||
|
||||
@@ -95,8 +95,8 @@ class SchemaValidator
|
||||
}
|
||||
|
||||
foreach ($class->associationMappings AS $fieldName => $assoc) {
|
||||
if (!$cmf->hasMetadataFor($assoc['targetEntity'])) {
|
||||
$ce[] = "The target entity '" . $assoc['targetEntity'] . "' specified on " . $class->name . '#' . $fieldName . ' is unknown.';
|
||||
if (!class_exists($assoc['targetEntity']) || $cmf->isTransient($assoc['targetEntity'])) {
|
||||
$ce[] = "The target entity '" . $assoc['targetEntity'] . "' specified on " . $class->name . '#' . $fieldName . ' is unknown or not an entity.';
|
||||
return $ce;
|
||||
}
|
||||
|
||||
@@ -119,7 +119,7 @@ class SchemaValidator
|
||||
$ce[] = "The field " . $class->name . "#" . $fieldName . " is on the inverse side of a ".
|
||||
"bi-directional relationship, but the specified mappedBy association on the target-entity ".
|
||||
$assoc['targetEntity'] . "#" . $assoc['mappedBy'] . " does not contain the required ".
|
||||
"'inversedBy' attribute.";
|
||||
"'inversedBy=".$fieldName."' attribute.";
|
||||
} else if ($targetMetadata->associationMappings[$assoc['mappedBy']]['inversedBy'] != $fieldName) {
|
||||
$ce[] = "The mappings " . $class->name . "#" . $fieldName . " and " .
|
||||
$assoc['targetEntity'] . "#" . $assoc['mappedBy'] . " are ".
|
||||
@@ -162,30 +162,21 @@ class SchemaValidator
|
||||
|
||||
if ($assoc['isOwningSide']) {
|
||||
if ($assoc['type'] == ClassMetadataInfo::MANY_TO_MANY) {
|
||||
$identifierColumns = $class->getIdentifierColumnNames();
|
||||
foreach ($assoc['joinTable']['joinColumns'] AS $joinColumn) {
|
||||
if (!isset($class->fieldNames[$joinColumn['referencedColumnName']])) {
|
||||
$ce[] = "The referenced column name '" . $joinColumn['referencedColumnName'] . "' does not " .
|
||||
"have a corresponding field with this column name on the class '" . $class->name . "'.";
|
||||
break;
|
||||
}
|
||||
|
||||
$fieldName = $class->fieldNames[$joinColumn['referencedColumnName']];
|
||||
if (!in_array($fieldName, $class->identifier)) {
|
||||
if (!in_array($joinColumn['referencedColumnName'], $identifierColumns)) {
|
||||
$ce[] = "The referenced column name '" . $joinColumn['referencedColumnName'] . "' " .
|
||||
"has to be a primary key column.";
|
||||
"has to be a primary key column on the target entity class '".$class->name."'.";
|
||||
break;
|
||||
}
|
||||
}
|
||||
foreach ($assoc['joinTable']['inverseJoinColumns'] AS $inverseJoinColumn) {
|
||||
if (!isset($targetMetadata->fieldNames[$inverseJoinColumn['referencedColumnName']])) {
|
||||
$ce[] = "The inverse referenced column name '" . $inverseJoinColumn['referencedColumnName'] . "' does not " .
|
||||
"have a corresponding field with this column name on the class '" . $targetMetadata->name . "'.";
|
||||
break;
|
||||
}
|
||||
|
||||
$fieldName = $targetMetadata->fieldNames[$inverseJoinColumn['referencedColumnName']];
|
||||
if (!in_array($fieldName, $targetMetadata->identifier)) {
|
||||
$ce[] = "The referenced column name '" . $inverseJoinColumn['referencedColumnName'] . "' " .
|
||||
"has to be a primary key column.";
|
||||
$identifierColumns = $targetMetadata->getIdentifierColumnNames();
|
||||
foreach ($assoc['joinTable']['inverseJoinColumns'] AS $inverseJoinColumn) {
|
||||
if (!in_array($inverseJoinColumn['referencedColumnName'], $identifierColumns)) {
|
||||
$ce[] = "The referenced column name '" . $joinColumn['referencedColumnName'] . "' " .
|
||||
"has to be a primary key column on the target entity class '".$targetMetadata->name."'.";
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -204,29 +195,23 @@ class SchemaValidator
|
||||
}
|
||||
|
||||
} else if ($assoc['type'] & ClassMetadataInfo::TO_ONE) {
|
||||
$identifierColumns = $targetMetadata->getIdentifierColumnNames();
|
||||
foreach ($assoc['joinColumns'] AS $joinColumn) {
|
||||
if (!isset($targetMetadata->fieldNames[$joinColumn['referencedColumnName']])) {
|
||||
$ce[] = "The referenced column name '" . $joinColumn['referencedColumnName'] . "' does not " .
|
||||
"have a corresponding field with this column name on the class '" . $targetMetadata->name . "'.";
|
||||
break;
|
||||
}
|
||||
|
||||
$fieldName = $targetMetadata->fieldNames[$joinColumn['referencedColumnName']];
|
||||
if (!in_array($fieldName, $targetMetadata->identifier)) {
|
||||
if (!in_array($joinColumn['referencedColumnName'], $identifierColumns)) {
|
||||
$ce[] = "The referenced column name '" . $joinColumn['referencedColumnName'] . "' " .
|
||||
"has to be a primary key column.";
|
||||
"has to be a primary key column on the target entity class '".$targetMetadata->name."'.";
|
||||
}
|
||||
}
|
||||
|
||||
if (count($class->getIdentifierColumnNames()) != count($assoc['joinColumns'])) {
|
||||
if (count($identifierColumns) != count($assoc['joinColumns'])) {
|
||||
$ids = array();
|
||||
foreach ($assoc['joinColumns'] AS $joinColumn) {
|
||||
$ids[] = $joinColumn['name'];
|
||||
}
|
||||
|
||||
$ce[] = "The join columns of the association '" . $assoc['fieldName'] . "' " .
|
||||
"have to match to ALL identifier columns of the source entity '". $class->name . "', " .
|
||||
"however '" . implode(", ", array_diff($class->getIdentifierColumnNames(), $ids)) .
|
||||
"have to match to ALL identifier columns of the target entity '". $class->name . "', " .
|
||||
"however '" . implode(", ", array_diff($targetMetadata->getIdentifierColumnNames(), $ids)) .
|
||||
"' are missing.";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -390,7 +390,7 @@ class UnitOfWork implements PropertyChangedListener
|
||||
*/
|
||||
private function computeSingleEntityChangeSet($entity)
|
||||
{
|
||||
if ( ! $this->isInIdentityMap($entity) ) {
|
||||
if ( $this->getEntityState($entity) !== self::STATE_MANAGED) {
|
||||
throw new \InvalidArgumentException("Entity has to be managed for single computation " . self::objToStr($entity));
|
||||
}
|
||||
|
||||
@@ -707,6 +707,15 @@ class UnitOfWork implements PropertyChangedListener
|
||||
$state = $this->getEntityState($entry, self::STATE_NEW);
|
||||
$oid = spl_object_hash($entry);
|
||||
|
||||
if (!($entry instanceof $assoc['targetEntity'])) {
|
||||
throw new ORMException(sprintf("Found entity of type %s on association %s#%s, but expecting %s",
|
||||
get_class($entry),
|
||||
$assoc['sourceEntity'],
|
||||
$assoc['fieldName'],
|
||||
$targetClass->name
|
||||
));
|
||||
}
|
||||
|
||||
switch ($state) {
|
||||
case self::STATE_NEW:
|
||||
if ( ! $assoc['isCascadePersist']) {
|
||||
@@ -1676,6 +1685,10 @@ class UnitOfWork implements PropertyChangedListener
|
||||
$class->setIdentifierValues($managedCopy, $id);
|
||||
|
||||
$this->persistNew($class, $managedCopy);
|
||||
} else {
|
||||
if ($managedCopy instanceof Proxy && ! $managedCopy->__isInitialized__) {
|
||||
$managedCopy->__load();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -36,7 +36,7 @@ class Version
|
||||
/**
|
||||
* Current Doctrine Version
|
||||
*/
|
||||
const VERSION = '2.2.0-DEV';
|
||||
const VERSION = '2.2.0';
|
||||
|
||||
/**
|
||||
* Compares a Doctrine version with the current one.
|
||||
|
||||
2
lib/vendor/doctrine-common
vendored
2
lib/vendor/doctrine-common
vendored
Submodule lib/vendor/doctrine-common updated: 17e774007b...84838bb8c9
2
lib/vendor/doctrine-dbal
vendored
2
lib/vendor/doctrine-dbal
vendored
Submodule lib/vendor/doctrine-dbal updated: 3dc1b22e12...e01f7468d8
@@ -28,7 +28,7 @@ class CompanyPerson
|
||||
*/
|
||||
private $name;
|
||||
/**
|
||||
* @OneToOne(targetEntity="CompanyPerson", mappedBy="spouse")
|
||||
* @OneToOne(targetEntity="CompanyPerson")
|
||||
* @JoinColumn(name="spouse_id", referencedColumnName="id")
|
||||
*/
|
||||
private $spouse;
|
||||
|
||||
@@ -16,7 +16,7 @@ class DDC117Reference
|
||||
|
||||
/**
|
||||
* @Id
|
||||
* @ManyToOne(targetEntity="DDC117Article", inversedBy="references")
|
||||
* @ManyToOne(targetEntity="DDC117Article")
|
||||
* @JoinColumn(name="target_id", referencedColumnName="article_id")
|
||||
*/
|
||||
private $target;
|
||||
@@ -61,4 +61,4 @@ class DDC117Reference
|
||||
{
|
||||
return $this->description;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ class DDC117Translation
|
||||
{
|
||||
/**
|
||||
* @Id
|
||||
* @ManyToOne(targetEntity="DDC117Article")
|
||||
* @ManyToOne(targetEntity="DDC117Article", inversedBy="translations")
|
||||
* @JoinColumn(name="article_id", referencedColumnName="article_id")
|
||||
*/
|
||||
private $article;
|
||||
@@ -62,4 +62,4 @@ class DDC117Translation
|
||||
{
|
||||
return $this->reviewedByEditors;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ class LegacyUserReference
|
||||
|
||||
/**
|
||||
* @Id
|
||||
* @ManyToOne(targetEntity="LegacyUser", inversedBy="_references")
|
||||
* @ManyToOne(targetEntity="LegacyUser")
|
||||
* @JoinColumn(name="iUserIdTarget", referencedColumnName="iUserId")
|
||||
*/
|
||||
private $_target;
|
||||
|
||||
@@ -26,7 +26,7 @@ class NavPointOfInterest
|
||||
private $name;
|
||||
|
||||
/**
|
||||
* @ManyToOne(targetEntity="NavCountry")
|
||||
* @ManyToOne(targetEntity="NavCountry", inversedBy="pois")
|
||||
*/
|
||||
private $country;
|
||||
|
||||
@@ -53,4 +53,4 @@ class NavPointOfInterest
|
||||
public function getCountry() {
|
||||
return $this->country;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1141,6 +1141,21 @@ class BasicFunctionalTest extends \Doctrine\Tests\OrmFunctionalTestCase
|
||||
$this->_em->flush($user);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group DDC-720
|
||||
* @group DDC-1612
|
||||
*/
|
||||
public function testFlushSingleNewEntity()
|
||||
{
|
||||
$user = new CmsUser;
|
||||
$user->name = 'Dominik';
|
||||
$user->username = 'domnikl';
|
||||
$user->status = 'developer';
|
||||
|
||||
$this->_em->persist($user);
|
||||
$this->_em->flush($user);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group DDC-720
|
||||
*/
|
||||
@@ -1197,4 +1212,21 @@ class BasicFunctionalTest extends \Doctrine\Tests\OrmFunctionalTestCase
|
||||
$user2 = $this->_em->find(get_class($user2), $user2->id);
|
||||
$this->assertEquals('developer', $user2->status);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group DDC-1585
|
||||
*/
|
||||
public function testWrongAssocationInstance()
|
||||
{
|
||||
$user = new CmsUser;
|
||||
$user->name = 'Dominik';
|
||||
$user->username = 'domnikl';
|
||||
$user->status = 'developer';
|
||||
$user->address = $user;
|
||||
|
||||
$this->_em->persist($user);
|
||||
|
||||
$this->setExpectedException("Doctrine\ORM\ORMException", "Found entity of type Doctrine\Tests\Models\CMS\CmsUser on association Doctrine\Tests\Models\CMS\CmsUser#address, but expecting Doctrine\Tests\Models\CMS\CmsAddress");
|
||||
$this->_em->flush();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -64,7 +64,7 @@ class ExtraLazyCollectionTest extends \Doctrine\Tests\OrmFunctionalTestCase
|
||||
/**
|
||||
* @group DDC-546
|
||||
*/
|
||||
public function testCountWhenNewEntitysPresent()
|
||||
public function testCountWhenNewEntityPresent()
|
||||
{
|
||||
$user = $this->_em->find('Doctrine\Tests\Models\CMS\CmsUser', $this->userId);
|
||||
|
||||
@@ -223,13 +223,15 @@ class ExtraLazyCollectionTest extends \Doctrine\Tests\OrmFunctionalTestCase
|
||||
$user = $this->_em->find('Doctrine\Tests\Models\CMS\CmsUser', $this->userId);
|
||||
$this->assertFalse($user->articles->isInitialized(), "Pre-Condition: Collection is not initialized.");
|
||||
|
||||
$article = $this->_em->find('Doctrine\Tests\Models\CMS\CmsArticle', $this->articleId);
|
||||
|
||||
// Test One to Many existance retrieved from DB
|
||||
$article = $this->_em->find('Doctrine\Tests\Models\CMS\CmsArticle', $this->articleId);
|
||||
$queryCount = $this->getCurrentQueryCount();
|
||||
|
||||
$this->assertTrue($user->articles->contains($article));
|
||||
$this->assertFalse($user->articles->isInitialized(), "Post-Condition: Collection is not initialized.");
|
||||
$this->assertEquals($queryCount + 1, $this->getCurrentQueryCount());
|
||||
|
||||
// Test One to Many existance with state new
|
||||
$article = new \Doctrine\Tests\Models\CMS\CmsArticle();
|
||||
$article->topic = "Testnew";
|
||||
$article->text = "blub";
|
||||
@@ -238,12 +240,26 @@ class ExtraLazyCollectionTest extends \Doctrine\Tests\OrmFunctionalTestCase
|
||||
$this->assertFalse($user->articles->contains($article));
|
||||
$this->assertEquals($queryCount, $this->getCurrentQueryCount(), "Checking for contains of new entity should cause no query to be executed.");
|
||||
|
||||
// Test One to Many existance with state clear
|
||||
$this->_em->persist($article);
|
||||
$this->_em->flush();
|
||||
|
||||
$queryCount = $this->getCurrentQueryCount();
|
||||
$this->assertFalse($user->articles->contains($article));
|
||||
$this->assertEquals($queryCount+1, $this->getCurrentQueryCount(), "Checking for contains of managed entity should cause one query to be executed.");
|
||||
$this->assertEquals($queryCount+1, $this->getCurrentQueryCount(), "Checking for contains of persisted entity should cause one query to be executed.");
|
||||
$this->assertFalse($user->articles->isInitialized(), "Post-Condition: Collection is not initialized.");
|
||||
|
||||
// Test One to Many existance with state managed
|
||||
$article = new \Doctrine\Tests\Models\CMS\CmsArticle();
|
||||
$article->topic = "How to not fail anymore on tests";
|
||||
$article->text = "That is simple! Just write more tests!";
|
||||
|
||||
$this->_em->persist($article);
|
||||
|
||||
$queryCount = $this->getCurrentQueryCount();
|
||||
|
||||
$this->assertFalse($user->articles->contains($article));
|
||||
$this->assertEquals($queryCount, $this->getCurrentQueryCount(), "Checking for contains of managed entity (but not persisted) should cause no query to be executed.");
|
||||
$this->assertFalse($user->articles->isInitialized(), "Post-Condition: Collection is not initialized.");
|
||||
}
|
||||
|
||||
@@ -255,6 +271,7 @@ class ExtraLazyCollectionTest extends \Doctrine\Tests\OrmFunctionalTestCase
|
||||
$user = $this->_em->find('Doctrine\Tests\Models\CMS\CmsUser', $this->userId);
|
||||
$this->assertFalse($user->groups->isInitialized(), "Pre-Condition: Collection is not initialized.");
|
||||
|
||||
// Test Many to Many existance retrieved from DB
|
||||
$group = $this->_em->find('Doctrine\Tests\Models\CMS\CmsGroup', $this->groupId);
|
||||
$queryCount = $this->getCurrentQueryCount();
|
||||
|
||||
@@ -262,6 +279,7 @@ class ExtraLazyCollectionTest extends \Doctrine\Tests\OrmFunctionalTestCase
|
||||
$this->assertEquals($queryCount + 1, $this->getCurrentQueryCount(), "Checking for contains of managed entity should cause one query to be executed.");
|
||||
$this->assertFalse($user->groups->isInitialized(), "Post-Condition: Collection is not initialized.");
|
||||
|
||||
// Test Many to Many existance with state new
|
||||
$group = new \Doctrine\Tests\Models\CMS\CmsGroup();
|
||||
$group->name = "A New group!";
|
||||
|
||||
@@ -271,13 +289,26 @@ class ExtraLazyCollectionTest extends \Doctrine\Tests\OrmFunctionalTestCase
|
||||
$this->assertEquals($queryCount, $this->getCurrentQueryCount(), "Checking for contains of new entity should cause no query to be executed.");
|
||||
$this->assertFalse($user->groups->isInitialized(), "Post-Condition: Collection is not initialized.");
|
||||
|
||||
// Test Many to Many existance with state clear
|
||||
$this->_em->persist($group);
|
||||
$this->_em->flush();
|
||||
|
||||
$queryCount = $this->getCurrentQueryCount();
|
||||
|
||||
$this->assertFalse($user->groups->contains($group));
|
||||
$this->assertEquals($queryCount + 1, $this->getCurrentQueryCount(), "Checking for contains of managed entity should cause one query to be executed.");
|
||||
$this->assertEquals($queryCount + 1, $this->getCurrentQueryCount(), "Checking for contains of persisted entity should cause one query to be executed.");
|
||||
$this->assertFalse($user->groups->isInitialized(), "Post-Condition: Collection is not initialized.");
|
||||
|
||||
// Test Many to Many existance with state managed
|
||||
$group = new \Doctrine\Tests\Models\CMS\CmsGroup();
|
||||
$group->name = "My managed group";
|
||||
|
||||
$this->_em->persist($group);
|
||||
|
||||
$queryCount = $this->getCurrentQueryCount();
|
||||
|
||||
$this->assertFalse($user->groups->contains($group));
|
||||
$this->assertEquals($queryCount, $this->getCurrentQueryCount(), "Checking for contains of managed entity (but not persisted) should cause no query to be executed.");
|
||||
$this->assertFalse($user->groups->isInitialized(), "Post-Condition: Collection is not initialized.");
|
||||
}
|
||||
|
||||
@@ -313,6 +344,7 @@ class ExtraLazyCollectionTest extends \Doctrine\Tests\OrmFunctionalTestCase
|
||||
$user = $this->_em->find('Doctrine\Tests\Models\CMS\CmsUser', $this->userId);
|
||||
$this->assertFalse($user->articles->isInitialized(), "Pre-Condition: Collection is not initialized.");
|
||||
|
||||
// Test One to Many removal with Entity retrieved from DB
|
||||
$article = $this->_em->find('Doctrine\Tests\Models\CMS\CmsArticle', $this->articleId);
|
||||
$queryCount = $this->getCurrentQueryCount();
|
||||
|
||||
@@ -321,6 +353,7 @@ class ExtraLazyCollectionTest extends \Doctrine\Tests\OrmFunctionalTestCase
|
||||
$this->assertFalse($user->articles->isInitialized(), "Post-Condition: Collection is not initialized.");
|
||||
$this->assertEquals($queryCount + 1, $this->getCurrentQueryCount());
|
||||
|
||||
// Test One to Many removal with Entity state as new
|
||||
$article = new \Doctrine\Tests\Models\CMS\CmsArticle();
|
||||
$article->topic = "Testnew";
|
||||
$article->text = "blub";
|
||||
@@ -331,6 +364,7 @@ class ExtraLazyCollectionTest extends \Doctrine\Tests\OrmFunctionalTestCase
|
||||
|
||||
$this->assertEquals($queryCount, $this->getCurrentQueryCount(), "Removing a new entity should cause no query to be executed.");
|
||||
|
||||
// Test One to Many removal with Entity state as clean
|
||||
$this->_em->persist($article);
|
||||
$this->_em->flush();
|
||||
|
||||
@@ -338,8 +372,21 @@ class ExtraLazyCollectionTest extends \Doctrine\Tests\OrmFunctionalTestCase
|
||||
|
||||
$user->articles->removeElement($article);
|
||||
|
||||
$this->assertEquals($queryCount + 1, $this->getCurrentQueryCount(), "Removing a managed entity should cause one query to be executed.");
|
||||
$this->assertEquals($queryCount + 1, $this->getCurrentQueryCount(), "Removing a persisted entity should cause one query to be executed.");
|
||||
$this->assertFalse($user->articles->isInitialized(), "Post-Condition: Collection is not initialized.");
|
||||
|
||||
// Test One to Many removal with Entity state as managed
|
||||
$article = new \Doctrine\Tests\Models\CMS\CmsArticle();
|
||||
$article->topic = "How to not fail anymore on tests";
|
||||
$article->text = "That is simple! Just write more tests!";
|
||||
|
||||
$this->_em->persist($article);
|
||||
|
||||
$queryCount = $this->getCurrentQueryCount();
|
||||
|
||||
$user->articles->removeElement($article);
|
||||
|
||||
$this->assertEquals($queryCount, $this->getCurrentQueryCount(), "Removing a managed entity should cause no query to be executed.");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -350,14 +397,16 @@ class ExtraLazyCollectionTest extends \Doctrine\Tests\OrmFunctionalTestCase
|
||||
$user = $this->_em->find('Doctrine\Tests\Models\CMS\CmsUser', $this->userId);
|
||||
$this->assertFalse($user->groups->isInitialized(), "Pre-Condition: Collection is not initialized.");
|
||||
|
||||
// Test Many to Many removal with Entity retrieved from DB
|
||||
$group = $this->_em->find('Doctrine\Tests\Models\CMS\CmsGroup', $this->groupId);
|
||||
$queryCount = $this->getCurrentQueryCount();
|
||||
|
||||
$user->groups->removeElement($group);
|
||||
|
||||
$this->assertEquals($queryCount + 1, $this->getCurrentQueryCount(), "Removing a managed entity should cause one query to be executed.");
|
||||
$this->assertEquals($queryCount + 1, $this->getCurrentQueryCount(), "Removing a persisted entity should cause one query to be executed.");
|
||||
$this->assertFalse($user->groups->isInitialized(), "Post-Condition: Collection is not initialized.");
|
||||
|
||||
// Test Many to Many removal with Entity state as new
|
||||
$group = new \Doctrine\Tests\Models\CMS\CmsGroup();
|
||||
$group->name = "A New group!";
|
||||
|
||||
@@ -368,6 +417,7 @@ class ExtraLazyCollectionTest extends \Doctrine\Tests\OrmFunctionalTestCase
|
||||
$this->assertEquals($queryCount, $this->getCurrentQueryCount(), "Removing new entity should cause no query to be executed.");
|
||||
$this->assertFalse($user->groups->isInitialized(), "Post-Condition: Collection is not initialized.");
|
||||
|
||||
// Test Many to Many removal with Entity state as clean
|
||||
$this->_em->persist($group);
|
||||
$this->_em->flush();
|
||||
|
||||
@@ -375,7 +425,20 @@ class ExtraLazyCollectionTest extends \Doctrine\Tests\OrmFunctionalTestCase
|
||||
|
||||
$user->groups->removeElement($group);
|
||||
|
||||
$this->assertEquals($queryCount + 1, $this->getCurrentQueryCount(), "Removing a managed entity should cause one query to be executed.");
|
||||
$this->assertEquals($queryCount + 1, $this->getCurrentQueryCount(), "Removing a persisted entity should cause one query to be executed.");
|
||||
$this->assertFalse($user->groups->isInitialized(), "Post-Condition: Collection is not initialized.");
|
||||
|
||||
// Test Many to Many removal with Entity state as managed
|
||||
$group = new \Doctrine\Tests\Models\CMS\CmsGroup();
|
||||
$group->name = "A New group!";
|
||||
|
||||
$this->_em->persist($group);
|
||||
|
||||
$queryCount = $this->getCurrentQueryCount();
|
||||
|
||||
$user->groups->removeElement($group);
|
||||
|
||||
$this->assertEquals($queryCount, $this->getCurrentQueryCount(), "Removing a managed entity should cause no query to be executed.");
|
||||
$this->assertFalse($user->groups->isInitialized(), "Post-Condition: Collection is not initialized.");
|
||||
}
|
||||
|
||||
|
||||
@@ -127,14 +127,14 @@ class OneToOneEagerLoadingTest extends \Doctrine\Tests\OrmFunctionalTestCase
|
||||
$this->_em->clear();
|
||||
|
||||
$train = $this->_em->find(get_class($train), $train->id);
|
||||
$this->assertEquals(
|
||||
$this->assertSQLEquals(
|
||||
"SELECT t0.id AS id1, t0.driver_id AS driver_id2, t3.id AS id4, t3.name AS name5, t0.owner_id AS owner_id6, t7.id AS id8, t7.name AS name9 FROM Train t0 LEFT JOIN TrainDriver t3 ON t0.driver_id = t3.id INNER JOIN TrainOwner t7 ON t0.owner_id = t7.id WHERE t0.id = ?",
|
||||
$this->_sqlLoggerStack->queries[$this->_sqlLoggerStack->currentQuery]['sql']
|
||||
);
|
||||
|
||||
$this->_em->clear();
|
||||
$driver = $this->_em->find(get_class($driver), $driver->id);
|
||||
$this->assertEquals(
|
||||
$this->assertSQLEquals(
|
||||
"SELECT t0.id AS id1, t0.name AS name2, t3.id AS id4, t3.driver_id AS driver_id5, t3.owner_id AS owner_id6 FROM TrainOwner t0 LEFT JOIN Train t3 ON t3.owner_id = t0.id WHERE t0.id IN (?)",
|
||||
$this->_sqlLoggerStack->queries[$this->_sqlLoggerStack->currentQuery]['sql']
|
||||
);
|
||||
@@ -155,13 +155,13 @@ class OneToOneEagerLoadingTest extends \Doctrine\Tests\OrmFunctionalTestCase
|
||||
$waggon = $this->_em->find(get_class($waggon), $waggon->id);
|
||||
|
||||
// The last query is the eager loading of the owner of the train
|
||||
$this->assertEquals(
|
||||
$this->assertSQLEquals(
|
||||
"SELECT t0.id AS id1, t0.name AS name2, t3.id AS id4, t3.driver_id AS driver_id5, t3.owner_id AS owner_id6 FROM TrainOwner t0 LEFT JOIN Train t3 ON t3.owner_id = t0.id WHERE t0.id IN (?)",
|
||||
$this->_sqlLoggerStack->queries[$this->_sqlLoggerStack->currentQuery]['sql']
|
||||
);
|
||||
|
||||
// The one before is the fetching of the waggon and train
|
||||
$this->assertEquals(
|
||||
$this->assertSQLEquals(
|
||||
"SELECT t0.id AS id1, t0.train_id AS train_id2, t3.id AS id4, t3.driver_id AS driver_id5, t3.owner_id AS owner_id6 FROM Waggon t0 INNER JOIN Train t3 ON t0.train_id = t3.id WHERE t0.id = ?",
|
||||
$this->_sqlLoggerStack->queries[$this->_sqlLoggerStack->currentQuery - 1]['sql']
|
||||
);
|
||||
@@ -176,7 +176,7 @@ class OneToOneEagerLoadingTest extends \Doctrine\Tests\OrmFunctionalTestCase
|
||||
$this->_em->clear();
|
||||
|
||||
$waggon = $this->_em->find(get_class($owner), $owner->id);
|
||||
$this->assertEquals(
|
||||
$this->assertSQLEquals(
|
||||
"SELECT t0.id AS id1, t0.name AS name2, t3.id AS id4, t3.driver_id AS driver_id5, t3.owner_id AS owner_id6 FROM TrainOwner t0 LEFT JOIN Train t3 ON t3.owner_id = t0.id WHERE t0.id = ?",
|
||||
$this->_sqlLoggerStack->queries[$this->_sqlLoggerStack->currentQuery]['sql']
|
||||
);
|
||||
|
||||
105
tests/Doctrine/Tests/ORM/Functional/PaginationTest.php
Normal file
105
tests/Doctrine/Tests/ORM/Functional/PaginationTest.php
Normal file
@@ -0,0 +1,105 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Tests\ORM\Functional;
|
||||
|
||||
use Doctrine\ORM\Tools\SchemaTool;
|
||||
use Doctrine\ORM\Query;
|
||||
use Doctrine\Tests\Models\CMS\CmsUser;
|
||||
use Doctrine\Tests\Models\CMS\CmsPhonenumber;
|
||||
use Doctrine\Tests\Models\CMS\CmsAddress;
|
||||
use Doctrine\Tests\Models\CMS\CmsGroup;
|
||||
use Doctrine\Tests\Models\CMS\CmsArticle;
|
||||
use Doctrine\Tests\Models\CMS\CmsComment;
|
||||
use Doctrine\ORM\Tools\Pagination\Paginator;
|
||||
|
||||
/**
|
||||
* @group DDC-1613
|
||||
*/
|
||||
class PaginationTest extends \Doctrine\Tests\OrmFunctionalTestCase
|
||||
{
|
||||
protected function setUp()
|
||||
{
|
||||
$this->useModelSet('cms');
|
||||
parent::setUp();
|
||||
$this->populate();
|
||||
}
|
||||
|
||||
public function testCountSimpleWithoutJoin()
|
||||
{
|
||||
$dql = "SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u";
|
||||
$query = $this->_em->createQuery($dql);
|
||||
|
||||
$paginator = new Paginator($query);
|
||||
$this->assertEquals(3, count($paginator));
|
||||
}
|
||||
|
||||
public function testCountWithFetchJoin()
|
||||
{
|
||||
$dql = "SELECT u,g FROM Doctrine\Tests\Models\CMS\CmsUser u JOIN u.groups g";
|
||||
$query = $this->_em->createQuery($dql);
|
||||
|
||||
$paginator = new Paginator($query);
|
||||
$this->assertEquals(3, count($paginator));
|
||||
}
|
||||
|
||||
public function testIterateSimpleWithoutJoinFetchJoinHandlingOff()
|
||||
{
|
||||
$dql = "SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u";
|
||||
$query = $this->_em->createQuery($dql);
|
||||
|
||||
$paginator = new Paginator($query, false);
|
||||
|
||||
$data = array();
|
||||
foreach ($paginator as $user) {
|
||||
$data[] = $user;
|
||||
}
|
||||
$this->assertEquals(3, count($data));
|
||||
}
|
||||
|
||||
public function testIterateSimpleWithoutJoinFetchJoinHandlingOn()
|
||||
{
|
||||
$dql = "SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u";
|
||||
$query = $this->_em->createQuery($dql);
|
||||
|
||||
$paginator = new Paginator($query, true);
|
||||
|
||||
$data = array();
|
||||
foreach ($paginator as $user) {
|
||||
$data[] = $user;
|
||||
}
|
||||
$this->assertEquals(3, count($data));
|
||||
}
|
||||
|
||||
public function testIterateWithFetchJoin()
|
||||
{
|
||||
$dql = "SELECT u,g FROM Doctrine\Tests\Models\CMS\CmsUser u JOIN u.groups g";
|
||||
$query = $this->_em->createQuery($dql);
|
||||
|
||||
$paginator = new Paginator($query, true);
|
||||
|
||||
$data = array();
|
||||
foreach ($paginator as $user) {
|
||||
$data[] = $user;
|
||||
}
|
||||
$this->assertEquals(3, count($data));
|
||||
}
|
||||
|
||||
public function populate()
|
||||
{
|
||||
for ($i = 0; $i < 3; $i++) {
|
||||
$user = new CmsUser();
|
||||
$user->name = "Name$i";
|
||||
$user->username = "username$i";
|
||||
$user->status = "active";
|
||||
$this->_em->persist($user);
|
||||
|
||||
for ($j = 0; $j < 3; $j++) {;
|
||||
$group = new CmsGroup();
|
||||
$group->name = "group$j";
|
||||
$user->addGroup($group);
|
||||
$this->_em->persist($group);
|
||||
}
|
||||
}
|
||||
$this->_em->flush();
|
||||
}
|
||||
}
|
||||
@@ -195,4 +195,28 @@ class ReferenceProxyTest extends \Doctrine\Tests\OrmFunctionalTestCase
|
||||
$this->assertEquals('Doctrine Cookbook', $entity->getName());
|
||||
$this->assertTrue($entity->__isInitialized__, "Getting something other than the identifier initializes the proxy.");
|
||||
}
|
||||
|
||||
/**
|
||||
* @group DDC-1604
|
||||
*/
|
||||
public function testCommonPersistenceProxy()
|
||||
{
|
||||
$id = $this->createProduct();
|
||||
|
||||
/* @var $entity Doctrine\Tests\Models\ECommerce\ECommerceProduct */
|
||||
$entity = $this->_em->getReference('Doctrine\Tests\Models\ECommerce\ECommerceProduct' , $id);
|
||||
$className = \Doctrine\Common\Util\ClassUtils::getClass($entity);
|
||||
|
||||
$this->assertInstanceOf('Doctrine\Common\Persistence\Proxy', $entity);
|
||||
$this->assertFalse($entity->__isInitialized());
|
||||
$this->assertEquals('Doctrine\Tests\Models\ECommerce\ECommerceProduct', $className);
|
||||
|
||||
$restName = str_replace($this->_em->getConfiguration()->getProxyNamespace(), "", get_class($entity));
|
||||
$restName = substr(get_class($entity), strlen($this->_em->getConfiguration()->getProxyNamespace()) +1);
|
||||
$proxyFileName = $this->_em->getConfiguration()->getProxyDir() . DIRECTORY_SEPARATOR . str_replace("\\", "", $restName) . ".php";
|
||||
$this->assertTrue(file_exists($proxyFileName), "Proxy file name cannot be found generically.");
|
||||
|
||||
$entity->__load();
|
||||
$this->assertTrue($entity->__isInitialized());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,16 +27,14 @@ class MySqlSchemaToolTest extends \Doctrine\Tests\OrmFunctionalTestCase
|
||||
$tool = new SchemaTool($this->_em);
|
||||
$sql = $tool->getCreateSchemaSql($classes);
|
||||
$this->assertEquals("CREATE TABLE cms_addresses (id INT AUTO_INCREMENT NOT NULL, user_id INT DEFAULT NULL, country VARCHAR(50) NOT NULL, zip VARCHAR(50) NOT NULL, city VARCHAR(50) NOT NULL, UNIQUE INDEX UNIQ_ACAC157BA76ED395 (user_id), PRIMARY KEY(id)) ENGINE = InnoDB", $sql[0]);
|
||||
$this->assertEquals("CREATE TABLE cms_users (id INT AUTO_INCREMENT NOT NULL, email_id INT DEFAULT NULL, status VARCHAR(50) DEFAULT NULL, username VARCHAR(255) NOT NULL, name VARCHAR(255) NOT NULL, UNIQUE INDEX UNIQ_3AF03EC5F85E0677 (username), UNIQUE INDEX UNIQ_3AF03EC5A832C1C9 (email_id), PRIMARY KEY(id)) ENGINE = InnoDB", $sql[1]);
|
||||
$this->assertEquals("CREATE TABLE cms_users (id INT AUTO_INCREMENT NOT NULL, status VARCHAR(50) DEFAULT NULL, username VARCHAR(255) NOT NULL, name VARCHAR(255) NOT NULL, email_id INT DEFAULT NULL, UNIQUE INDEX UNIQ_3AF03EC5F85E0677 (username), UNIQUE INDEX UNIQ_3AF03EC5A832C1C9 (email_id), PRIMARY KEY(id)) ENGINE = InnoDB", $sql[1]);
|
||||
$this->assertEquals("CREATE TABLE cms_users_groups (user_id INT NOT NULL, group_id INT NOT NULL, INDEX IDX_7EA9409AA76ED395 (user_id), INDEX IDX_7EA9409AFE54D947 (group_id), PRIMARY KEY(user_id, group_id)) ENGINE = InnoDB", $sql[2]);
|
||||
$this->assertEquals("CREATE TABLE cms_phonenumbers (phonenumber VARCHAR(50) NOT NULL, user_id INT DEFAULT NULL, INDEX IDX_F21F790FA76ED395 (user_id), PRIMARY KEY(phonenumber)) ENGINE = InnoDB", $sql[3]);
|
||||
$this->assertEquals("ALTER TABLE cms_addresses ADD CONSTRAINT FK_ACAC157BA76ED395 FOREIGN KEY (user_id) REFERENCES cms_users (id)", $sql[4]);
|
||||
$this->assertEquals("ALTER TABLE cms_users ADD CONSTRAINT FK_3AF03EC5A832C1C9 FOREIGN KEY (email_id) REFERENCES cms_emails (id)", $sql[5]);
|
||||
$this->assertEquals("ALTER TABLE cms_users_groups ADD CONSTRAINT FK_7EA9409AA76ED395 FOREIGN KEY (user_id) REFERENCES cms_users (id)", $sql[6]);
|
||||
$this->assertEquals("ALTER TABLE cms_users_groups ADD CONSTRAINT FK_7EA9409AFE54D947 FOREIGN KEY (group_id) REFERENCES cms_groups (id)", $sql[7]);
|
||||
$this->assertEquals("ALTER TABLE cms_phonenumbers ADD CONSTRAINT FK_F21F790FA76ED395 FOREIGN KEY (user_id) REFERENCES cms_users (id)", $sql[8]);
|
||||
$this->assertEquals("ALTER TABLE cms_users_groups ADD CONSTRAINT FK_7EA9409AA76ED395 FOREIGN KEY (user_id) REFERENCES cms_users (id)", $sql[5]);
|
||||
$this->assertEquals("ALTER TABLE cms_phonenumbers ADD CONSTRAINT FK_F21F790FA76ED395 FOREIGN KEY (user_id) REFERENCES cms_users (id)", $sql[6]);
|
||||
|
||||
$this->assertEquals(9, count($sql));
|
||||
$this->assertEquals(7, count($sql));
|
||||
}
|
||||
|
||||
public function testGetCreateSchemaSql2()
|
||||
@@ -64,4 +62,31 @@ class MySqlSchemaToolTest extends \Doctrine\Tests\OrmFunctionalTestCase
|
||||
$this->assertEquals(1, count($sql));
|
||||
$this->assertEquals("CREATE TABLE boolean_model (id INT AUTO_INCREMENT NOT NULL, booleanField TINYINT(1) NOT NULL, PRIMARY KEY(id)) ENGINE = InnoDB", $sql[0]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group DBAL-204
|
||||
*/
|
||||
public function testGetCreateSchemaSql4()
|
||||
{
|
||||
$classes = array(
|
||||
$this->_em->getClassMetadata(__NAMESPACE__ . '\\MysqlSchemaNamespacedEntity')
|
||||
);
|
||||
|
||||
$tool = new SchemaTool($this->_em);
|
||||
$sql = $tool->getCreateSchemaSql($classes);
|
||||
|
||||
$this->assertEquals(0, count($sql));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @Entity
|
||||
* @Table("namespace.entity")
|
||||
*/
|
||||
class MysqlSchemaNamespacedEntity
|
||||
{
|
||||
/** @Column(type="integer") @Id @GeneratedValue */
|
||||
public $id;
|
||||
}
|
||||
|
||||
|
||||
50
tests/Doctrine/Tests/ORM/Functional/SchemaValidatorTest.php
Normal file
50
tests/Doctrine/Tests/ORM/Functional/SchemaValidatorTest.php
Normal file
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Tests\ORM\Functional;
|
||||
|
||||
use Doctrine\ORM\Tools\SchemaValidator;
|
||||
|
||||
/**
|
||||
* Test the validity of all modelsets
|
||||
*
|
||||
* @group DDC-1601
|
||||
*/
|
||||
class SchemaValidatorTest extends \Doctrine\Tests\OrmFunctionalTestCase
|
||||
{
|
||||
static public function dataValidateModelSets()
|
||||
{
|
||||
$modelSets = array();
|
||||
foreach (self::$_modelSets as $modelSet => $classes) {
|
||||
if ($modelSet == "customtype") {
|
||||
continue;
|
||||
}
|
||||
$modelSets[] = array($modelSet);
|
||||
}
|
||||
return $modelSets;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider dataValidateModelSets
|
||||
*/
|
||||
public function testValidateModelSets($modelSet)
|
||||
{
|
||||
$validator = new SchemaValidator($this->_em);
|
||||
|
||||
$classes = array();
|
||||
foreach (self::$_modelSets[$modelSet] as $className) {
|
||||
$classes[] = $this->_em->getClassMetadata($className);
|
||||
}
|
||||
|
||||
foreach ($classes as $class) {
|
||||
$ce = $validator->validateClass($class);
|
||||
|
||||
foreach ($ce as $key => $error) {
|
||||
if (strpos($error, "must be private or protected. Public fields may break lazy-loading.") !== false) {
|
||||
unset($ce[$key]);
|
||||
}
|
||||
}
|
||||
|
||||
$this->assertEquals(0, count($ce), "Invalid Modelset: " . $modelSet . " class " . $class->name . ": ". implode("\n", $ce));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -36,7 +36,7 @@ class DDC1430Test extends \Doctrine\Tests\OrmFunctionalTestCase
|
||||
->getQuery();
|
||||
|
||||
$this->assertEquals('SELECT o.id, o.date, COUNT(p.id) AS p_count FROM Doctrine\Tests\ORM\Functional\Ticket\DDC1430Order o LEFT JOIN o.products p GROUP BY o.id, o.date ORDER BY o.id ASC', $query->getDQL());
|
||||
$this->assertEquals('SELECT d0_.order_id AS order_id0, d0_.created_at AS created_at1, COUNT(d1_.id) AS sclr2 FROM DDC1430Order d0_ LEFT JOIN DDC1430OrderProduct d1_ ON d0_.order_id = d1_.order_id GROUP BY d0_.order_id, d0_.created_at ORDER BY d0_.order_id ASC', $query->getSQL());
|
||||
$this->assertSQLEquals('SELECT d0_.order_id AS order_id0, d0_.created_at AS created_at1, COUNT(d1_.id) AS sclr2 FROM DDC1430Order d0_ LEFT JOIN DDC1430OrderProduct d1_ ON d0_.order_id = d1_.order_id GROUP BY d0_.order_id, d0_.created_at ORDER BY d0_.order_id ASC', $query->getSQL());
|
||||
|
||||
|
||||
$result = $query->getResult();
|
||||
@@ -68,7 +68,7 @@ class DDC1430Test extends \Doctrine\Tests\OrmFunctionalTestCase
|
||||
|
||||
|
||||
$this->assertEquals('SELECT o, COUNT(p.id) AS p_count FROM Doctrine\Tests\ORM\Functional\Ticket\DDC1430Order o LEFT JOIN o.products p GROUP BY o.id, o.date, o.status ORDER BY o.id ASC', $query->getDQL());
|
||||
$this->assertEquals('SELECT d0_.order_id AS order_id0, d0_.created_at AS created_at1, d0_.order_status AS order_status2, COUNT(d1_.id) AS sclr3 FROM DDC1430Order d0_ LEFT JOIN DDC1430OrderProduct d1_ ON d0_.order_id = d1_.order_id GROUP BY d0_.order_id, d0_.created_at, d0_.order_status ORDER BY d0_.order_id ASC', $query->getSQL());
|
||||
$this->assertSQLEquals('SELECT d0_.order_id AS order_id0, d0_.created_at AS created_at1, d0_.order_status AS order_status2, COUNT(d1_.id) AS sclr3 FROM DDC1430Order d0_ LEFT JOIN DDC1430OrderProduct d1_ ON d0_.order_id = d1_.order_id GROUP BY d0_.order_id, d0_.created_at, d0_.order_status ORDER BY d0_.order_id ASC', $query->getSQL());
|
||||
|
||||
$result = $query->getResult();
|
||||
|
||||
@@ -97,7 +97,7 @@ class DDC1430Test extends \Doctrine\Tests\OrmFunctionalTestCase
|
||||
|
||||
|
||||
$this->assertEquals('SELECT o, COUNT(p.id) AS p_count FROM Doctrine\Tests\ORM\Functional\Ticket\DDC1430Order o LEFT JOIN o.products p GROUP BY o ORDER BY o.id ASC', $query->getDQL());
|
||||
$this->assertEquals('SELECT d0_.order_id AS order_id0, d0_.created_at AS created_at1, d0_.order_status AS order_status2, COUNT(d1_.id) AS sclr3 FROM DDC1430Order d0_ LEFT JOIN DDC1430OrderProduct d1_ ON d0_.order_id = d1_.order_id GROUP BY d0_.order_id, d0_.created_at, d0_.order_status ORDER BY d0_.order_id ASC', $query->getSQL());
|
||||
$this->assertSQLEquals('SELECT d0_.order_id AS order_id0, d0_.created_at AS created_at1, d0_.order_status AS order_status2, COUNT(d1_.id) AS sclr3 FROM DDC1430Order d0_ LEFT JOIN DDC1430OrderProduct d1_ ON d0_.order_id = d1_.order_id GROUP BY d0_.order_id, d0_.created_at, d0_.order_status ORDER BY d0_.order_id ASC', $query->getSQL());
|
||||
|
||||
|
||||
$result = $query->getResult();
|
||||
@@ -294,4 +294,4 @@ class DDC1430OrderProduct
|
||||
$this->value = $value;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -57,6 +57,8 @@ class DDC1514Test extends \Doctrine\Tests\OrmFunctionalTestCase
|
||||
$dql = "SELECT a, b, ba, c FROM " . __NAMESPACE__ . "\DDC1514EntityA AS a LEFT JOIN a.entitiesB AS b LEFT JOIN b.entityATo AS ba LEFT JOIN a.entityC AS c";
|
||||
$results = $this->_em->createQuery($dql)->getResult();
|
||||
|
||||
$this->assertInternalType('array', $results);
|
||||
$this->assertTrue(count($results) >= 1, "At least one result expected in array");
|
||||
$this->assertEquals($c->title, $results[1]->entityC->title);
|
||||
}
|
||||
}
|
||||
|
||||
67
tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1526Test.php
Normal file
67
tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1526Test.php
Normal file
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Tests\ORM\Functional\Ticket;
|
||||
|
||||
/**
|
||||
* @group DDC-1526
|
||||
*/
|
||||
class DDC1526Test extends \Doctrine\Tests\OrmFunctionalTestCase
|
||||
{
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
$this->_schemaTool->createSchema(array(
|
||||
$this->_em->getClassMetadata(__NAMESPACE__ . '\\DDC1526Menu'),
|
||||
));
|
||||
}
|
||||
|
||||
public function testIssue()
|
||||
{
|
||||
$parents = array();
|
||||
for ($i = 0; $i < 9; $i++) {
|
||||
$entity = new DDC1526Menu;
|
||||
|
||||
if (isset ($parents[($i % 3)])) {
|
||||
$entity->parent = $parents[($i%3)];
|
||||
}
|
||||
|
||||
$this->_em->persist($entity);
|
||||
$parents[$i] = $entity;
|
||||
}
|
||||
$this->_em->flush();
|
||||
$this->_em->clear();
|
||||
|
||||
|
||||
$dql = "SELECT m, c
|
||||
FROM " . __NAMESPACE__ . "\DDC1526Menu m
|
||||
LEFT JOIN m.children c";
|
||||
$menus = $this->_em->createQuery($dql)->getResult();
|
||||
|
||||
// All Children collection now have to be initiailzed
|
||||
foreach ($menus as $menu) {
|
||||
$this->assertTrue($menu->children->isInitialized());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @Entity
|
||||
*/
|
||||
class DDC1526Menu
|
||||
{
|
||||
/**
|
||||
* @Column(type="integer")
|
||||
* @Id
|
||||
* @GeneratedValue
|
||||
*/
|
||||
public $id;
|
||||
/**
|
||||
* @ManyToOne(targetEntity="DDC1526Menu", inversedBy="children")
|
||||
*/
|
||||
public $parent;
|
||||
|
||||
/**
|
||||
* @OneToMany(targetEntity="DDC1526Menu", mappedBy="parent")
|
||||
*/
|
||||
public $children;
|
||||
}
|
||||
45
tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1594Test.php
Normal file
45
tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1594Test.php
Normal file
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Tests\ORM\Functional\Ticket;
|
||||
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
|
||||
use Doctrine\Tests\Models\CMS\CmsComment;
|
||||
use Doctrine\Tests\Models\CMS\CmsArticle;
|
||||
use Doctrine\Tests\Models\CMS\CmsUser;
|
||||
|
||||
/**
|
||||
* @group DDC-1594
|
||||
*/
|
||||
class DDC1594Test extends \Doctrine\Tests\OrmFunctionalTestCase
|
||||
{
|
||||
public function setUp()
|
||||
{
|
||||
$this->useModelSet('cms');
|
||||
parent::setUp();
|
||||
}
|
||||
|
||||
public function testIssue()
|
||||
{
|
||||
$user = new CmsUser();
|
||||
$user->status = 'foo';
|
||||
$user->username = 'foo';
|
||||
$user->name = 'foo';
|
||||
|
||||
$this->_em->persist($user);
|
||||
$this->_em->flush();
|
||||
|
||||
$this->_em->clear();
|
||||
$detachedUser = clone $user;
|
||||
$detachedUser->name = 'bar';
|
||||
$detachedUser->status = 'bar';
|
||||
|
||||
$newUser = $this->_em->getReference(get_class($user), $user->id);
|
||||
|
||||
$mergedUser = $this->_em->merge($detachedUser);
|
||||
|
||||
$this->assertNotSame($mergedUser, $detachedUser);
|
||||
$this->assertEquals('bar', $detachedUser->getName());
|
||||
$this->assertEquals('bar', $mergedUser->getName());
|
||||
}
|
||||
}
|
||||
111
tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1595Test.php
Normal file
111
tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1595Test.php
Normal file
@@ -0,0 +1,111 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Tests\ORM\Functional\Ticket;
|
||||
|
||||
/**
|
||||
* @group DDC-1595
|
||||
* @group DDC-1596
|
||||
*/
|
||||
class DDC1595Test extends \Doctrine\Tests\OrmFunctionalTestCase
|
||||
{
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->_em->getConnection()->getConfiguration()->setSQLLogger(new \Doctrine\DBAL\Logging\DebugStack);
|
||||
|
||||
$this->_schemaTool->createSchema(array(
|
||||
$this->_em->getClassMetadata(__NAMESPACE__ . '\\DDC1595BaseInheritance'),
|
||||
$this->_em->getClassMetadata(__NAMESPACE__ . '\\DDC1595InheritedEntity1'),
|
||||
$this->_em->getClassMetadata(__NAMESPACE__ . '\\DDC1595InheritedEntity2'),
|
||||
));
|
||||
}
|
||||
|
||||
public function testIssue()
|
||||
{
|
||||
$e1 = new DDC1595InheritedEntity1();
|
||||
|
||||
$this->_em->persist($e1);
|
||||
$this->_em->flush();
|
||||
$this->_em->clear();
|
||||
|
||||
$sqlLogger = $this->_em->getConnection()->getConfiguration()->getSQLLogger();
|
||||
$repository = $this->_em->getRepository(__NAMESPACE__ . '\\DDC1595InheritedEntity1');
|
||||
|
||||
$entity1 = $repository->find($e1->id);
|
||||
|
||||
// DDC-1596
|
||||
$this->assertSQLEquals(
|
||||
"SELECT t0.id AS id1, t0.type FROM base t0 WHERE t0.id = ? AND t0.type IN ('Entity1')",
|
||||
$sqlLogger->queries[count($sqlLogger->queries)]['sql']
|
||||
);
|
||||
|
||||
$entities = $entity1->getEntities()->getValues();
|
||||
|
||||
$this->assertSQLEquals(
|
||||
"SELECT t0.id AS id1, t0.type FROM base t0 INNER JOIN entity1_entity2 ON t0.id = entity1_entity2.item WHERE entity1_entity2.parent = ? AND t0.type IN ('Entity2')",
|
||||
$sqlLogger->queries[count($sqlLogger->queries)]['sql']
|
||||
);
|
||||
|
||||
$this->_em->clear();
|
||||
|
||||
$entity1 = $repository->find($e1->id);
|
||||
$entities = $entity1->getEntities()->count();
|
||||
|
||||
$this->assertSQLEquals(
|
||||
"SELECT COUNT(*) FROM entity1_entity2 t WHERE parent = ?",
|
||||
$sqlLogger->queries[count($sqlLogger->queries)]['sql']
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @Entity
|
||||
* @Table(name="base")
|
||||
*
|
||||
* @InheritanceType("SINGLE_TABLE")
|
||||
* @DiscriminatorColumn(name="type", type="string")
|
||||
* @DiscriminatorMap({
|
||||
* "Entity1" = "DDC1595InheritedEntity1",
|
||||
* "Entity2" = "DDC1595InheritedEntity2"
|
||||
* })
|
||||
*/
|
||||
abstract class DDC1595BaseInheritance
|
||||
{
|
||||
/**
|
||||
* @Id @GeneratedValue
|
||||
* @Column(type="integer")
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
public $id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @Entity
|
||||
* @Table(name="entity1")
|
||||
*/
|
||||
class DDC1595InheritedEntity1 extends DDC1595BaseInheritance
|
||||
{
|
||||
/**
|
||||
* @ManyToMany(targetEntity="DDC1595InheritedEntity2", fetch="EXTRA_LAZY")
|
||||
* @JoinTable(name="entity1_entity2",
|
||||
* joinColumns={@JoinColumn(name="parent", referencedColumnName="id")},
|
||||
* inverseJoinColumns={@JoinColumn(name="item", referencedColumnName="id")}
|
||||
* )
|
||||
*/
|
||||
protected $entities;
|
||||
|
||||
public function getEntities()
|
||||
{
|
||||
return $this->entities;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @Entity
|
||||
* @Table(name="entity2")
|
||||
*/
|
||||
class DDC1595InheritedEntity2 extends DDC1595BaseInheritance
|
||||
{
|
||||
}
|
||||
118
tests/Doctrine/Tests/ORM/Functional/Ticket/DDC657Test.php
Normal file
118
tests/Doctrine/Tests/ORM/Functional/Ticket/DDC657Test.php
Normal file
@@ -0,0 +1,118 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Tests\ORM\Functional\Ticket;
|
||||
|
||||
require_once __DIR__ . '/../../../TestInit.php';
|
||||
|
||||
use Doctrine\Tests\Models\Generic\DateTimeModel;
|
||||
|
||||
/**
|
||||
* @group DDC-657
|
||||
*/
|
||||
class DDC657Test extends \Doctrine\Tests\OrmFunctionalTestCase
|
||||
{
|
||||
const NS = 'Doctrine\Tests\Models\Generic';
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
$this->useModelSet('generic');
|
||||
parent::setUp();
|
||||
|
||||
$this->loadFixtures();
|
||||
}
|
||||
|
||||
public function testEntitySingleResult()
|
||||
{
|
||||
$query = $this->_em->createQuery('SELECT d FROM ' . self::NS . '\DateTimeModel d');
|
||||
$datetime = $query->setMaxResults(1)->getSingleResult();
|
||||
|
||||
$this->assertTrue($datetime instanceof DateTimeModel);
|
||||
|
||||
$this->assertTrue($datetime->datetime instanceof \DateTime);
|
||||
$this->assertTrue($datetime->time instanceof \DateTime);
|
||||
$this->assertTrue($datetime->date instanceof \DateTime);
|
||||
}
|
||||
|
||||
public function testScalarResult()
|
||||
{
|
||||
$query = $this->_em->createQuery('SELECT d.id, d.time, d.date, d.datetime FROM ' . self::NS . '\DateTimeModel d ORDER BY d.date ASC');
|
||||
$result = $query->getScalarResult();
|
||||
|
||||
$this->assertCount(2,$result);
|
||||
|
||||
$this->assertContains('11:11:11', $result[0]['time']);
|
||||
$this->assertContains('2010-01-01', $result[0]['date']);
|
||||
$this->assertContains('2010-01-01 11:11:11', $result[0]['datetime']);
|
||||
|
||||
$this->assertContains('12:12:12', $result[1]['time']);
|
||||
$this->assertContains('2010-02-02', $result[1]['date']);
|
||||
$this->assertContains('2010-02-02 12:12:12', $result[1]['datetime']);
|
||||
}
|
||||
|
||||
public function testaTicketEntityArrayResult()
|
||||
{
|
||||
$query = $this->_em->createQuery('SELECT d FROM ' . self::NS . '\DateTimeModel d ORDER BY d.date ASC');
|
||||
$result = $query->getArrayResult();
|
||||
|
||||
$this->assertCount(2,$result);
|
||||
|
||||
$this->assertTrue($result[0]['datetime'] instanceof \DateTime);
|
||||
$this->assertTrue($result[0]['time'] instanceof \DateTime);
|
||||
$this->assertTrue($result[0]['date'] instanceof \DateTime);
|
||||
|
||||
$this->assertTrue($result[1]['datetime'] instanceof \DateTime);
|
||||
$this->assertTrue($result[1]['time'] instanceof \DateTime);
|
||||
$this->assertTrue($result[1]['date'] instanceof \DateTime);
|
||||
}
|
||||
|
||||
public function testTicketSingleResult()
|
||||
{
|
||||
$query = $this->_em->createQuery('SELECT d.id, d.time, d.date, d.datetime FROM ' . self::NS . '\DateTimeModel d ORDER BY d.date ASC');
|
||||
$datetime = $query->setMaxResults(1)->getSingleResult();
|
||||
|
||||
$this->assertTrue(is_array($datetime));
|
||||
|
||||
$this->assertTrue($datetime['datetime'] instanceof \DateTime);
|
||||
$this->assertTrue($datetime['time'] instanceof \DateTime);
|
||||
$this->assertTrue($datetime['date'] instanceof \DateTime);
|
||||
}
|
||||
|
||||
public function testTicketResult()
|
||||
{
|
||||
$query = $this->_em->createQuery('SELECT d.id, d.time, d.date, d.datetime FROM ' . self::NS . '\DateTimeModel d ORDER BY d.date ASC');
|
||||
$result = $query->getResult();
|
||||
|
||||
$this->assertCount(2,$result);
|
||||
|
||||
$this->assertTrue($result[0]['time'] instanceof \DateTime);
|
||||
$this->assertTrue($result[0]['date'] instanceof \DateTime);
|
||||
$this->assertTrue($result[0]['datetime'] instanceof \DateTime);
|
||||
$this->assertEquals('2010-01-01 11:11:11', $result[0]['datetime']->format('Y-m-d G:i:s'));
|
||||
|
||||
$this->assertTrue($result[1]['time'] instanceof \DateTime);
|
||||
$this->assertTrue($result[1]['date'] instanceof \DateTime);
|
||||
$this->assertTrue($result[1]['datetime'] instanceof \DateTime);
|
||||
$this->assertEquals('2010-02-02 12:12:12', $result[1]['datetime']->format('Y-m-d G:i:s'));
|
||||
}
|
||||
|
||||
public function loadFixtures()
|
||||
{
|
||||
$timezone = new \DateTimeZone('America/Sao_Paulo');
|
||||
|
||||
$dateTime1 = new DateTimeModel();
|
||||
$dateTime2 = new DateTimeModel();
|
||||
|
||||
$dateTime1->date = new \DateTime('2010-01-01', $timezone);
|
||||
$dateTime1->time = new \DateTime('2010-01-01 11:11:11', $timezone);
|
||||
$dateTime1->datetime= new \DateTime('2010-01-01 11:11:11', $timezone);
|
||||
|
||||
$dateTime2->date = new \DateTime('2010-02-02', $timezone);
|
||||
$dateTime2->time = new \DateTime('2010-02-02 12:12:12', $timezone);
|
||||
$dateTime2->datetime= new \DateTime('2010-02-02 12:12:12', $timezone);
|
||||
|
||||
$this->_em->persist($dateTime1);
|
||||
$this->_em->persist($dateTime2);
|
||||
|
||||
$this->_em->flush();
|
||||
}
|
||||
}
|
||||
@@ -8,6 +8,9 @@ require_once __DIR__ . '/../../../TestInit.php';
|
||||
|
||||
class DDC742Test extends \Doctrine\Tests\OrmFunctionalTestCase
|
||||
{
|
||||
private $userCm;
|
||||
private $commentCm;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
@@ -15,6 +18,7 @@ class DDC742Test extends \Doctrine\Tests\OrmFunctionalTestCase
|
||||
if (\extension_loaded('memcache')) {
|
||||
$memcache = new \Memcache();
|
||||
$memcache->addServer('localhost');
|
||||
$memcache->flush();
|
||||
|
||||
$cacheDriver = new \Doctrine\Common\Cache\MemcacheCache();
|
||||
$cacheDriver->setMemcache($memcache);
|
||||
@@ -123,4 +127,4 @@ class DDC742Comment
|
||||
* @var string
|
||||
*/
|
||||
public $content;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,6 +9,9 @@ require_once __DIR__ . '/../../TestInit.php';
|
||||
|
||||
class ClassMetadataLoadEventTest extends \Doctrine\Tests\OrmTestCase
|
||||
{
|
||||
/**
|
||||
* @group DDC-1610
|
||||
*/
|
||||
public function testEvent()
|
||||
{
|
||||
$em = $this->_getTestEntityManager();
|
||||
@@ -17,6 +20,8 @@ class ClassMetadataLoadEventTest extends \Doctrine\Tests\OrmTestCase
|
||||
$evm->addEventListener(Events::loadClassMetadata, $this);
|
||||
$classMetadata = $metadataFactory->getMetadataFor('Doctrine\Tests\ORM\Mapping\LoadEventTestEntity');
|
||||
$this->assertTrue($classMetadata->hasField('about'));
|
||||
$this->assertArrayHasKey('about', $classMetadata->reflFields);
|
||||
$this->assertInstanceOf('ReflectionProperty', $classMetadata->reflFields['about']);
|
||||
}
|
||||
|
||||
public function loadClassMetadata(\Doctrine\ORM\Event\LoadClassMetadataEventArgs $eventArgs)
|
||||
@@ -48,4 +53,4 @@ class LoadEventTestEntity
|
||||
private $name;
|
||||
|
||||
private $about;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,7 +52,7 @@ class ProxyClassGeneratorTest extends \Doctrine\Tests\OrmTestCase
|
||||
public function testReferenceProxyDelegatesLoadingToThePersister()
|
||||
{
|
||||
$identifier = array('id' => 42);
|
||||
$proxyClass = 'Proxies\DoctrineTestsModelsECommerceECommerceFeatureProxy';
|
||||
$proxyClass = 'Proxies\__CG__\Doctrine\Tests\Models\ECommerce\ECommerceFeature';
|
||||
$persister = $this->_getMockPersister();
|
||||
$this->_uowMock->setEntityPersister('Doctrine\Tests\Models\ECommerce\ECommerceFeature', $persister);
|
||||
|
||||
@@ -69,7 +69,7 @@ class ProxyClassGeneratorTest extends \Doctrine\Tests\OrmTestCase
|
||||
public function testReferenceProxyExecutesLoadingOnlyOnce()
|
||||
{
|
||||
$identifier = array('id' => 42);
|
||||
$proxyClass = 'Proxies\DoctrineTestsModelsECommerceECommerceFeatureProxy';
|
||||
$proxyClass = 'Proxies\__CG__\Doctrine\Tests\Models\ECommerce\ECommerceFeature';
|
||||
$persister = $this->_getMockPersister();
|
||||
$this->_uowMock->setEntityPersister('Doctrine\Tests\Models\ECommerce\ECommerceFeature', $persister);
|
||||
$proxy = $this->_proxyFactory->getProxy('Doctrine\Tests\Models\ECommerce\ECommerceFeature', $identifier);
|
||||
@@ -108,7 +108,7 @@ class ProxyClassGeneratorTest extends \Doctrine\Tests\OrmTestCase
|
||||
|
||||
public function testCreatesAssociationProxyAsSubclassOfTheOriginalOne()
|
||||
{
|
||||
$proxyClass = 'Proxies\DoctrineTestsModelsECommerceECommerceFeatureProxy';
|
||||
$proxyClass = 'Proxies\__CG__\Doctrine\Tests\Models\ECommerce\ECommerceFeature';
|
||||
$this->assertTrue(is_subclass_of($proxyClass, 'Doctrine\Tests\Models\ECommerce\ECommerceFeature'));
|
||||
}
|
||||
|
||||
@@ -125,7 +125,7 @@ class ProxyClassGeneratorTest extends \Doctrine\Tests\OrmTestCase
|
||||
require_once dirname(__FILE__)."/fixtures/NonNamespacedProxies.php";
|
||||
|
||||
$className = "\DoctrineOrmTestEntity";
|
||||
$proxyName = "DoctrineOrmTestEntityProxy";
|
||||
$proxyName = "DoctrineOrmTestEntity";
|
||||
$classMetadata = new \Doctrine\ORM\Mapping\ClassMetadata($className);
|
||||
$classMetadata->initializeReflection(new \Doctrine\Common\Persistence\Mapping\RuntimeReflectionService);
|
||||
$classMetadata->mapField(array('fieldName' => 'id', 'type' => 'integer'));
|
||||
@@ -133,16 +133,16 @@ class ProxyClassGeneratorTest extends \Doctrine\Tests\OrmTestCase
|
||||
|
||||
$this->_proxyFactory->generateProxyClasses(array($classMetadata));
|
||||
|
||||
$classCode = file_get_contents(dirname(__FILE__)."/generated/".$proxyName.".php");
|
||||
$classCode = file_get_contents(dirname(__FILE__)."/generated/__CG__".$proxyName.".php");
|
||||
|
||||
$this->assertNotContains("class DoctrineOrmTestEntityProxy extends \\\\DoctrineOrmTestEntity", $classCode);
|
||||
$this->assertContains("class DoctrineOrmTestEntityProxy extends \\DoctrineOrmTestEntity", $classCode);
|
||||
$this->assertNotContains("class DoctrineOrmTestEntity extends \\\\DoctrineOrmTestEntity", $classCode);
|
||||
$this->assertContains("class DoctrineOrmTestEntity extends \\DoctrineOrmTestEntity", $classCode);
|
||||
}
|
||||
|
||||
public function testClassWithSleepProxyGeneration()
|
||||
{
|
||||
$className = "\Doctrine\Tests\ORM\Proxy\SleepClass";
|
||||
$proxyName = "DoctrineTestsORMProxySleepClassProxy";
|
||||
$proxyName = "DoctrineTestsORMProxySleepClass";
|
||||
$classMetadata = new \Doctrine\ORM\Mapping\ClassMetadata($className);
|
||||
$classMetadata->initializeReflection(new \Doctrine\Common\Persistence\Mapping\RuntimeReflectionService);
|
||||
$classMetadata->mapField(array('fieldName' => 'id', 'type' => 'integer'));
|
||||
@@ -150,7 +150,7 @@ class ProxyClassGeneratorTest extends \Doctrine\Tests\OrmTestCase
|
||||
|
||||
$this->_proxyFactory->generateProxyClasses(array($classMetadata));
|
||||
|
||||
$classCode = file_get_contents(dirname(__FILE__)."/generated/".$proxyName.".php");
|
||||
$classCode = file_get_contents(dirname(__FILE__)."/generated/__CG__".$proxyName.".php");
|
||||
|
||||
$this->assertEquals(1, substr_count($classCode, 'function __sleep'));
|
||||
}
|
||||
|
||||
@@ -101,4 +101,28 @@ class QueryTest extends \Doctrine\Tests\OrmTestCase
|
||||
$q->useResultCache(true);
|
||||
$this->assertSame($this->_em->getConfiguration()->getResultCacheImpl(), $q->getQueryCacheProfile()->getResultCacheDriver());
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Doctrine\ORM\Query\QueryException
|
||||
**/
|
||||
public function testIterateWithNoDistinctAndWrongSelectClause()
|
||||
{
|
||||
$q = $this->_em->createQuery("select u, a from Doctrine\Tests\Models\CMS\CmsUser u LEFT JOIN u.articles a");
|
||||
$q->iterate();
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Doctrine\ORM\Query\QueryException
|
||||
**/
|
||||
public function testIterateWithNoDistinctAndWithValidSelectClause()
|
||||
{
|
||||
$q = $this->_em->createQuery("select u from Doctrine\Tests\Models\CMS\CmsUser u LEFT JOIN u.articles a");
|
||||
$q->iterate();
|
||||
}
|
||||
|
||||
public function testIterateWithDistinct()
|
||||
{
|
||||
$q = $this->_em->createQuery("SELECT DISTINCT u from Doctrine\Tests\Models\CMS\CmsUser u LEFT JOIN u.articles a");
|
||||
$q->iterate();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -732,4 +732,17 @@ class QueryBuilderTest extends \Doctrine\Tests\OrmTestCase
|
||||
|
||||
$this->assertEquals('SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u', $qb->getDQL());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @group DDC-1619
|
||||
*/
|
||||
public function testAddDistinct()
|
||||
{
|
||||
$qb = $this->_em->createQueryBuilder()
|
||||
->select('u')
|
||||
->distinct()
|
||||
->from('Doctrine\Tests\Models\CMS\CmsUser', 'u');
|
||||
|
||||
$this->assertEquals('SELECT DISTINCT u FROM Doctrine\Tests\Models\CMS\CmsUser u', $qb->getDQL());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -47,6 +47,8 @@ class EntityGeneratorTest extends \Doctrine\Tests\OrmTestCase
|
||||
$metadata->customRepositoryClassName = $this->_namespace . '\EntityGeneratorBookRepository';
|
||||
|
||||
$metadata->table['name'] = 'book';
|
||||
$metadata->table['uniqueConstraints']['name_uniq'] = array('columns' => array('name'));
|
||||
$metadata->table['indexes']['status_idx'] = array('columns' => array('status'));
|
||||
$metadata->mapField(array('fieldName' => 'name', 'type' => 'string'));
|
||||
$metadata->mapField(array('fieldName' => 'status', 'type' => 'string', 'default' => 'published'));
|
||||
$metadata->mapField(array('fieldName' => 'id', 'type' => 'integer', 'id' => true));
|
||||
|
||||
@@ -0,0 +1,78 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Tests\ORM\Tools\Pagination;
|
||||
|
||||
use Doctrine\ORM\Query;
|
||||
use Doctrine\ORM\Tools\Pagination\CountWalker;
|
||||
|
||||
/**
|
||||
* @group DDC-1613
|
||||
*/
|
||||
class CountWalkerTest extends PaginationTestCase
|
||||
{
|
||||
public function testCountQuery()
|
||||
{
|
||||
$query = $this->entityManager->createQuery(
|
||||
'SELECT p, c, a FROM Doctrine\Tests\ORM\Tools\Pagination\BlogPost p JOIN p.category c JOIN p.author a');
|
||||
$query->setHint(Query::HINT_CUSTOM_TREE_WALKERS, array('Doctrine\ORM\Tools\Pagination\CountWalker'));
|
||||
$query->setHint(CountWalker::HINT_DISTINCT, true);
|
||||
$query->setFirstResult(null)->setMaxResults(null);
|
||||
|
||||
$this->assertEquals(
|
||||
"SELECT count(DISTINCT b0_.id) AS sclr0 FROM BlogPost b0_ INNER JOIN Category c1_ ON b0_.category_id = c1_.id INNER JOIN Author a2_ ON b0_.author_id = a2_.id", $query->getSql()
|
||||
);
|
||||
}
|
||||
|
||||
public function testCountQuery_MixedResultsWithName()
|
||||
{
|
||||
$query = $this->entityManager->createQuery(
|
||||
'SELECT a, sum(a.name) as foo FROM Doctrine\Tests\ORM\Tools\Pagination\Author a');
|
||||
$query->setHint(Query::HINT_CUSTOM_TREE_WALKERS, array('Doctrine\ORM\Tools\Pagination\CountWalker'));
|
||||
$query->setHint(CountWalker::HINT_DISTINCT, true);
|
||||
$query->setFirstResult(null)->setMaxResults(null);
|
||||
|
||||
$this->assertEquals(
|
||||
"SELECT count(DISTINCT a0_.id) AS sclr0 FROM Author a0_", $query->getSql()
|
||||
);
|
||||
}
|
||||
|
||||
public function testCountQuery_KeepsGroupBy()
|
||||
{
|
||||
$query = $this->entityManager->createQuery(
|
||||
'SELECT b FROM Doctrine\Tests\ORM\Tools\Pagination\BlogPost b GROUP BY b.id');
|
||||
$query->setHint(Query::HINT_CUSTOM_TREE_WALKERS, array('Doctrine\ORM\Tools\Pagination\CountWalker'));
|
||||
$query->setHint(CountWalker::HINT_DISTINCT, true);
|
||||
$query->setFirstResult(null)->setMaxResults(null);
|
||||
|
||||
$this->assertEquals(
|
||||
"SELECT count(DISTINCT b0_.id) AS sclr0 FROM BlogPost b0_ GROUP BY b0_.id", $query->getSql()
|
||||
);
|
||||
}
|
||||
|
||||
public function testCountQuery_RemovesOrderBy()
|
||||
{
|
||||
$query = $this->entityManager->createQuery(
|
||||
'SELECT p, c, a FROM Doctrine\Tests\ORM\Tools\Pagination\BlogPost p JOIN p.category c JOIN p.author a ORDER BY a.name');
|
||||
$query->setHint(Query::HINT_CUSTOM_TREE_WALKERS, array('Doctrine\ORM\Tools\Pagination\CountWalker'));
|
||||
$query->setHint(CountWalker::HINT_DISTINCT, true);
|
||||
$query->setFirstResult(null)->setMaxResults(null);
|
||||
|
||||
$this->assertEquals(
|
||||
"SELECT count(DISTINCT b0_.id) AS sclr0 FROM BlogPost b0_ INNER JOIN Category c1_ ON b0_.category_id = c1_.id INNER JOIN Author a2_ ON b0_.author_id = a2_.id", $query->getSql()
|
||||
);
|
||||
}
|
||||
|
||||
public function testCountQuery_RemovesLimits()
|
||||
{
|
||||
$query = $this->entityManager->createQuery(
|
||||
'SELECT p, c, a FROM Doctrine\Tests\ORM\Tools\Pagination\BlogPost p JOIN p.category c JOIN p.author a');
|
||||
$query->setHint(Query::HINT_CUSTOM_TREE_WALKERS, array('Doctrine\ORM\Tools\Pagination\CountWalker'));
|
||||
$query->setHint(CountWalker::HINT_DISTINCT, true);
|
||||
$query->setFirstResult(null)->setMaxResults(null);
|
||||
|
||||
$this->assertEquals(
|
||||
"SELECT count(DISTINCT b0_.id) AS sclr0 FROM BlogPost b0_ INNER JOIN Category c1_ ON b0_.category_id = c1_.id INNER JOIN Author a2_ ON b0_.author_id = a2_.id", $query->getSql()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Tests\ORM\Tools\Pagination;
|
||||
|
||||
use Doctrine\ORM\Query;
|
||||
|
||||
/**
|
||||
* @group DDC-1613
|
||||
*/
|
||||
class LimitSubqueryWalkerTest extends PaginationTestCase
|
||||
{
|
||||
public function testLimitSubquery()
|
||||
{
|
||||
$query = $this->entityManager->createQuery(
|
||||
'SELECT p, c, a FROM Doctrine\Tests\ORM\Tools\Pagination\MyBlogPost p JOIN p.category c JOIN p.author a');
|
||||
$limitQuery = clone $query;
|
||||
$limitQuery->setHint(Query::HINT_CUSTOM_TREE_WALKERS, array('Doctrine\ORM\Tools\Pagination\LimitSubqueryWalker'));
|
||||
|
||||
$this->assertEquals(
|
||||
"SELECT DISTINCT m0_.id AS id0 FROM MyBlogPost m0_ INNER JOIN Category c1_ ON m0_.category_id = c1_.id INNER JOIN Author a2_ ON m0_.author_id = a2_.id", $limitQuery->getSql()
|
||||
);
|
||||
}
|
||||
|
||||
public function testCountQuery_MixedResultsWithName()
|
||||
{
|
||||
$query = $this->entityManager->createQuery(
|
||||
'SELECT a, sum(a.name) as foo FROM Doctrine\Tests\ORM\Tools\Pagination\Author a');
|
||||
$limitQuery = clone $query;
|
||||
$limitQuery->setHint(Query::HINT_CUSTOM_TREE_WALKERS, array('Doctrine\ORM\Tools\Pagination\LimitSubqueryWalker'));
|
||||
|
||||
$this->assertEquals(
|
||||
"SELECT DISTINCT a0_.id AS id0, sum(a0_.name) AS sclr1 FROM Author a0_", $limitQuery->getSql()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
142
tests/Doctrine/Tests/ORM/Tools/Pagination/PaginationTestCase.php
Normal file
142
tests/Doctrine/Tests/ORM/Tools/Pagination/PaginationTestCase.php
Normal file
@@ -0,0 +1,142 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Tests\ORM\Tools\Pagination;
|
||||
|
||||
use Doctrine\Tests\OrmTestCase;
|
||||
|
||||
abstract class PaginationTestCase extends OrmTestCase
|
||||
{
|
||||
public $entityManager;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
$this->entityManager = $this->_getTestEntityManager();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @Entity
|
||||
*/
|
||||
class MyBlogPost
|
||||
{
|
||||
|
||||
/** @Id @column(type="integer") @generatedValue */
|
||||
public $id;
|
||||
/**
|
||||
* @ManyToOne(targetEntity="Author")
|
||||
*/
|
||||
public $author;
|
||||
/**
|
||||
* @ManyToOne(targetEntity="Category")
|
||||
*/
|
||||
public $category;
|
||||
}
|
||||
|
||||
/**
|
||||
* @Entity
|
||||
*/
|
||||
class MyAuthor
|
||||
{
|
||||
|
||||
/** @Id @column(type="integer") @generatedValue */
|
||||
public $id;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @Entity
|
||||
*/
|
||||
class MyCategory
|
||||
{
|
||||
|
||||
/** @id @column(type="integer") @generatedValue */
|
||||
public $id;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @Entity
|
||||
*/
|
||||
class BlogPost
|
||||
{
|
||||
|
||||
/** @Id @column(type="integer") @generatedValue */
|
||||
public $id;
|
||||
/**
|
||||
* @ManyToOne(targetEntity="Author")
|
||||
*/
|
||||
public $author;
|
||||
/**
|
||||
* @ManyToOne(targetEntity="Category")
|
||||
*/
|
||||
public $category;
|
||||
}
|
||||
|
||||
/**
|
||||
* @Entity
|
||||
*/
|
||||
class Author
|
||||
{
|
||||
|
||||
/** @Id @column(type="integer") @generatedValue */
|
||||
public $id;
|
||||
/** @Column(type="string") */
|
||||
public $name;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @Entity
|
||||
*/
|
||||
class Person
|
||||
{
|
||||
|
||||
/** @Id @column(type="integer") @generatedValue */
|
||||
public $id;
|
||||
/** @Column(type="string") */
|
||||
public $name;
|
||||
/** @Column(type="string") */
|
||||
public $biography;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @Entity
|
||||
*/
|
||||
class Category
|
||||
{
|
||||
|
||||
/** @id @column(type="integer") @generatedValue */
|
||||
public $id;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/** @Entity @Table(name="groups") */
|
||||
class Group
|
||||
{
|
||||
|
||||
/** @Id @column(type="integer") @generatedValue */
|
||||
public $id;
|
||||
/** @ManyToMany(targetEntity="User", mappedBy="groups") */
|
||||
public $users;
|
||||
}
|
||||
|
||||
/** @Entity */
|
||||
class User
|
||||
{
|
||||
|
||||
/** @Id @column(type="integer") @generatedValue */
|
||||
public $id;
|
||||
/**
|
||||
* @ManyToMany(targetEntity="Group", inversedBy="users")
|
||||
* @JoinTable(
|
||||
* name="user_group",
|
||||
* joinColumns = {@JoinColumn(name="user_id", referencedColumnName="id")},
|
||||
* inverseJoinColumns = {@JoinColumn(name="group_id", referencedColumnName="id")}
|
||||
* )
|
||||
*/
|
||||
public $groups;
|
||||
}
|
||||
111
tests/Doctrine/Tests/ORM/Tools/Pagination/WhereInWalkerTest.php
Normal file
111
tests/Doctrine/Tests/ORM/Tools/Pagination/WhereInWalkerTest.php
Normal file
@@ -0,0 +1,111 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Tests\ORM\Tools\Pagination;
|
||||
|
||||
use Doctrine\ORM\Query;
|
||||
use Doctrine\ORM\Tools\Pagination\WhereInWalker;
|
||||
|
||||
/**
|
||||
* @group DDC-1613
|
||||
*/
|
||||
class WhereInWalkerTest extends PaginationTestCase
|
||||
{
|
||||
public function testWhereInQuery_NoWhere()
|
||||
{
|
||||
$query = $this->entityManager->createQuery(
|
||||
'SELECT u, g FROM Doctrine\Tests\ORM\Tools\Pagination\User u JOIN u.groups g'
|
||||
);
|
||||
$whereInQuery = clone $query;
|
||||
$whereInQuery->setHint(Query::HINT_CUSTOM_TREE_WALKERS, array('Doctrine\ORM\Tools\Pagination\WhereInWalker'));
|
||||
$whereInQuery->setHint(WhereInWalker::HINT_PAGINATOR_ID_COUNT, 10);
|
||||
|
||||
$this->assertEquals(
|
||||
"SELECT u0_.id AS id0, g1_.id AS id1 FROM User u0_ INNER JOIN user_group u2_ ON u0_.id = u2_.user_id INNER JOIN groups g1_ ON g1_.id = u2_.group_id WHERE u0_.id IN (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", $whereInQuery->getSql()
|
||||
);
|
||||
}
|
||||
|
||||
public function testCountQuery_MixedResultsWithName()
|
||||
{
|
||||
$query = $this->entityManager->createQuery(
|
||||
'SELECT a, sum(a.name) as foo FROM Doctrine\Tests\ORM\Tools\Pagination\Author a'
|
||||
);
|
||||
$whereInQuery = clone $query;
|
||||
$whereInQuery->setHint(Query::HINT_CUSTOM_TREE_WALKERS, array('Doctrine\ORM\Tools\Pagination\WhereInWalker'));
|
||||
$whereInQuery->setHint(WhereInWalker::HINT_PAGINATOR_ID_COUNT, 10);
|
||||
|
||||
$this->assertEquals(
|
||||
"SELECT a0_.id AS id0, a0_.name AS name1, sum(a0_.name) AS sclr2 FROM Author a0_ WHERE a0_.id IN (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", $whereInQuery->getSql()
|
||||
);
|
||||
}
|
||||
|
||||
public function testWhereInQuery_SingleWhere()
|
||||
{
|
||||
$query = $this->entityManager->createQuery(
|
||||
'SELECT u, g FROM Doctrine\Tests\ORM\Tools\Pagination\User u JOIN u.groups g WHERE 1 = 1'
|
||||
);
|
||||
$whereInQuery = clone $query;
|
||||
$whereInQuery->setHint(Query::HINT_CUSTOM_TREE_WALKERS, array('Doctrine\ORM\Tools\Pagination\WhereInWalker'));
|
||||
$whereInQuery->setHint(WhereInWalker::HINT_PAGINATOR_ID_COUNT, 10);
|
||||
|
||||
$this->assertEquals(
|
||||
"SELECT u0_.id AS id0, g1_.id AS id1 FROM User u0_ INNER JOIN user_group u2_ ON u0_.id = u2_.user_id INNER JOIN groups g1_ ON g1_.id = u2_.group_id WHERE 1 = 1 AND u0_.id IN (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", $whereInQuery->getSql()
|
||||
);
|
||||
}
|
||||
|
||||
public function testWhereInQuery_MultipleWhereWithAnd()
|
||||
{
|
||||
$query = $this->entityManager->createQuery(
|
||||
'SELECT u, g FROM Doctrine\Tests\ORM\Tools\Pagination\User u JOIN u.groups g WHERE 1 = 1 AND 2 = 2'
|
||||
);
|
||||
$whereInQuery = clone $query;
|
||||
$whereInQuery->setHint(Query::HINT_CUSTOM_TREE_WALKERS, array('Doctrine\ORM\Tools\Pagination\WhereInWalker'));
|
||||
$whereInQuery->setHint(WhereInWalker::HINT_PAGINATOR_ID_COUNT, 10);
|
||||
|
||||
$this->assertEquals(
|
||||
"SELECT u0_.id AS id0, g1_.id AS id1 FROM User u0_ INNER JOIN user_group u2_ ON u0_.id = u2_.user_id INNER JOIN groups g1_ ON g1_.id = u2_.group_id WHERE 1 = 1 AND 2 = 2 AND u0_.id IN (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", $whereInQuery->getSql()
|
||||
);
|
||||
}
|
||||
|
||||
public function testWhereInQuery_MultipleWhereWithOr()
|
||||
{
|
||||
$query = $this->entityManager->createQuery(
|
||||
'SELECT u, g FROM Doctrine\Tests\ORM\Tools\Pagination\User u JOIN u.groups g WHERE 1 = 1 OR 2 = 2'
|
||||
);
|
||||
$whereInQuery = clone $query;
|
||||
$whereInQuery->setHint(Query::HINT_CUSTOM_TREE_WALKERS, array('Doctrine\ORM\Tools\Pagination\WhereInWalker'));
|
||||
$whereInQuery->setHint(WhereInWalker::HINT_PAGINATOR_ID_COUNT, 10);
|
||||
|
||||
$this->assertEquals(
|
||||
"SELECT u0_.id AS id0, g1_.id AS id1 FROM User u0_ INNER JOIN user_group u2_ ON u0_.id = u2_.user_id INNER JOIN groups g1_ ON g1_.id = u2_.group_id WHERE (1 = 1 OR 2 = 2) AND u0_.id IN (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", $whereInQuery->getSql()
|
||||
);
|
||||
}
|
||||
|
||||
public function testWhereInQuery_MultipleWhereWithMixed_1()
|
||||
{
|
||||
$query = $this->entityManager->createQuery(
|
||||
'SELECT u, g FROM Doctrine\Tests\ORM\Tools\Pagination\User u JOIN u.groups g WHERE (1 = 1 OR 2 = 2) AND 3 = 3'
|
||||
);
|
||||
$whereInQuery = clone $query;
|
||||
$whereInQuery->setHint(Query::HINT_CUSTOM_TREE_WALKERS, array('Doctrine\ORM\Tools\Pagination\WhereInWalker'));
|
||||
$whereInQuery->setHint(WhereInWalker::HINT_PAGINATOR_ID_COUNT, 10);
|
||||
|
||||
$this->assertEquals(
|
||||
"SELECT u0_.id AS id0, g1_.id AS id1 FROM User u0_ INNER JOIN user_group u2_ ON u0_.id = u2_.user_id INNER JOIN groups g1_ ON g1_.id = u2_.group_id WHERE (1 = 1 OR 2 = 2) AND 3 = 3 AND u0_.id IN (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", $whereInQuery->getSql()
|
||||
);
|
||||
}
|
||||
|
||||
public function testWhereInQuery_MultipleWhereWithMixed_2()
|
||||
{
|
||||
$query = $this->entityManager->createQuery(
|
||||
'SELECT u, g FROM Doctrine\Tests\ORM\Tools\Pagination\User u JOIN u.groups g WHERE 1 = 1 AND 2 = 2 OR 3 = 3'
|
||||
);
|
||||
$whereInQuery = clone $query;
|
||||
$whereInQuery->setHint(Query::HINT_CUSTOM_TREE_WALKERS, array('Doctrine\ORM\Tools\Pagination\WhereInWalker'));
|
||||
$whereInQuery->setHint(WhereInWalker::HINT_PAGINATOR_ID_COUNT, 10);
|
||||
|
||||
$this->assertEquals(
|
||||
"SELECT u0_.id AS id0, g1_.id AS id1 FROM User u0_ INNER JOIN user_group u2_ ON u0_.id = u2_.user_id INNER JOIN groups g1_ ON g1_.id = u2_.group_id WHERE (1 = 1 AND 2 = 2 OR 3 = 3) AND u0_.id IN (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", $whereInQuery->getSql()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,6 +32,21 @@ class SchemaToolTest extends \Doctrine\Tests\OrmTestCase
|
||||
$this->assertTrue($schema->getTable('cms_users')->columnsAreIndexed(array('username')), "username column should be indexed.");
|
||||
}
|
||||
|
||||
public function testColumnAnnotationOptionsAttribute()
|
||||
{
|
||||
$em = $this->_getTestEntityManager();
|
||||
$schemaTool = new SchemaTool($em);
|
||||
|
||||
$classes = array(
|
||||
$em->getClassMetadata(__NAMESPACE__ . '\\TestEntityWithColumnAnnotationOptionsAttribute'),
|
||||
);
|
||||
|
||||
$schema = $schemaTool->getSchemaFromMetadata($classes);
|
||||
|
||||
$expected = array('foo' => 'bar', 'baz' => array('key' => 'val'));
|
||||
$this->assertEquals($expected, $schema->getTable('TestEntityWithColumnAnnotationOptionsAttribute')->getColumn('test')->getCustomSchemaOptions(), "options annotation are passed to the columns customSchemaOptions");
|
||||
}
|
||||
|
||||
/**
|
||||
* @group DDC-200
|
||||
*/
|
||||
@@ -86,6 +101,20 @@ class SchemaToolTest extends \Doctrine\Tests\OrmTestCase
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @Entity
|
||||
*/
|
||||
class TestEntityWithColumnAnnotationOptionsAttribute
|
||||
{
|
||||
/** @Id @Column */
|
||||
private $id;
|
||||
|
||||
/**
|
||||
* @Column(type="string", options={"foo": "bar", "baz": {"key": "val"}})
|
||||
*/
|
||||
private $test;
|
||||
}
|
||||
|
||||
class GenerateSchemaEventListener
|
||||
{
|
||||
public $tableCalls = 0;
|
||||
|
||||
@@ -103,8 +103,8 @@ class SchemaValidatorTest extends \Doctrine\Tests\OrmTestCase
|
||||
|
||||
$this->assertEquals(
|
||||
array(
|
||||
"The referenced column name 'id' does not have a corresponding field with this column name on the class 'Doctrine\Tests\ORM\Tools\InvalidEntity1'.",
|
||||
"The join columns of the association 'assoc' have to match to ALL identifier columns of the source entity 'Doctrine\Tests\ORM\Tools\InvalidEntity2', however 'key3, key4' are missing."
|
||||
"The referenced column name 'id' has to be a primary key column on the target entity class 'Doctrine\Tests\ORM\Tools\InvalidEntity1'.",
|
||||
"The join columns of the association 'assoc' have to match to ALL identifier columns of the target entity 'Doctrine\Tests\ORM\Tools\InvalidEntity2', however 'key1, key2' are missing."
|
||||
),
|
||||
$ce
|
||||
);
|
||||
|
||||
@@ -114,4 +114,9 @@ abstract class OrmTestCase extends DoctrineTestCase
|
||||
|
||||
return self::$_queryCacheImpl;
|
||||
}
|
||||
|
||||
public function assertSQLEquals($expectedSQL, $actualSQL, $failureMessage = null)
|
||||
{
|
||||
return $this->assertEquals(strtolower($expectedSQL), strtolower($actualSQL), $failureMessage);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user