1
0
mirror of synced 2025-01-18 06:21:40 +03:00

Merge master into DDC-117

This commit is contained in:
Benjamin Eberlei 2010-08-27 22:27:00 +02:00
commit 5bd8ffa53c
72 changed files with 479 additions and 389 deletions

View File

@ -21,16 +21,16 @@ if (file_exists($configFile)) {
require $configFile; require $configFile;
foreach ($GLOBALS as $helperSetCandidate) { foreach ($GLOBALS as $helperSetCandidate) {
if ($helperSetCandidate instanceof \Symfony\Components\Console\Helper\HelperSet) { if ($helperSetCandidate instanceof \Symfony\Component\Console\Helper\HelperSet) {
$helperSet = $helperSetCandidate; $helperSet = $helperSetCandidate;
break; break;
} }
} }
} }
$helperSet = ($helperSet) ?: new \Symfony\Components\Console\Helper\HelperSet(); $helperSet = ($helperSet) ?: new \Symfony\Component\Console\Helper\HelperSet();
$cli = new \Symfony\Components\Console\Application('Doctrine Command Line Interface', Doctrine\ORM\Version::VERSION); $cli = new \Symfony\Component\Console\Application('Doctrine Command Line Interface', Doctrine\ORM\Version::VERSION);
$cli->setCatchExceptions(true); $cli->setCatchExceptions(true);
$cli->setHelperSet($helperSet); $cli->setHelperSet($helperSet);
$cli->addCommands(array( $cli->addCommands(array(
@ -55,4 +55,4 @@ $cli->addCommands(array(
new \Doctrine\ORM\Tools\Console\Command\ValidateSchemaCommand(), new \Doctrine\ORM\Tools\Console\Command\ValidateSchemaCommand(),
)); ));
$cli->run(); $cli->run();

View File

@ -138,10 +138,16 @@ abstract class AbstractQuery
/** /**
* Frees the resources used by the query object. * Frees the resources used by the query object.
*
* Resets Parameters, Parameter Types and Query Hints.
*
* @return void
*/ */
public function free() public function free()
{ {
$this->_params = array(); $this->_params = array();
$this->_paramTypes = array();
$this->_hints = array();
} }
/** /**
@ -569,4 +575,14 @@ abstract class AbstractQuery
* @return Doctrine\DBAL\Driver\Statement The executed database statement that holds the results. * @return Doctrine\DBAL\Driver\Statement The executed database statement that holds the results.
*/ */
abstract protected function _doExecute(); abstract protected function _doExecute();
/**
* Cleanup Query resource when clone is called.
*
* @return void
*/
public function __clone()
{
$this->free();
}
} }

View File

@ -38,17 +38,40 @@ use ReflectionException,
*/ */
class ClassMetadataFactory class ClassMetadataFactory
{ {
private $_em; /**
/** The targeted database platform. */ * @var EntityManager
private $_targetPlatform; */
/** The used metadata driver. */ private $em;
private $_driver;
/** The event manager instance */ /**
private $_evm; * @var AbstractPlatform
/** The used cache driver. */ */
private $_cacheDriver; private $targetPlatform;
private $_loadedMetadata = array();
private $_initialized = false; /**
* @var Driver\Driver
*/
private $driver;
/**
* @var \Doctrine\Common\EventManager
*/
private $evm;
/**
* @var \Doctrine\Common\Cache\Cache
*/
private $cacheDriver;
/**
* @var array
*/
private $loadedMetadata = array();
/**
* @var bool
*/
private $initialized = false;
/** /**
* Creates a new factory instance that uses the given metadata driver implementation. * Creates a new factory instance that uses the given metadata driver implementation.
@ -57,7 +80,7 @@ class ClassMetadataFactory
*/ */
public function __construct(EntityManager $em) public function __construct(EntityManager $em)
{ {
$this->_em = $em; $this->em = $em;
} }
/** /**
@ -67,7 +90,7 @@ class ClassMetadataFactory
*/ */
public function setCacheDriver($cacheDriver) public function setCacheDriver($cacheDriver)
{ {
$this->_cacheDriver = $cacheDriver; $this->cacheDriver = $cacheDriver;
} }
/** /**
@ -77,12 +100,12 @@ class ClassMetadataFactory
*/ */
public function getCacheDriver() public function getCacheDriver()
{ {
return $this->_cacheDriver; return $this->cacheDriver;
} }
public function getLoadedMetadata() public function getLoadedMetadata()
{ {
return $this->_loadedMetadata; return $this->loadedMetadata;
} }
/** /**
@ -93,12 +116,12 @@ class ClassMetadataFactory
*/ */
public function getAllMetadata() public function getAllMetadata()
{ {
if ( ! $this->_initialized) { if ( ! $this->initialized) {
$this->_initialize(); $this->initialize();
} }
$metadata = array(); $metadata = array();
foreach ($this->_driver->getAllClassNames() as $className) { foreach ($this->driver->getAllClassNames() as $className) {
$metadata[] = $this->getMetadataFor($className); $metadata[] = $this->getMetadataFor($className);
} }
@ -109,12 +132,12 @@ class ClassMetadataFactory
* Lazy initialization of this stuff, especially the metadata driver, * Lazy initialization of this stuff, especially the metadata driver,
* since these are not needed at all when a metadata cache is active. * since these are not needed at all when a metadata cache is active.
*/ */
private function _initialize() private function initialize()
{ {
$this->_driver = $this->_em->getConfiguration()->getMetadataDriverImpl(); $this->driver = $this->em->getConfiguration()->getMetadataDriverImpl();
$this->_targetPlatform = $this->_em->getConnection()->getDatabasePlatform(); $this->targetPlatform = $this->em->getConnection()->getDatabasePlatform();
$this->_evm = $this->_em->getEventManager(); $this->evm = $this->em->getEventManager();
$this->_initialized = true; $this->initialized = true;
} }
/** /**
@ -125,43 +148,43 @@ class ClassMetadataFactory
*/ */
public function getMetadataFor($className) public function getMetadataFor($className)
{ {
if ( ! isset($this->_loadedMetadata[$className])) { if ( ! isset($this->loadedMetadata[$className])) {
$realClassName = $className; $realClassName = $className;
// Check for namespace alias // Check for namespace alias
if (strpos($className, ':') !== false) { if (strpos($className, ':') !== false) {
list($namespaceAlias, $simpleClassName) = explode(':', $className); list($namespaceAlias, $simpleClassName) = explode(':', $className);
$realClassName = $this->_em->getConfiguration()->getEntityNamespace($namespaceAlias) . '\\' . $simpleClassName; $realClassName = $this->em->getConfiguration()->getEntityNamespace($namespaceAlias) . '\\' . $simpleClassName;
if (isset($this->_loadedMetadata[$realClassName])) { if (isset($this->loadedMetadata[$realClassName])) {
// We do not have the alias name in the map, include it // We do not have the alias name in the map, include it
$this->_loadedMetadata[$className] = $this->_loadedMetadata[$realClassName]; $this->loadedMetadata[$className] = $this->loadedMetadata[$realClassName];
return $this->_loadedMetadata[$realClassName]; return $this->loadedMetadata[$realClassName];
} }
} }
if ($this->_cacheDriver) { if ($this->cacheDriver) {
if (($cached = $this->_cacheDriver->fetch("$realClassName\$CLASSMETADATA")) !== false) { if (($cached = $this->cacheDriver->fetch("$realClassName\$CLASSMETADATA")) !== false) {
$this->_loadedMetadata[$realClassName] = $cached; $this->loadedMetadata[$realClassName] = $cached;
} else { } else {
foreach ($this->_loadMetadata($realClassName) as $loadedClassName) { foreach ($this->loadMetadata($realClassName) as $loadedClassName) {
$this->_cacheDriver->save( $this->cacheDriver->save(
"$loadedClassName\$CLASSMETADATA", $this->_loadedMetadata[$loadedClassName], null "$loadedClassName\$CLASSMETADATA", $this->loadedMetadata[$loadedClassName], null
); );
} }
} }
} else { } else {
$this->_loadMetadata($realClassName); $this->loadMetadata($realClassName);
} }
if ($className != $realClassName) { if ($className != $realClassName) {
// We do not have the alias name in the map, include it // We do not have the alias name in the map, include it
$this->_loadedMetadata[$className] = $this->_loadedMetadata[$realClassName]; $this->loadedMetadata[$className] = $this->loadedMetadata[$realClassName];
} }
} }
return $this->_loadedMetadata[$className]; return $this->loadedMetadata[$className];
} }
/** /**
@ -172,7 +195,7 @@ class ClassMetadataFactory
*/ */
public function hasMetadataFor($className) public function hasMetadataFor($className)
{ {
return isset($this->_loadedMetadata[$className]); return isset($this->loadedMetadata[$className]);
} }
/** /**
@ -185,7 +208,7 @@ class ClassMetadataFactory
*/ */
public function setMetadataFor($className, $class) public function setMetadataFor($className, $class)
{ {
$this->_loadedMetadata[$className] = $class; $this->loadedMetadata[$className] = $class;
} }
/** /**
@ -194,12 +217,12 @@ class ClassMetadataFactory
* @param string $name * @param string $name
* @return array $parentClasses * @return array $parentClasses
*/ */
protected function _getParentClasses($name) protected function getParentClasses($name)
{ {
// Collect parent classes, ignoring transient (not-mapped) classes. // Collect parent classes, ignoring transient (not-mapped) classes.
$parentClasses = array(); $parentClasses = array();
foreach (array_reverse(class_parents($name)) as $parentClass) { foreach (array_reverse(class_parents($name)) as $parentClass) {
if ( ! $this->_driver->isTransient($parentClass)) { if ( ! $this->driver->isTransient($parentClass)) {
$parentClasses[] = $parentClass; $parentClasses[] = $parentClass;
} }
} }
@ -213,37 +236,37 @@ class ClassMetadataFactory
* @param string $name The name of the class for which the metadata should get loaded. * @param string $name The name of the class for which the metadata should get loaded.
* @param array $tables The metadata collection to which the loaded metadata is added. * @param array $tables The metadata collection to which the loaded metadata is added.
*/ */
protected function _loadMetadata($name) protected function loadMetadata($name)
{ {
if ( ! $this->_initialized) { if ( ! $this->initialized) {
$this->_initialize(); $this->initialize();
} }
$loaded = array(); $loaded = array();
$parentClasses = $this->_getParentClasses($name); $parentClasses = $this->getParentClasses($name);
$parentClasses[] = $name; $parentClasses[] = $name;
// Move down the hierarchy of parent classes, starting from the topmost class // Move down the hierarchy of parent classes, starting from the topmost class
$parent = null; $parent = null;
$visited = array(); $visited = array();
foreach ($parentClasses as $className) { foreach ($parentClasses as $className) {
if (isset($this->_loadedMetadata[$className])) { if (isset($this->loadedMetadata[$className])) {
$parent = $this->_loadedMetadata[$className]; $parent = $this->loadedMetadata[$className];
if ( ! $parent->isMappedSuperclass) { if ( ! $parent->isMappedSuperclass) {
array_unshift($visited, $className); array_unshift($visited, $className);
} }
continue; continue;
} }
$class = $this->_newClassMetadataInstance($className); $class = $this->newClassMetadataInstance($className);
if ($parent) { if ($parent) {
$class->setInheritanceType($parent->inheritanceType); $class->setInheritanceType($parent->inheritanceType);
$class->setDiscriminatorColumn($parent->discriminatorColumn); $class->setDiscriminatorColumn($parent->discriminatorColumn);
$class->setIdGeneratorType($parent->generatorType); $class->setIdGeneratorType($parent->generatorType);
$this->_addInheritedFields($class, $parent); $this->addInheritedFields($class, $parent);
$this->_addInheritedRelations($class, $parent); $this->addInheritedRelations($class, $parent);
$class->setIdentifier($parent->identifier); $class->setIdentifier($parent->identifier);
$class->setVersioned($parent->isVersioned); $class->setVersioned($parent->isVersioned);
$class->setVersionField($parent->versionField); $class->setVersionField($parent->versionField);
@ -254,7 +277,7 @@ class ClassMetadataFactory
// Invoke driver // Invoke driver
try { try {
$this->_driver->loadMetadataForClass($className, $class); $this->driver->loadMetadataForClass($className, $class);
} catch (ReflectionException $e) { } catch (ReflectionException $e) {
throw MappingException::reflectionFailure($className, $e); throw MappingException::reflectionFailure($className, $e);
} }
@ -276,7 +299,17 @@ class ClassMetadataFactory
$class->setIdGenerator($parent->idGenerator); $class->setIdGenerator($parent->idGenerator);
} }
} else { } else {
$this->_completeIdGeneratorMapping($class); $this->completeIdGeneratorMapping($class);
}
// verify inheritance
if (!$parent && !$class->isMappedSuperclass && !$class->isInheritanceTypeNone()) {
if (count($class->discriminatorMap) == 0) {
throw MappingException::missingDiscriminatorMap($class->name);
}
if (!$class->discriminatorColumn) {
throw MappingException::missingDiscriminatorColumn($class->name);
}
} }
if ($parent && $parent->isInheritanceTypeSingleTable()) { if ($parent && $parent->isInheritanceTypeSingleTable()) {
@ -285,12 +318,12 @@ class ClassMetadataFactory
$class->setParentClasses($visited); $class->setParentClasses($visited);
if ($this->_evm->hasListeners(Events::loadClassMetadata)) { if ($this->evm->hasListeners(Events::loadClassMetadata)) {
$eventArgs = new \Doctrine\ORM\Event\LoadClassMetadataEventArgs($class); $eventArgs = new \Doctrine\ORM\Event\LoadClassMetadataEventArgs($class);
$this->_evm->dispatchEvent(Events::loadClassMetadata, $eventArgs); $this->evm->dispatchEvent(Events::loadClassMetadata, $eventArgs);
} }
$this->_loadedMetadata[$className] = $class; $this->loadedMetadata[$className] = $class;
$parent = $class; $parent = $class;
@ -310,7 +343,7 @@ class ClassMetadataFactory
* @param string $className * @param string $className
* @return Doctrine\ORM\Mapping\ClassMetadata * @return Doctrine\ORM\Mapping\ClassMetadata
*/ */
protected function _newClassMetadataInstance($className) protected function newClassMetadataInstance($className)
{ {
return new ClassMetadata($className); return new ClassMetadata($className);
} }
@ -321,7 +354,7 @@ class ClassMetadataFactory
* @param Doctrine\ORM\Mapping\ClassMetadata $subClass * @param Doctrine\ORM\Mapping\ClassMetadata $subClass
* @param Doctrine\ORM\Mapping\ClassMetadata $parentClass * @param Doctrine\ORM\Mapping\ClassMetadata $parentClass
*/ */
private function _addInheritedFields(ClassMetadata $subClass, ClassMetadata $parentClass) private function addInheritedFields(ClassMetadata $subClass, ClassMetadata $parentClass)
{ {
foreach ($parentClass->fieldMappings as $fieldName => $mapping) { foreach ($parentClass->fieldMappings as $fieldName => $mapping) {
if ( ! isset($mapping['inherited']) && ! $parentClass->isMappedSuperclass) { if ( ! isset($mapping['inherited']) && ! $parentClass->isMappedSuperclass) {
@ -343,7 +376,7 @@ class ClassMetadataFactory
* @param Doctrine\ORM\Mapping\ClassMetadata $subClass * @param Doctrine\ORM\Mapping\ClassMetadata $subClass
* @param Doctrine\ORM\Mapping\ClassMetadata $parentClass * @param Doctrine\ORM\Mapping\ClassMetadata $parentClass
*/ */
private function _addInheritedRelations(ClassMetadata $subClass, ClassMetadata $parentClass) private function addInheritedRelations(ClassMetadata $subClass, ClassMetadata $parentClass)
{ {
foreach ($parentClass->associationMappings as $field => $mapping) { foreach ($parentClass->associationMappings as $field => $mapping) {
//$subclassMapping = $mapping; //$subclassMapping = $mapping;
@ -363,13 +396,13 @@ class ClassMetadataFactory
* *
* @param Doctrine\ORM\Mapping\ClassMetadata $class * @param Doctrine\ORM\Mapping\ClassMetadata $class
*/ */
private function _completeIdGeneratorMapping(ClassMetadataInfo $class) private function completeIdGeneratorMapping(ClassMetadataInfo $class)
{ {
$idGenType = $class->generatorType; $idGenType = $class->generatorType;
if ($idGenType == ClassMetadata::GENERATOR_TYPE_AUTO) { if ($idGenType == ClassMetadata::GENERATOR_TYPE_AUTO) {
if ($this->_targetPlatform->prefersSequences()) { if ($this->targetPlatform->prefersSequences()) {
$class->setIdGeneratorType(ClassMetadata::GENERATOR_TYPE_SEQUENCE); $class->setIdGeneratorType(ClassMetadata::GENERATOR_TYPE_SEQUENCE);
} else if ($this->_targetPlatform->prefersIdentityColumns()) { } else if ($this->targetPlatform->prefersIdentityColumns()) {
$class->setIdGeneratorType(ClassMetadata::GENERATOR_TYPE_IDENTITY); $class->setIdGeneratorType(ClassMetadata::GENERATOR_TYPE_IDENTITY);
} else { } else {
$class->setIdGeneratorType(ClassMetadata::GENERATOR_TYPE_TABLE); $class->setIdGeneratorType(ClassMetadata::GENERATOR_TYPE_TABLE);
@ -382,7 +415,7 @@ class ClassMetadataFactory
// For PostgreSQL IDENTITY (SERIAL) we need a sequence name. It defaults to // For PostgreSQL IDENTITY (SERIAL) we need a sequence name. It defaults to
// <table>_<column>_seq in PostgreSQL for SERIAL columns. // <table>_<column>_seq in PostgreSQL for SERIAL columns.
// Not pretty but necessary and the simplest solution that currently works. // Not pretty but necessary and the simplest solution that currently works.
$seqName = $this->_targetPlatform instanceof Platforms\PostgreSQLPlatform ? $seqName = $this->targetPlatform instanceof Platforms\PostgreSQLPlatform ?
$class->table['name'] . '_' . $class->columnNames[$class->identifier[0]] . '_seq' : $class->table['name'] . '_' . $class->columnNames[$class->identifier[0]] . '_seq' :
null; null;
$class->setIdGenerator(new \Doctrine\ORM\Id\IdentityGenerator($seqName)); $class->setIdGenerator(new \Doctrine\ORM\Id\IdentityGenerator($seqName));
@ -392,7 +425,7 @@ class ClassMetadataFactory
$definition = $class->sequenceGeneratorDefinition; $definition = $class->sequenceGeneratorDefinition;
if ( ! $definition) { if ( ! $definition) {
$sequenceName = $class->getTableName() . '_' . $class->getSingleIdentifierColumnName() . '_seq'; $sequenceName = $class->getTableName() . '_' . $class->getSingleIdentifierColumnName() . '_seq';
$definition['sequenceName'] = $this->_targetPlatform->fixSchemaElementName($sequenceName); $definition['sequenceName'] = $this->targetPlatform->fixSchemaElementName($sequenceName);
$definition['allocationSize'] = 1; $definition['allocationSize'] = 1;
$definition['initialValue'] = 1; $definition['initialValue'] = 1;
$class->setSequenceGeneratorDefinition($definition); $class->setSequenceGeneratorDefinition($definition);

View File

@ -680,9 +680,11 @@ class ClassMetadataInfo
} }
/** /**
* Validates & completes the mapping. Mapping defaults are applied here. * Validates & completes the basic mapping information that is common to all
* association mappings (one-to-one, many-ot-one, one-to-many, many-to-many).
* *
* @param array $mapping * @param array $mapping The mapping.
* @return array The updated mapping.
* @throws MappingException If something is wrong with the mapping. * @throws MappingException If something is wrong with the mapping.
*/ */
protected function _validateAndCompleteAssociationMapping(array $mapping) protected function _validateAndCompleteAssociationMapping(array $mapping)
@ -693,10 +695,13 @@ class ClassMetadataInfo
if ( ! isset($mapping['inversedBy'])) { if ( ! isset($mapping['inversedBy'])) {
$mapping['inversedBy'] = null; $mapping['inversedBy'] = null;
} }
$mapping['isOwningSide'] = true; $mapping['isOwningSide'] = true; // assume owning side until we hit mappedBy
// If targetEntity is unqualified, assume it is in the same namespace as
// the sourceEntity.
$mapping['sourceEntity'] = $this->name; $mapping['sourceEntity'] = $this->name;
if (isset($mapping['targetEntity']) && strpos($mapping['targetEntity'], '\\') === false && strlen($this->namespace) > 0) { if (isset($mapping['targetEntity']) && strpos($mapping['targetEntity'], '\\') === false
&& strlen($this->namespace) > 0) {
$mapping['targetEntity'] = $this->namespace . '\\' . $mapping['targetEntity']; $mapping['targetEntity'] = $this->namespace . '\\' . $mapping['targetEntity'];
} }
@ -712,23 +717,18 @@ class ClassMetadataInfo
} }
// Mandatory attributes for both sides // Mandatory attributes for both sides
// Mandatory: fieldName, targetEntity
if ( ! isset($mapping['fieldName'])) { if ( ! isset($mapping['fieldName'])) {
throw MappingException::missingFieldName(); throw MappingException::missingFieldName();
} }
if ( ! isset($mapping['sourceEntity'])) {
throw MappingException::missingSourceEntity($mapping['fieldName']);
}
if ( ! isset($mapping['targetEntity'])) { if ( ! isset($mapping['targetEntity'])) {
throw MappingException::missingTargetEntity($mapping['fieldName']); throw MappingException::missingTargetEntity($mapping['fieldName']);
} }
// Mandatory and optional attributes for either side // Mandatory and optional attributes for either side
if ( ! isset($mapping['mappedBy'])) { if ( ! $mapping['mappedBy']) {
// Optional
if (isset($mapping['joinTable']) && $mapping['joinTable']) { if (isset($mapping['joinTable']) && $mapping['joinTable']) {
if ($mapping['joinTable']['name'][0] == '`') { if (isset($mapping['joinTable']['name']) && $mapping['joinTable']['name'][0] == '`') {
$mapping['joinTable']['name'] = trim($mapping['joinTable']['name'], '`'); $mapping['joinTable']['name'] = trim($mapping['joinTable']['name'], '`');
$mapping['joinTable']['quoted'] = true; $mapping['joinTable']['quoted'] = true;
} }
@ -737,12 +737,13 @@ class ClassMetadataInfo
$mapping['isOwningSide'] = false; $mapping['isOwningSide'] = false;
} }
// Optional attributes for both sides // Fetch mode. Default fetch mode to LAZY, if not set.
if ( ! isset($mapping['fetch'])) { if ( ! isset($mapping['fetch'])) {
$mapping['fetch'] = self::FETCH_LAZY; $mapping['fetch'] = self::FETCH_LAZY;
} }
// Cascades
$cascades = isset($mapping['cascade']) ? $mapping['cascade'] : array(); $cascades = isset($mapping['cascade']) ? $mapping['cascade'] : array();
if (in_array('all', $cascades)) { if (in_array('all', $cascades)) {
$cascades = array( $cascades = array(
'remove', 'remove',
@ -763,10 +764,10 @@ class ClassMetadataInfo
} }
/** /**
* {@inheritdoc} * Validates & completes a one-to-one association mapping.
* *
* @param array $mapping The mapping to validate & complete. * @param array $mapping The mapping to validate & complete.
* @return array The validated & completed mapping. * @return array The validated & completed mapping.
* @override * @override
*/ */
protected function _validateAndCompleteOneToOneMapping(array $mapping) protected function _validateAndCompleteOneToOneMapping(array $mapping)
@ -785,11 +786,16 @@ class ClassMetadataInfo
'referencedColumnName' => 'id' 'referencedColumnName' => 'id'
)); ));
} }
foreach ($mapping['joinColumns'] AS $key => $joinColumn) { foreach ($mapping['joinColumns'] as $key => &$joinColumn) {
if ($mapping['type'] == self::ONE_TO_ONE) { if ($mapping['type'] === self::ONE_TO_ONE) {
$mapping['joinColumns'][$key]['unique'] = true; $joinColumn['unique'] = true;
}
if (empty($joinColumn['name'])) {
$joinColumn['name'] = $mapping['fieldName'] . '_id';
}
if (empty($joinColumn['referencedColumnName'])) {
$joinColumn['referencedColumnName'] = 'id';
} }
$mapping['sourceToTargetKeyColumns'][$joinColumn['name']] = $joinColumn['referencedColumnName']; $mapping['sourceToTargetKeyColumns'][$joinColumn['name']] = $joinColumn['referencedColumnName'];
$mapping['joinColumnFieldNames'][$joinColumn['name']] = isset($joinColumn['fieldName']) $mapping['joinColumnFieldNames'][$joinColumn['name']] = isset($joinColumn['fieldName'])
? $joinColumn['fieldName'] : $joinColumn['name']; ? $joinColumn['fieldName'] : $joinColumn['name'];
@ -837,58 +843,49 @@ class ClassMetadataInfo
{ {
$mapping = $this->_validateAndCompleteAssociationMapping($mapping); $mapping = $this->_validateAndCompleteAssociationMapping($mapping);
if ($mapping['isOwningSide']) { if ($mapping['isOwningSide']) {
$sourceShortName = strtolower(substr($mapping['sourceEntity'], strrpos($mapping['sourceEntity'], '\\') + 1));
$targetShortName = strtolower(substr($mapping['targetEntity'], strrpos($mapping['targetEntity'], '\\') + 1));
// owning side MUST have a join table // owning side MUST have a join table
if ( ! isset($mapping['joinTable']) || ! $mapping['joinTable']) { if ( ! isset($mapping['joinTable']['name'])) {
// Apply default join table $mapping['joinTable']['name'] = $sourceShortName .'_' . $targetShortName;
$sourceShortName = substr($mapping['sourceEntity'], strrpos($mapping['sourceEntity'], '\\') + 1);
$targetShortName = substr($mapping['targetEntity'], strrpos($mapping['targetEntity'], '\\') + 1);
$mapping['joinTable'] = array(
'name' => $sourceShortName .'_' . $targetShortName,
'joinColumns' => array(
array(
'name' => $sourceShortName . '_id',
'referencedColumnName' => 'id',
'onDelete' => 'CASCADE'
)
),
'inverseJoinColumns' => array(
array(
'name' => $targetShortName . '_id',
'referencedColumnName' => 'id',
'onDelete' => 'CASCADE'
)
)
);
} }
// owning side MUST specify joinColumns if ( ! isset($mapping['joinTable']['joinColumns'])) {
else if ( ! isset($mapping['joinTable']['joinColumns'])) { $mapping['joinTable']['joinColumns'] = array(array(
throw MappingException::missingRequiredOption( 'name' => $sourceShortName . '_id',
$mapping['fieldName'], 'joinColumns', 'referencedColumnName' => 'id',
'Did you think of case sensitivity / plural s?' 'onDelete' => 'CASCADE'));
);
} }
// owning side MUST specify inverseJoinColumns if ( ! isset($mapping['joinTable']['inverseJoinColumns'])) {
else if ( ! isset($mapping['joinTable']['inverseJoinColumns'])) { $mapping['joinTable']['inverseJoinColumns'] = array(array(
throw MappingException::missingRequiredOption( 'name' => $targetShortName . '_id',
$mapping['fieldName'], 'inverseJoinColumns', 'referencedColumnName' => 'id',
'Did you think of case sensitivity / plural s?' 'onDelete' => 'CASCADE'));
);
} }
foreach ($mapping['joinTable']['joinColumns'] as $joinColumn) { foreach ($mapping['joinTable']['joinColumns'] as &$joinColumn) {
if (empty($joinColumn['name'])) {
$joinColumn['name'] = $sourceShortName . '_id';
}
if (empty($joinColumn['referencedColumnName'])) {
$joinColumn['referencedColumnName'] = 'id';
}
if (isset($joinColumn['onDelete']) && strtolower($joinColumn['onDelete']) == 'cascade') { if (isset($joinColumn['onDelete']) && strtolower($joinColumn['onDelete']) == 'cascade') {
$mapping['isOnDeleteCascade'] = true; $mapping['isOnDeleteCascade'] = true;
} }
$mapping['relationToSourceKeyColumns'][$joinColumn['name']] = $joinColumn['referencedColumnName']; $mapping['relationToSourceKeyColumns'][$joinColumn['name']] = $joinColumn['referencedColumnName'];
$mapping['joinTableColumns'][] = $joinColumn['name']; $mapping['joinTableColumns'][] = $joinColumn['name'];
} }
foreach ($mapping['joinTable']['inverseJoinColumns'] as $inverseJoinColumn) { foreach ($mapping['joinTable']['inverseJoinColumns'] as &$inverseJoinColumn) {
if (empty($inverseJoinColumn['name'])) {
$inverseJoinColumn['name'] = $targetShortName . '_id';
}
if (empty($inverseJoinColumn['referencedColumnName'])) {
$inverseJoinColumn['referencedColumnName'] = 'id';
}
if (isset($inverseJoinColumn['onDelete']) && strtolower($inverseJoinColumn['onDelete']) == 'cascade') { if (isset($inverseJoinColumn['onDelete']) && strtolower($inverseJoinColumn['onDelete']) == 'cascade') {
$mapping['isOnDeleteCascade'] = true; $mapping['isOnDeleteCascade'] = true;
} }
$mapping['relationToTargetKeyColumns'][$inverseJoinColumn['name']] = $inverseJoinColumn['referencedColumnName']; $mapping['relationToTargetKeyColumns'][$inverseJoinColumn['name']] = $inverseJoinColumn['referencedColumnName'];
$mapping['joinTableColumns'][] = $inverseJoinColumn['name']; $mapping['joinTableColumns'][] = $inverseJoinColumn['name'];
} }
@ -899,7 +896,7 @@ class ClassMetadataInfo
throw new \InvalidArgumentException("'orderBy' is expected to be an array, not ".gettype($mapping['orderBy'])); throw new \InvalidArgumentException("'orderBy' is expected to be an array, not ".gettype($mapping['orderBy']));
} }
} }
return $mapping; return $mapping;
} }
@ -1226,22 +1223,33 @@ class ClassMetadataInfo
* indexes => array of indexes (optional) * indexes => array of indexes (optional)
* uniqueConstraints => array of constraints (optional) * uniqueConstraints => array of constraints (optional)
* *
* @param array $table * If a key is omitted, the current value is kept.
*
* @param array $table The table description.
*/ */
public function setPrimaryTable(array $table) public function setPrimaryTable(array $table)
{ {
if (isset($table['name']) && $table['name'][0] == '`') { if (isset($table['name'])) {
$table['name'] = trim($table['name'], '`'); if ($table['name'][0] == '`') {
$table['quoted'] = true; $this->table['name'] = trim($table['name'], '`');
$this->table['quoted'] = true;
} else {
$this->table['name'] = $table['name'];
}
}
if (isset($table['indexes'])) {
$this->table['indexes'] = $table['indexes'];
}
if (isset($table['uniqueConstraints'])) {
$this->table['uniqueConstraints'] = $table['uniqueConstraints'];
} }
$this->table = $table;
} }
/** /**
* Checks whether the given type identifies an inheritance type. * Checks whether the given type identifies an inheritance type.
* *
* @param string $type * @param integer $type
* @return boolean * @return boolean TRUE if the given type identifies an inheritance type, FALSe otherwise.
*/ */
private function _isInheritanceType($type) private function _isInheritanceType($type)
{ {

View File

@ -179,16 +179,12 @@ class AnnotationDriver implements Driver
'type' => $discrColumnAnnot->type, 'type' => $discrColumnAnnot->type,
'length' => $discrColumnAnnot->length 'length' => $discrColumnAnnot->length
)); ));
} else {
throw MappingException::missingDiscriminatorColumn($className);
} }
// Evaluate DiscriminatorMap annotation // Evaluate DiscriminatorMap annotation
if (isset($classAnnotations['Doctrine\ORM\Mapping\DiscriminatorMap'])) { if (isset($classAnnotations['Doctrine\ORM\Mapping\DiscriminatorMap'])) {
$discrMapAnnot = $classAnnotations['Doctrine\ORM\Mapping\DiscriminatorMap']; $discrMapAnnot = $classAnnotations['Doctrine\ORM\Mapping\DiscriminatorMap'];
$metadata->setDiscriminatorMap($discrMapAnnot->value); $metadata->setDiscriminatorMap($discrMapAnnot->value);
} else {
throw MappingException::missingDiscriminatorMap($className);
} }
} }
} }

View File

@ -87,8 +87,6 @@ class XmlDriver extends AbstractFileDriver
'type' => (string)$discrColumn['type'], 'type' => (string)$discrColumn['type'],
'length' => (string)$discrColumn['length'] 'length' => (string)$discrColumn['length']
)); ));
} else {
throw MappingException::missingDiscriminatorColumn($className);
} }
// Evaluate <discriminator-map...> // Evaluate <discriminator-map...>
@ -98,8 +96,6 @@ class XmlDriver extends AbstractFileDriver
$map[(string)$discrMapElement['value']] = (string)$discrMapElement['class']; $map[(string)$discrMapElement['value']] = (string)$discrMapElement['class'];
} }
$metadata->setDiscriminatorMap($map); $metadata->setDiscriminatorMap($map);
} else {
throw MappingException::missingDiscriminatorMap($className);
} }
} }
} }

View File

@ -79,15 +79,11 @@ class YamlDriver extends AbstractFileDriver
'type' => $discrColumn['type'], 'type' => $discrColumn['type'],
'length' => $discrColumn['length'] 'length' => $discrColumn['length']
)); ));
} else {
throw MappingException::missingDiscriminatorColumn($className);
} }
// Evaluate discriminatorMap // Evaluate discriminatorMap
if (isset($element['discriminatorMap'])) { if (isset($element['discriminatorMap'])) {
$metadata->setDiscriminatorMap($element['discriminatorMap']); $metadata->setDiscriminatorMap($element['discriminatorMap']);
} else {
throw MappingException::missingDiscriminatorMap($className);
} }
} }
} }
@ -452,6 +448,6 @@ class YamlDriver extends AbstractFileDriver
*/ */
protected function _loadMappingFile($file) protected function _loadMappingFile($file)
{ {
return \Symfony\Components\Yaml\Yaml::load($file); return \Symfony\Component\Yaml\Yaml::load($file);
} }
} }

View File

@ -661,4 +661,21 @@ final class PersistentCollection implements Collection
{ {
return $this->coll; return $this->coll;
} }
/**
* Extract a slice of $length elements starting at position $offset from the Collection.
*
* If $length is null it returns all elements from $offset to the end of the Collection.
* Keys have to be preserved by this method. Calling this method will only return the
* selected slice and NOT change the elements contained in the collection slice is called on.
*
* @param int $offset
* @param int $length
* @return array
*/
public function slice($offset, $length = null)
{
$this->initialize();
return $this->coll->slice($offset, $length);
}
} }

View File

@ -425,15 +425,11 @@ class Parser
/** /**
* Checks if the given token indicates a mathematical operator. * Checks if the given token indicates a mathematical operator.
* *
* @return boolean TRUE is the token is a mathematical operator, FALSE otherwise. * @return boolean TRUE if the token is a mathematical operator, FALSE otherwise.
*/ */
private function _isMathOperator($token) private function _isMathOperator($token)
{ {
if (in_array($token['value'], array("+", "-", "/", "*"))) { return in_array($token['value'], array("+", "-", "/", "*"));
return true;
}
return false;
} }
/** /**

View File

@ -21,9 +21,9 @@
namespace Doctrine\ORM\Tools\Console\Command\ClearCache; namespace Doctrine\ORM\Tools\Console\Command\ClearCache;
use Symfony\Components\Console\Input\InputArgument, use Symfony\Component\Console\Input\InputArgument,
Symfony\Components\Console\Input\InputOption, Symfony\Component\Console\Input\InputOption,
Symfony\Components\Console; Symfony\Component\Console;
/** /**
* Command to clear the metadata cache of the various cache drivers. * Command to clear the metadata cache of the various cache drivers.
@ -82,4 +82,4 @@ EOT
$output->write('No entries to be deleted.' . PHP_EOL); $output->write('No entries to be deleted.' . PHP_EOL);
} }
} }
} }

View File

@ -21,9 +21,9 @@
namespace Doctrine\ORM\Tools\Console\Command\ClearCache; namespace Doctrine\ORM\Tools\Console\Command\ClearCache;
use Symfony\Components\Console\Input\InputArgument, use Symfony\Component\Console\Input\InputArgument,
Symfony\Components\Console\Input\InputOption, Symfony\Component\Console\Input\InputOption,
Symfony\Components\Console; Symfony\Component\Console;
/** /**
* Command to clear the query cache of the various cache drivers. * Command to clear the query cache of the various cache drivers.
@ -82,4 +82,4 @@ EOT
$output->write('No entries to be deleted.' . PHP_EOL); $output->write('No entries to be deleted.' . PHP_EOL);
} }
} }
} }

View File

@ -21,9 +21,9 @@
namespace Doctrine\ORM\Tools\Console\Command\ClearCache; namespace Doctrine\ORM\Tools\Console\Command\ClearCache;
use Symfony\Components\Console\Input\InputArgument, use Symfony\Component\Console\Input\InputArgument,
Symfony\Components\Console\Input\InputOption, Symfony\Component\Console\Input\InputOption,
Symfony\Components\Console; Symfony\Component\Console;
/** /**
* Command to clear the result cache of the various cache drivers. * Command to clear the result cache of the various cache drivers.
@ -165,4 +165,4 @@ EOT
$output->write('No entries to be deleted.' . PHP_EOL); $output->write('No entries to be deleted.' . PHP_EOL);
} }
} }
} }

View File

@ -21,9 +21,9 @@
namespace Doctrine\ORM\Tools\Console\Command; namespace Doctrine\ORM\Tools\Console\Command;
use Symfony\Components\Console\Input\InputArgument, use Symfony\Component\Console\Input\InputArgument,
Symfony\Components\Console\Input\InputOption, Symfony\Component\Console\Input\InputOption,
Symfony\Components\Console, Symfony\Component\Console,
Doctrine\ORM\Tools\Export\ClassMetadataExporter, Doctrine\ORM\Tools\Export\ClassMetadataExporter,
Doctrine\ORM\Tools\ConvertDoctrine1Schema, Doctrine\ORM\Tools\ConvertDoctrine1Schema,
Doctrine\ORM\Tools\EntityGenerator; Doctrine\ORM\Tools\EntityGenerator;
@ -220,4 +220,4 @@ EOT
$output->write('No Metadata Classes to process.' . PHP_EOL); $output->write('No Metadata Classes to process.' . PHP_EOL);
} }
} }
} }

View File

@ -21,9 +21,9 @@
namespace Doctrine\ORM\Tools\Console\Command; namespace Doctrine\ORM\Tools\Console\Command;
use Symfony\Components\Console\Input\InputArgument, use Symfony\Component\Console\Input\InputArgument,
Symfony\Components\Console\Input\InputOption, Symfony\Component\Console\Input\InputOption,
Symfony\Components\Console, Symfony\Component\Console,
Doctrine\ORM\Tools\Console\MetadataFilter, Doctrine\ORM\Tools\Console\MetadataFilter,
Doctrine\ORM\Tools\Export\ClassMetadataExporter, Doctrine\ORM\Tools\Export\ClassMetadataExporter,
Doctrine\ORM\Tools\EntityGenerator, Doctrine\ORM\Tools\EntityGenerator,
@ -147,4 +147,4 @@ EOT
$output->write('No Metadata Classes to process.' . PHP_EOL); $output->write('No Metadata Classes to process.' . PHP_EOL);
} }
} }
} }

View File

@ -21,9 +21,9 @@
namespace Doctrine\ORM\Tools\Console\Command; namespace Doctrine\ORM\Tools\Console\Command;
use Symfony\Components\Console\Input\InputArgument, use Symfony\Component\Console\Input\InputArgument,
Symfony\Components\Console\Input\InputOption, Symfony\Component\Console\Input\InputOption,
Symfony\Components\Console; Symfony\Component\Console;
/** /**
* Command to ensure that Doctrine is properly configured for a production environment. * Command to ensure that Doctrine is properly configured for a production environment.
@ -82,4 +82,4 @@ EOT
$output->write('<info>Environment is correctly configured for production.</info>' . PHP_EOL); $output->write('<info>Environment is correctly configured for production.</info>' . PHP_EOL);
} }
} }
} }

View File

@ -21,9 +21,9 @@
namespace Doctrine\ORM\Tools\Console\Command; namespace Doctrine\ORM\Tools\Console\Command;
use Symfony\Components\Console\Input\InputArgument, use Symfony\Component\Console\Input\InputArgument,
Symfony\Components\Console\Input\InputOption, Symfony\Component\Console\Input\InputOption,
Symfony\Components\Console, Symfony\Component\Console,
Doctrine\ORM\Tools\Console\MetadataFilter, Doctrine\ORM\Tools\Console\MetadataFilter,
Doctrine\ORM\Tools\EntityGenerator, Doctrine\ORM\Tools\EntityGenerator,
Doctrine\ORM\Tools\DisconnectedClassMetadataFactory; Doctrine\ORM\Tools\DisconnectedClassMetadataFactory;
@ -142,4 +142,4 @@ EOT
$output->write('No Metadata Classes to process.' . PHP_EOL); $output->write('No Metadata Classes to process.' . PHP_EOL);
} }
} }
} }

View File

@ -21,9 +21,9 @@
namespace Doctrine\ORM\Tools\Console\Command; namespace Doctrine\ORM\Tools\Console\Command;
use Symfony\Components\Console\Input\InputArgument, use Symfony\Component\Console\Input\InputArgument,
Symfony\Components\Console\Input\InputOption, Symfony\Component\Console\Input\InputOption,
Symfony\Components\Console, Symfony\Component\Console,
Doctrine\ORM\Tools\Console\MetadataFilter; Doctrine\ORM\Tools\Console\MetadataFilter;
/** /**
@ -112,4 +112,4 @@ EOT
} }
} }
} }

View File

@ -21,9 +21,9 @@
namespace Doctrine\ORM\Tools\Console\Command; namespace Doctrine\ORM\Tools\Console\Command;
use Symfony\Components\Console\Input\InputArgument, use Symfony\Component\Console\Input\InputArgument,
Symfony\Components\Console\Input\InputOption, Symfony\Component\Console\Input\InputOption,
Symfony\Components\Console, Symfony\Component\Console,
Doctrine\ORM\Tools\Console\MetadataFilter, Doctrine\ORM\Tools\Console\MetadataFilter,
Doctrine\ORM\Tools\EntityRepositoryGenerator; Doctrine\ORM\Tools\EntityRepositoryGenerator;
@ -113,4 +113,4 @@ EOT
$output->write('No Metadata Classes to process.' . PHP_EOL); $output->write('No Metadata Classes to process.' . PHP_EOL);
} }
} }
} }

View File

@ -21,9 +21,9 @@
namespace Doctrine\ORM\Tools\Console\Command; namespace Doctrine\ORM\Tools\Console\Command;
use Symfony\Components\Console\Input\InputArgument, use Symfony\Component\Console\Input\InputArgument,
Symfony\Components\Console\Input\InputOption, Symfony\Component\Console\Input\InputOption,
Symfony\Components\Console; Symfony\Component\Console;
/** /**
* Command to execute DQL queries in a given EntityManager. * Command to execute DQL queries in a given EntityManager.
@ -121,4 +121,4 @@ EOT
\Doctrine\Common\Util\Debug::dump($resultSet, $input->getOption('depth')); \Doctrine\Common\Util\Debug::dump($resultSet, $input->getOption('depth'));
} }
} }

View File

@ -21,11 +21,11 @@
namespace Doctrine\ORM\Tools\Console\Command\SchemaTool; namespace Doctrine\ORM\Tools\Console\Command\SchemaTool;
use Symfony\Components\Console\Input\InputArgument, use Symfony\Component\Console\Input\InputArgument,
Symfony\Components\Console\Input\InputOption, Symfony\Component\Console\Input\InputOption,
Symfony\Components\Console\Input\InputInterface, Symfony\Component\Console\Input\InputInterface,
Symfony\Components\Console\Output\OutputInterface, Symfony\Component\Console\Output\OutputInterface,
Symfony\Components\Console\Command\Command, Symfony\Component\Console\Command\Command,
Doctrine\ORM\Tools\Console\Helper\EntityManagerHelper, Doctrine\ORM\Tools\Console\Helper\EntityManagerHelper,
Doctrine\ORM\Tools\SchemaTool, Doctrine\ORM\Tools\SchemaTool,
Doctrine\ORM\Mapping\Driver\AbstractFileDriver; Doctrine\ORM\Mapping\Driver\AbstractFileDriver;
@ -61,4 +61,4 @@ abstract class AbstractCommand extends Command
$output->write('No Metadata Classes to process.' . PHP_EOL); $output->write('No Metadata Classes to process.' . PHP_EOL);
} }
} }
} }

View File

@ -21,10 +21,10 @@
namespace Doctrine\ORM\Tools\Console\Command\SchemaTool; namespace Doctrine\ORM\Tools\Console\Command\SchemaTool;
use Symfony\Components\Console\Input\InputArgument, use Symfony\Component\Console\Input\InputArgument,
Symfony\Components\Console\Input\InputOption, Symfony\Component\Console\Input\InputOption,
Symfony\Components\Console\Input\InputInterface, Symfony\Component\Console\Input\InputInterface,
Symfony\Components\Console\Output\OutputInterface, Symfony\Component\Console\Output\OutputInterface,
Doctrine\ORM\Tools\SchemaTool; Doctrine\ORM\Tools\SchemaTool;
/** /**
@ -74,4 +74,4 @@ EOT
$output->write('Database schema created successfully!' . PHP_EOL); $output->write('Database schema created successfully!' . PHP_EOL);
} }
} }
} }

View File

@ -21,10 +21,10 @@
namespace Doctrine\ORM\Tools\Console\Command\SchemaTool; namespace Doctrine\ORM\Tools\Console\Command\SchemaTool;
use Symfony\Components\Console\Input\InputArgument, use Symfony\Component\Console\Input\InputArgument,
Symfony\Components\Console\Input\InputOption, Symfony\Component\Console\Input\InputOption,
Symfony\Components\Console\Input\InputInterface, Symfony\Component\Console\Input\InputInterface,
Symfony\Components\Console\Output\OutputInterface, Symfony\Component\Console\Output\OutputInterface,
Doctrine\ORM\Tools\SchemaTool; Doctrine\ORM\Tools\SchemaTool;
/** /**
@ -75,4 +75,4 @@ EOT
$output->write('Database schema dropped successfully!' . PHP_EOL); $output->write('Database schema dropped successfully!' . PHP_EOL);
} }
} }
} }

View File

@ -21,10 +21,10 @@
namespace Doctrine\ORM\Tools\Console\Command\SchemaTool; namespace Doctrine\ORM\Tools\Console\Command\SchemaTool;
use Symfony\Components\Console\Input\InputArgument, use Symfony\Component\Console\Input\InputArgument,
Symfony\Components\Console\Input\InputOption, Symfony\Component\Console\Input\InputOption,
Symfony\Components\Console\Input\InputInterface, Symfony\Component\Console\Input\InputInterface,
Symfony\Components\Console\Output\OutputInterface, Symfony\Component\Console\Output\OutputInterface,
Doctrine\ORM\Tools\SchemaTool; Doctrine\ORM\Tools\SchemaTool;
/** /**
@ -83,4 +83,4 @@ EOT
$output->write('Database schema updated successfully!' . PHP_EOL); $output->write('Database schema updated successfully!' . PHP_EOL);
} }
} }
} }

View File

@ -21,9 +21,9 @@
namespace Doctrine\ORM\Tools\Console\Command; namespace Doctrine\ORM\Tools\Console\Command;
use Symfony\Components\Console\Input\InputArgument, use Symfony\Component\Console\Input\InputArgument,
Symfony\Components\Console\Input\InputOption, Symfony\Component\Console\Input\InputOption,
Symfony\Components\Console; Symfony\Component\Console;
/** /**
* Validate that the current mapping is valid * Validate that the current mapping is valid
@ -86,4 +86,4 @@ EOT
exit($exit); exit($exit);
} }
} }

View File

@ -21,7 +21,7 @@
namespace Doctrine\ORM\Tools\Console\Helper; namespace Doctrine\ORM\Tools\Console\Helper;
use Symfony\Components\Console\Helper\Helper, use Symfony\Component\Console\Helper\Helper,
Doctrine\ORM\EntityManager; Doctrine\ORM\EntityManager;
/** /**
@ -71,4 +71,4 @@ class EntityManagerHelper extends Helper
{ {
return 'entityManager'; return 'entityManager';
} }
} }

View File

@ -70,10 +70,10 @@ class ConvertDoctrine1Schema
if (is_dir($path)) { if (is_dir($path)) {
$files = glob($path . '/*.yml'); $files = glob($path . '/*.yml');
foreach ($files as $file) { foreach ($files as $file) {
$schema = array_merge($schema, (array) \Symfony\Components\Yaml\Yaml::load($file)); $schema = array_merge($schema, (array) \Symfony\Component\Yaml\Yaml::load($file));
} }
} else { } else {
$schema = array_merge($schema, (array) \Symfony\Components\Yaml\Yaml::load($path)); $schema = array_merge($schema, (array) \Symfony\Component\Yaml\Yaml::load($path));
} }
} }
@ -271,4 +271,4 @@ class ConvertDoctrine1Schema
} }
} }
} }
} }

View File

@ -44,7 +44,7 @@ class DisconnectedClassMetadataFactory extends ClassMetadataFactory
/** /**
* @override * @override
*/ */
protected function _newClassMetadataInstance($className) protected function newClassMetadataInstance($className)
{ {
return new ClassMetadataInfo($className); return new ClassMetadataInfo($className);
} }
@ -52,7 +52,7 @@ class DisconnectedClassMetadataFactory extends ClassMetadataFactory
/** /**
* @override * @override
*/ */
protected function _getParentClasses($name) protected function getParentClasses($name)
{ {
return array(); return array();
} }

View File

@ -198,6 +198,6 @@ class YamlExporter extends AbstractExporter
$array['lifecycleCallbacks'] = $metadata->lifecycleCallbacks; $array['lifecycleCallbacks'] = $metadata->lifecycleCallbacks;
} }
return \Symfony\Components\Yaml\Yaml::dump(array($metadata->name => $array), 10); return \Symfony\Component\Yaml\Yaml::dump(array($metadata->name => $array), 10);
} }
} }

View File

@ -1,22 +1,22 @@
<?php <?php
namespace Symfony\Components\Console; namespace Symfony\Component\Console;
use Symfony\Components\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputInterface;
use Symfony\Components\Console\Input\ArgvInput; use Symfony\Component\Console\Input\ArgvInput;
use Symfony\Components\Console\Input\ArrayInput; use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Components\Console\Input\InputDefinition; use Symfony\Component\Console\Input\InputDefinition;
use Symfony\Components\Console\Input\InputOption; use Symfony\Component\Console\Input\InputOption;
use Symfony\Components\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputArgument;
use Symfony\Components\Console\Output\OutputInterface; use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Components\Console\Output\Output; use Symfony\Component\Console\Output\Output;
use Symfony\Components\Console\Output\ConsoleOutput; use Symfony\Component\Console\Output\ConsoleOutput;
use Symfony\Components\Console\Command\Command; use Symfony\Component\Console\Command\Command;
use Symfony\Components\Console\Command\HelpCommand; use Symfony\Component\Console\Command\HelpCommand;
use Symfony\Components\Console\Command\ListCommand; use Symfony\Component\Console\Command\ListCommand;
use Symfony\Components\Console\Helper\HelperSet; use Symfony\Component\Console\Helper\HelperSet;
use Symfony\Components\Console\Helper\FormatterHelper; use Symfony\Component\Console\Helper\FormatterHelper;
use Symfony\Components\Console\Helper\DialogHelper; use Symfony\Component\Console\Helper\DialogHelper;
/* /*
* This file is part of the symfony framework. * This file is part of the symfony framework.

View File

@ -1,13 +1,13 @@
<?php <?php
namespace Symfony\Components\Console\Command; namespace Symfony\Component\Console\Command;
use Symfony\Components\Console\Input\InputDefinition; use Symfony\Component\Console\Input\InputDefinition;
use Symfony\Components\Console\Input\InputOption; use Symfony\Component\Console\Input\InputOption;
use Symfony\Components\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputArgument;
use Symfony\Components\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputInterface;
use Symfony\Components\Console\Output\OutputInterface; use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Components\Console\Application; use Symfony\Component\Console\Application;
/* /*
* This file is part of the symfony framework. * This file is part of the symfony framework.

View File

@ -1,13 +1,13 @@
<?php <?php
namespace Symfony\Components\Console\Command; namespace Symfony\Component\Console\Command;
use Symfony\Components\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputArgument;
use Symfony\Components\Console\Input\InputOption; use Symfony\Component\Console\Input\InputOption;
use Symfony\Components\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputInterface;
use Symfony\Components\Console\Output\OutputInterface; use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Components\Console\Output\Output; use Symfony\Component\Console\Output\Output;
use Symfony\Components\Console\Command\Command; use Symfony\Component\Console\Command\Command;
/* /*
* This file is part of the symfony framework. * This file is part of the symfony framework.

View File

@ -1,13 +1,13 @@
<?php <?php
namespace Symfony\Components\Console\Command; namespace Symfony\Component\Console\Command;
use Symfony\Components\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputArgument;
use Symfony\Components\Console\Input\InputOption; use Symfony\Component\Console\Input\InputOption;
use Symfony\Components\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputInterface;
use Symfony\Components\Console\Output\OutputInterface; use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Components\Console\Output\Output; use Symfony\Component\Console\Output\Output;
use Symfony\Components\Console\Command\Command; use Symfony\Component\Console\Command\Command;
/* /*
* This file is part of the symfony framework. * This file is part of the symfony framework.

View File

@ -1,8 +1,8 @@
<?php <?php
namespace Symfony\Components\Console\Helper; namespace Symfony\Component\Console\Helper;
use Symfony\Components\Console\Output\OutputInterface; use Symfony\Component\Console\Output\OutputInterface;
/* /*
* This file is part of the symfony framework. * This file is part of the symfony framework.

View File

@ -1,6 +1,6 @@
<?php <?php
namespace Symfony\Components\Console\Helper; namespace Symfony\Component\Console\Helper;
/* /*
* This file is part of the symfony framework. * This file is part of the symfony framework.

View File

@ -1,6 +1,6 @@
<?php <?php
namespace Symfony\Components\Console\Helper; namespace Symfony\Component\Console\Helper;
/* /*
* This file is part of the symfony framework. * This file is part of the symfony framework.

View File

@ -1,6 +1,6 @@
<?php <?php
namespace Symfony\Components\Console\Helper; namespace Symfony\Component\Console\Helper;
/* /*
* This file is part of the symfony framework. * This file is part of the symfony framework.

View File

@ -1,8 +1,8 @@
<?php <?php
namespace Symfony\Components\Console\Helper; namespace Symfony\Component\Console\Helper;
use Symfony\Components\Console\Command\Command; use Symfony\Component\Console\Command\Command;
/* /*
* This file is part of the symfony framework. * This file is part of the symfony framework.

View File

@ -1,6 +1,6 @@
<?php <?php
namespace Symfony\Components\Console\Input; namespace Symfony\Component\Console\Input;
/* /*
* This file is part of the symfony framework. * This file is part of the symfony framework.

View File

@ -1,6 +1,6 @@
<?php <?php
namespace Symfony\Components\Console\Input; namespace Symfony\Component\Console\Input;
/* /*
* This file is part of the symfony framework. * This file is part of the symfony framework.

View File

@ -1,6 +1,6 @@
<?php <?php
namespace Symfony\Components\Console\Input; namespace Symfony\Component\Console\Input;
/* /*
* This file is part of the symfony framework. * This file is part of the symfony framework.

View File

@ -1,6 +1,6 @@
<?php <?php
namespace Symfony\Components\Console\Input; namespace Symfony\Component\Console\Input;
/* /*
* This file is part of the symfony framework. * This file is part of the symfony framework.

View File

@ -1,6 +1,6 @@
<?php <?php
namespace Symfony\Components\Console\Input; namespace Symfony\Component\Console\Input;
/* /*
* This file is part of the symfony framework. * This file is part of the symfony framework.

View File

@ -1,6 +1,6 @@
<?php <?php
namespace Symfony\Components\Console\Input; namespace Symfony\Component\Console\Input;
/* /*
* This file is part of the symfony framework. * This file is part of the symfony framework.

View File

@ -1,6 +1,6 @@
<?php <?php
namespace Symfony\Components\Console\Input; namespace Symfony\Component\Console\Input;
/* /*
* This file is part of the symfony framework. * This file is part of the symfony framework.

View File

@ -1,6 +1,6 @@
<?php <?php
namespace Symfony\Components\Console\Input; namespace Symfony\Component\Console\Input;
/* /*
* This file is part of the symfony framework. * This file is part of the symfony framework.

View File

@ -1,6 +1,6 @@
<?php <?php
namespace Symfony\Components\Console\Output; namespace Symfony\Component\Console\Output;
/* /*
* This file is part of the symfony framework. * This file is part of the symfony framework.

View File

@ -1,6 +1,6 @@
<?php <?php
namespace Symfony\Components\Console\Output; namespace Symfony\Component\Console\Output;
/* /*
* This file is part of the symfony framework. * This file is part of the symfony framework.

View File

@ -1,6 +1,6 @@
<?php <?php
namespace Symfony\Components\Console\Output; namespace Symfony\Component\Console\Output;
/* /*
* This file is part of the symfony framework. * This file is part of the symfony framework.

View File

@ -1,6 +1,6 @@
<?php <?php
namespace Symfony\Components\Console\Output; namespace Symfony\Component\Console\Output;
/* /*
* This file is part of the symfony framework. * This file is part of the symfony framework.

View File

@ -1,6 +1,6 @@
<?php <?php
namespace Symfony\Components\Console\Output; namespace Symfony\Component\Console\Output;
/* /*
* This file is part of the symfony framework. * This file is part of the symfony framework.

View File

@ -1,10 +1,10 @@
<?php <?php
namespace Symfony\Components\Console; namespace Symfony\Component\Console;
use Symfony\Components\Console\Application; use Symfony\Component\Console\Application;
use Symfony\Components\Console\Input\StringInput; use Symfony\Component\Console\Input\StringInput;
use Symfony\Components\Console\Output\ConsoleOutput; use Symfony\Component\Console\Output\ConsoleOutput;
/* /*
* This file is part of the symfony framework. * This file is part of the symfony framework.

View File

@ -1,10 +1,10 @@
<?php <?php
namespace Symfony\Components\Console\Tester; namespace Symfony\Component\Console\Tester;
use Symfony\Components\Console\Application; use Symfony\Component\Console\Application;
use Symfony\Components\Console\Input\ArrayInput; use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Components\Console\Output\StreamOutput; use Symfony\Component\Console\Output\StreamOutput;
class ApplicationTester class ApplicationTester
{ {

View File

@ -1,10 +1,10 @@
<?php <?php
namespace Symfony\Components\Console\Tester; namespace Symfony\Component\Console\Tester;
use Symfony\Components\Console\Command\Command; use Symfony\Component\Console\Command\Command;
use Symfony\Components\Console\Input\ArrayInput; use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Components\Console\Output\StreamOutput; use Symfony\Component\Console\Output\StreamOutput;
class CommandTester class CommandTester
{ {

View File

@ -1,6 +1,6 @@
<?php <?php
namespace Symfony\Components\Yaml; namespace Symfony\Component\Yaml;
/* /*
* This file is part of the symfony package. * This file is part of the symfony package.

View File

@ -1,6 +1,6 @@
<?php <?php
namespace Symfony\Components\Yaml; namespace Symfony\Component\Yaml;
/* /*
* This file is part of the symfony package. * This file is part of the symfony package.

View File

@ -1,6 +1,6 @@
<?php <?php
namespace Symfony\Components\Yaml; namespace Symfony\Component\Yaml;
/* /*
* This file is part of the symfony package. * This file is part of the symfony package.

View File

@ -1,6 +1,6 @@
<?php <?php
namespace Symfony\Components\Yaml; namespace Symfony\Component\Yaml;
/* /*
* This file is part of the symfony package. * This file is part of the symfony package.

View File

@ -1,6 +1,6 @@
<?php <?php
namespace Symfony\Components\Yaml; namespace Symfony\Component\Yaml;
/* /*
* This file is part of the symfony package. * This file is part of the symfony package.

View File

@ -1,6 +1,6 @@
<?php <?php
namespace Symfony\Components\Yaml; namespace Symfony\Component\Yaml;
/* /*
* This file is part of the symfony package. * This file is part of the symfony package.

View File

@ -39,6 +39,7 @@ class CmsAddress
/** /**
* @OneToOne(targetEntity="CmsUser", inversedBy="address") * @OneToOne(targetEntity="CmsUser", inversedBy="address")
* @JoinColumn(referencedColumnName="id")
*/ */
public $user; public $user;

View File

@ -19,28 +19,6 @@ class QueryTest extends \Doctrine\Tests\OrmFunctionalTestCase
$this->useModelSet('cms'); $this->useModelSet('cms');
parent::setUp(); parent::setUp();
} }
/**
* @expectedException Doctrine\ORM\Query\QueryException
*/
public function testParameterIndexZeroThrowsException()
{
$query = $this->_em->createQuery("select u from Doctrine\Tests\Models\CMS\CmsUser u where u.username = ?1");
$query->execute(array(42)); // same as array(0 => 42), 0 is invalid parameter position
}
public function testGetParameters()
{
$query = $this->_em->createQuery("select u from Doctrine\Tests\Models\CMS\CmsUser u where u.username = ?1");
$this->assertEquals(array(), $query->getParameters());
}
public function testGetParameters_HasSomeAlready()
{
$query = $this->_em->createQuery("select u from Doctrine\Tests\Models\CMS\CmsUser u where u.username = ?1");
$query->setParameter(2, 84);
$this->assertEquals(array(2 => 84), $query->getParameters());
}
public function testSimpleQueries() public function testSimpleQueries()
{ {

View File

@ -19,7 +19,7 @@ class PostgreSqlSchemaToolTest extends \Doctrine\Tests\OrmFunctionalTestCase
public function testPostgresMetadataSequenceIncrementedBy10() public function testPostgresMetadataSequenceIncrementedBy10()
{ {
$address = $this->_em->getClassMetadata('Doctrine\Tests\Models\CMS\CmsAddress'); $address = $this->_em->getClassMetadata('Doctrine\Tests\Models\CMS\CmsAddress');
$this->assertEquals(10, $address->sequenceGeneratorDefinition['allocationSize']); $this->assertEquals(1, $address->sequenceGeneratorDefinition['allocationSize']);
} }
public function testGetCreateSchemaSql() public function testGetCreateSchemaSql()
@ -39,8 +39,8 @@ class PostgreSqlSchemaToolTest extends \Doctrine\Tests\OrmFunctionalTestCase
$this->assertEquals("CREATE UNIQUE INDEX cms_users_username_uniq ON cms_users (username)", $sql[3]); $this->assertEquals("CREATE UNIQUE INDEX cms_users_username_uniq ON cms_users (username)", $sql[3]);
$this->assertEquals("CREATE TABLE cms_users_groups (user_id INT NOT NULL, group_id INT NOT NULL, PRIMARY KEY(user_id, group_id))", $sql[4]); $this->assertEquals("CREATE TABLE cms_users_groups (user_id INT NOT NULL, group_id INT NOT NULL, PRIMARY KEY(user_id, group_id))", $sql[4]);
$this->assertEquals("CREATE TABLE cms_phonenumbers (phonenumber VARCHAR(50) NOT NULL, user_id INT DEFAULT NULL, PRIMARY KEY(phonenumber))", $sql[5]); $this->assertEquals("CREATE TABLE cms_phonenumbers (phonenumber VARCHAR(50) NOT NULL, user_id INT DEFAULT NULL, PRIMARY KEY(phonenumber))", $sql[5]);
$this->assertEquals("CREATE SEQUENCE cms_addresses_id_seq INCREMENT BY 10 MINVALUE 1 START 1", $sql[6]); $this->assertEquals("CREATE SEQUENCE cms_addresses_id_seq INCREMENT BY 1 MINVALUE 1 START 1", $sql[6]);
$this->assertEquals("CREATE SEQUENCE cms_users_id_seq INCREMENT BY 10 MINVALUE 1 START 1", $sql[7]); $this->assertEquals("CREATE SEQUENCE cms_users_id_seq INCREMENT BY 1 MINVALUE 1 START 1", $sql[7]);
$this->assertEquals("ALTER TABLE cms_addresses ADD FOREIGN KEY (user_id) REFERENCES cms_users(id) NOT DEFERRABLE INITIALLY IMMEDIATE", $sql[8]); $this->assertEquals("ALTER TABLE cms_addresses ADD FOREIGN KEY (user_id) REFERENCES cms_users(id) NOT DEFERRABLE INITIALLY IMMEDIATE", $sql[8]);
$this->assertEquals("ALTER TABLE cms_users_groups ADD FOREIGN KEY (user_id) REFERENCES cms_users(id) NOT DEFERRABLE INITIALLY IMMEDIATE", $sql[9]); $this->assertEquals("ALTER TABLE cms_users_groups ADD FOREIGN KEY (user_id) REFERENCES cms_users(id) NOT DEFERRABLE INITIALLY IMMEDIATE", $sql[9]);
$this->assertEquals("ALTER TABLE cms_users_groups ADD FOREIGN KEY (group_id) REFERENCES cms_groups(id) NOT DEFERRABLE INITIALLY IMMEDIATE", $sql[10]); $this->assertEquals("ALTER TABLE cms_users_groups ADD FOREIGN KEY (group_id) REFERENCES cms_groups(id) NOT DEFERRABLE INITIALLY IMMEDIATE", $sql[10]);
@ -61,7 +61,7 @@ class PostgreSqlSchemaToolTest extends \Doctrine\Tests\OrmFunctionalTestCase
$this->assertEquals(2, count($sql)); $this->assertEquals(2, count($sql));
$this->assertEquals('CREATE TABLE decimal_model (id INT NOT NULL, "decimal" NUMERIC(5, 2) NOT NULL, "high_scale" NUMERIC(14, 4) NOT NULL, PRIMARY KEY(id))', $sql[0]); $this->assertEquals('CREATE TABLE decimal_model (id INT NOT NULL, "decimal" NUMERIC(5, 2) NOT NULL, "high_scale" NUMERIC(14, 4) NOT NULL, PRIMARY KEY(id))', $sql[0]);
$this->assertEquals("CREATE SEQUENCE decimal_model_id_seq INCREMENT BY 10 MINVALUE 1 START 1", $sql[1]); $this->assertEquals("CREATE SEQUENCE decimal_model_id_seq INCREMENT BY 1 MINVALUE 1 START 1", $sql[1]);
} }
public function testGetCreateSchemaSql3() public function testGetCreateSchemaSql3()
@ -75,6 +75,6 @@ class PostgreSqlSchemaToolTest extends \Doctrine\Tests\OrmFunctionalTestCase
$this->assertEquals(2, count($sql)); $this->assertEquals(2, count($sql));
$this->assertEquals("CREATE TABLE boolean_model (id INT NOT NULL, booleanField BOOLEAN NOT NULL, PRIMARY KEY(id))", $sql[0]); $this->assertEquals("CREATE TABLE boolean_model (id INT NOT NULL, booleanField BOOLEAN NOT NULL, PRIMARY KEY(id))", $sql[0]);
$this->assertEquals("CREATE SEQUENCE boolean_model_id_seq INCREMENT BY 10 MINVALUE 1 START 1", $sql[1]); $this->assertEquals("CREATE SEQUENCE boolean_model_id_seq INCREMENT BY 1 MINVALUE 1 START 1", $sql[1]);
} }
} }

View File

@ -90,24 +90,6 @@ class AnnotationDriverTest extends AbstractMappingDriverTest
$this->assertNotContains($extraneousClassName, $classes); $this->assertNotContains($extraneousClassName, $classes);
} }
public function testInheritenceWithoutDiscriminatorMap()
{
$cm = new ClassMetadata('Doctrine\Tests\ORM\Mapping\ClassWithoutDiscriminatorMap');
$annotationDriver = $this->_loadDriver();
$this->setExpectedException("Doctrine\ORM\Mapping\MappingException");
$annotationDriver->loadMetadataForClass($cm->name, $cm);
}
public function testInheritenceWithoutDiscriminatorColumn()
{
$cm = new ClassMetadata('Doctrine\Tests\ORM\Mapping\ClassWithoutDiscriminatorColumn');
$annotationDriver = $this->_loadDriver();
$this->setExpectedException("Doctrine\ORM\Mapping\MappingException");
$annotationDriver->loadMetadataForClass($cm->name, $cm);
}
protected function _loadDriverForCMSModels() protected function _loadDriverForCMSModels()
{ {
$annotationDriver = $this->_loadDriver(); $annotationDriver = $this->_loadDriver();
@ -137,25 +119,3 @@ class ColumnWithoutType
/** @Id @Column */ /** @Id @Column */
public $id; public $id;
} }
/**
* @Entity
* @InheritanceType("SINGLE_TABLE")
* @DiscriminatorMap({"a" = "ClassWithoutDiscriminatorColumn"})
*/
class ClassWithoutDiscriminatorColumn
{
/** @Id @Column */
public $id;
}
/**
* @Entity
* @InheritanceType("SINGLE_TABLE")
* @DiscriminatorColumn(name="discr", type="string")
*/
class ClassWithoutDiscriminatorMap
{
/** @Id @Column */
public $id;
}

View File

@ -102,27 +102,27 @@ class ClassMetadataFactoryTest extends \Doctrine\Tests\OrmTestCase
/* Test subject class with overriden factory method for mocking purposes */ /* Test subject class with overriden factory method for mocking purposes */
class ClassMetadataFactoryTestSubject extends \Doctrine\ORM\Mapping\ClassMetadataFactory class ClassMetadataFactoryTestSubject extends \Doctrine\ORM\Mapping\ClassMetadataFactory
{ {
private $_mockMetadata = array(); private $mockMetadata = array();
private $_requestedClasses = array(); private $requestedClasses = array();
/** @override */ /** @override */
protected function _newClassMetadataInstance($className) protected function newClassMetadataInstance($className)
{ {
$this->_requestedClasses[] = $className; $this->requestedClasses[] = $className;
if ( ! isset($this->_mockMetadata[$className])) { if ( ! isset($this->mockMetadata[$className])) {
throw new InvalidArgumentException("No mock metadata found for class $className."); throw new InvalidArgumentException("No mock metadata found for class $className.");
} }
return $this->_mockMetadata[$className]; return $this->mockMetadata[$className];
} }
public function setMetadataForClass($className, $metadata) public function setMetadataForClass($className, $metadata)
{ {
$this->_mockMetadata[$className] = $metadata; $this->mockMetadata[$className] = $metadata;
} }
public function getRequestedClasses() public function getRequestedClasses()
{ {
return $this->_requestedClasses; return $this->requestedClasses;
} }
} }

View File

@ -102,9 +102,9 @@ class ClassMetadataTest extends \Doctrine\Tests\OrmTestCase
$assoc = $cm->associationMappings['groups']; $assoc = $cm->associationMappings['groups'];
//$this->assertTrue($assoc instanceof \Doctrine\ORM\Mapping\ManyToManyMapping); //$this->assertTrue($assoc instanceof \Doctrine\ORM\Mapping\ManyToManyMapping);
$this->assertEquals(array( $this->assertEquals(array(
'name' => 'CmsUser_CmsGroup', 'name' => 'cmsuser_cmsgroup',
'joinColumns' => array(array('name' => 'CmsUser_id', 'referencedColumnName' => 'id', 'onDelete' => 'CASCADE')), 'joinColumns' => array(array('name' => 'cmsuser_id', 'referencedColumnName' => 'id', 'onDelete' => 'CASCADE')),
'inverseJoinColumns' => array(array('name' => 'CmsGroup_id', 'referencedColumnName' => 'id', 'onDelete' => 'CASCADE')) 'inverseJoinColumns' => array(array('name' => 'cmsgroup_id', 'referencedColumnName' => 'id', 'onDelete' => 'CASCADE'))
), $assoc['joinTable']); ), $assoc['joinTable']);
$this->assertTrue($assoc['isOnDeleteCascade']); $this->assertTrue($assoc['isOnDeleteCascade']);
} }
@ -231,4 +231,49 @@ class ClassMetadataTest extends \Doctrine\Tests\OrmTestCase
$this->setExpectedException('Doctrine\ORM\Mapping\MappingException'); $this->setExpectedException('Doctrine\ORM\Mapping\MappingException');
$cm->mapField(array('fieldName' => 'name', 'columnName' => 'name')); $cm->mapField(array('fieldName' => 'name', 'columnName' => 'name'));
} }
public function testDefaultTableName()
{
$cm = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsUser');
// When table's name is not given
$primaryTable = array();
$cm->setPrimaryTable($primaryTable);
$this->assertEquals('CmsUser', $cm->getTableName());
$this->assertEquals('CmsUser', $cm->table['name']);
$cm = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsAddress');
// When joinTable's name is not given
$cm->mapManyToMany(array(
'fieldName' => 'user',
'targetEntity' => 'CmsUser',
'inversedBy' => 'users',
'joinTable' => array('joinColumns' => array(array('referencedColumnName' => 'id')),
'inverseJoinColumns' => array(array('referencedColumnName' => 'id')))));
$this->assertEquals('cmsaddress_cmsuser', $cm->associationMappings['user']['joinTable']['name']);
}
public function testDefaultJoinColumnName()
{
$cm = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsAddress');
// this is really dirty, but it's the simpliest way to test whether
// joinColumn's name will be automatically set to user_id
$cm->mapOneToOne(array(
'fieldName' => 'user',
'targetEntity' => 'CmsUser',
'joinColumns' => array(array('referencedColumnName' => 'id'))));
$this->assertEquals('user_id', $cm->associationMappings['user']['joinColumns'][0]['name']);
$cm = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsAddress');
$cm->mapManyToMany(array(
'fieldName' => 'user',
'targetEntity' => 'CmsUser',
'inversedBy' => 'users',
'joinTable' => array('name' => 'user_CmsUser',
'joinColumns' => array(array('referencedColumnName' => 'id')),
'inverseJoinColumns' => array(array('referencedColumnName' => 'id')))));
$this->assertEquals('cmsaddress_id', $cm->associationMappings['user']['joinTable']['joinColumns'][0]['name']);
$this->assertEquals('cmsuser_id', $cm->associationMappings['user']['joinTable']['inverseJoinColumns'][0]['name']);
}
} }

View File

@ -12,10 +12,10 @@ class YamlMappingDriverTest extends AbstractMappingDriverTest
{ {
protected function _loadDriver() protected function _loadDriver()
{ {
if (!class_exists('Symfony\Components\Yaml\Yaml', true)) { if (!class_exists('Symfony\Component\Yaml\Yaml', true)) {
$this->markTestSkipped('Please install Symfony YAML Component into the include path of your PHP installation.'); $this->markTestSkipped('Please install Symfony YAML Component into the include path of your PHP installation.');
} }
return new YamlDriver(__DIR__ . DIRECTORY_SEPARATOR . 'yaml'); return new YamlDriver(__DIR__ . DIRECTORY_SEPARATOR . 'yaml');
} }
} }

View File

@ -26,6 +26,7 @@ class AllTests
$suite->addTestSuite('Doctrine\Tests\ORM\Query\UpdateSqlGenerationTest'); $suite->addTestSuite('Doctrine\Tests\ORM\Query\UpdateSqlGenerationTest');
$suite->addTestSuite('Doctrine\Tests\ORM\Query\ExprTest'); $suite->addTestSuite('Doctrine\Tests\ORM\Query\ExprTest');
$suite->addTestSuite('Doctrine\Tests\ORM\Query\ParserResultTest'); $suite->addTestSuite('Doctrine\Tests\ORM\Query\ParserResultTest');
$suite->addTestSuite('Doctrine\Tests\ORM\Query\QueryTest');
return $suite; return $suite;
} }

View File

@ -0,0 +1,47 @@
<?php
namespace Doctrine\Tests\ORM\Query;
require_once __DIR__ . '/../../TestInit.php';
class QueryTest extends \Doctrine\Tests\OrmTestCase
{
protected $_em = null;
protected function setUp()
{
$this->_em = $this->_getTestEntityManager();
}
/**
* @expectedException Doctrine\ORM\Query\QueryException
*/
public function testParameterIndexZeroThrowsException()
{
$query = $this->_em->createQuery("select u from Doctrine\Tests\Models\CMS\CmsUser u where u.username = ?1");
$query->execute(array(42)); // same as array(0 => 42), 0 is invalid parameter position
}
public function testGetParameters()
{
$query = $this->_em->createQuery("select u from Doctrine\Tests\Models\CMS\CmsUser u where u.username = ?1");
$this->assertEquals(array(), $query->getParameters());
}
public function testGetParameters_HasSomeAlready()
{
$query = $this->_em->createQuery("select u from Doctrine\Tests\Models\CMS\CmsUser u where u.username = ?1");
$query->setParameter(2, 84);
$this->assertEquals(array(2 => 84), $query->getParameters());
}
public function testFree()
{
$query = $this->_em->createQuery("select u from Doctrine\Tests\Models\CMS\CmsUser u where u.username = ?1");
$query->setParameter(2, 84, \PDO::PARAM_INT);
$query->free();
$this->assertEquals(array(), $query->getParameters());
}
}

View File

@ -13,7 +13,7 @@ class ConvertDoctrine1SchemaCommandTest extends \Doctrine\Tests\OrmTestCase
$command = new ConvertDoctrine1SchemaCommand(); $command = new ConvertDoctrine1SchemaCommand();
$command->setEntityGenerator($entityGenerator); $command->setEntityGenerator($entityGenerator);
$output = $this->getMock('Symfony\Components\Console\Output\OutputInterface'); $output = $this->getMock('Symfony\Component\Console\Output\OutputInterface');
$output->expects($this->once()) $output->expects($this->once())
->method('write') ->method('write')
->with($this->equalTo('No Metadata Classes to process.' . PHP_EOL)); ->with($this->equalTo('No Metadata Classes to process.' . PHP_EOL));

View File

@ -61,7 +61,7 @@ class ConvertDoctrine1SchemaTest extends \Doctrine\Tests\OrmTestCase
public function testTest() public function testTest()
{ {
if ( ! class_exists('Symfony\Components\Yaml\Yaml', true)) { if ( ! class_exists('Symfony\Component\Yaml\Yaml', true)) {
$this->markTestSkipped('Please install Symfony YAML Component into the include path of your PHP installation.'); $this->markTestSkipped('Please install Symfony YAML Component into the include path of your PHP installation.');
} }
@ -100,4 +100,4 @@ class ConvertDoctrine1SchemaTest extends \Doctrine\Tests\OrmTestCase
unlink(__DIR__ . '/convert/Profile.dcm.yml'); unlink(__DIR__ . '/convert/Profile.dcm.yml');
rmdir(__DIR__ . '/convert'); rmdir(__DIR__ . '/convert');
} }
} }

View File

@ -37,10 +37,10 @@ class YamlClassMetadataExporterTest extends AbstractClassMetadataExporterTest
{ {
protected function _getType() protected function _getType()
{ {
if (!class_exists('Symfony\Components\Yaml\Yaml', true)) { if (!class_exists('Symfony\Component\Yaml\Yaml', true)) {
$this->markTestSkipped('Please install Symfony YAML Component into the include path of your PHP installation.'); $this->markTestSkipped('Please install Symfony YAML Component into the include path of your PHP installation.');
} }
return 'yaml'; return 'yaml';
} }
} }

View File

@ -18,7 +18,7 @@ $classLoader->register();
// Variable $helperSet is defined inside cli-config.php // Variable $helperSet is defined inside cli-config.php
require __DIR__ . '/cli-config.php'; require __DIR__ . '/cli-config.php';
$cli = new \Symfony\Components\Console\Application('Doctrine Command Line Interface', Doctrine\Common\Version::VERSION); $cli = new \Symfony\Component\Console\Application('Doctrine Command Line Interface', Doctrine\Common\Version::VERSION);
$cli->setCatchExceptions(true); $cli->setCatchExceptions(true);
$helperSet = $cli->getHelperSet(); $helperSet = $cli->getHelperSet();
foreach ($helpers as $name => $helper) { foreach ($helpers as $name => $helper) {
@ -46,4 +46,4 @@ $cli->addCommands(array(
new \Doctrine\ORM\Tools\Console\Command\ValidateSchemaCommand(), new \Doctrine\ORM\Tools\Console\Command\ValidateSchemaCommand(),
)); ));
$cli->run(); $cli->run();