Commit cb1c7bce authored by romanb's avatar romanb

[2.0] DBAL cleanups (DDC-46). Proxy class improvements (DDC-19, DDC-39)....

[2.0] DBAL cleanups (DDC-46). Proxy class improvements (DDC-19, DDC-39). Started new UPGRADE_TO document for upgrade instructions between advancing Doctrine 2 versions.
parent b9f74489
> **NOTE**
> This document does not describe how to upgrade from Doctrine 1.x to Doctrine 2 as this is a more
> complicated process.
# Upgrade from 2.0-ALPHA2 to 2.0-ALPHA3
This section details the changes made to Doctrine 2.0-ALPHA3 to make it easier for you
to upgrade your projects to use this version.
## Class loader changes
The behavior of the two class loaders in the Common package changed slightly for more flexibility. When registering a namespace you now need to include the last namespace separator as well, if you really want the prefix to be checked as a namespace and not only as the string. Examples:
[php]
// This loader would load classes in the Doctrine namespace but not classes in other
// namespaces that start with the string "Doctrine", like "DoctrineExtensions".
$isolatedLoader = new IsolatedClassLoader('Doctrine\\');
// or...
$globalLoader = new GlobalClassLoader;
$globalLoader->registerNamespace('Doctrine\\', '/path/to/doctrine');
## Proxy class changes
You are now required to make supply some minimalist configuration with regards to proxy objects. That involves 2 new configuration options. First, the directory where generated proxy classes should be placed needs to be specified. Secondly, you need to configure the namespace used for proxy classes. The following snippet shows an example:
[php]
// step 1: configure directory for proxy classes
// $config instanceof Doctrine\ORM\Configuration
$config->setProxyDir('/path/to/myproject/lib/MyProject/Generated/Proxies');
$config->setProxyNamespace('MyProject\Generated\Proxies');
Note that proxy classes behave exactly like any other classes when it comes to class loading. Therefore you need to make sure the proxy classes can be loaded by some class loader. If you place the generated proxy classes in a namespace and directory under your projects class files, like in the example above, it would be sufficient to register the MyProject namespace on a class loader. Since the proxy classes are contained in that namespace and adhere to the standards for class loading, no additional work is required.
Generating the proxy classes into a namespace within your class library is the recommended setup.
Entities with initialized proxy objects can now be serialized and unserialized properly from within the same application.
For more details refer to the Configuration section of the manual.
## Removed allowPartialObjects configuration option
The allowPartialObjects configuration option together with the `Configuration#getAllowPartialObjects` and `Configuration#setAllowPartialObjects` methods have been removed.
The new behavior is as if the option were set to FALSE all the time, basically disallowing partial objects globally. However, you can still use the `Query::HINT_FORCE_PARTIAL_LOAD` query hint to force a query to return partial objects for optimization purposes.
## Renamed Methods
* Doctrine\ORM\Configuration#getCacheDir() to getProxyDir()
* Doctrine\ORM\Configuration#setCacheDir($dir) to setProxyDir($dir)
# Upgrade from 2.0-ALPHA3 to 2.0-ALPHA4
-
......@@ -119,18 +119,13 @@ class GlobalClassLoader
if (($pos = strpos($className, $separator)) !== false) {
$prefix = substr($className, 0, strpos($className, $separator));
} else if (($pos = strpos($className, '_')) !== false) {
// Support for '_' namespace separator for compatibility with Zend/PEAR/...
// Support for '_' namespace separator for compatibility with the "old" standard
$prefix = substr($className, 0, strpos($className, '_'));
$separator = '_';
}
// Build the class file name
$class = ((isset($this->_basePaths[$prefix])) ?
$this->_basePaths[$prefix] . DIRECTORY_SEPARATOR : '')
require ((isset($this->_basePaths[$prefix])) ? $this->_basePaths[$prefix] . DIRECTORY_SEPARATOR : '')
. str_replace($separator, DIRECTORY_SEPARATOR, $className)
. (isset($this->_fileExtensions[$prefix]) ?
$this->_fileExtensions[$prefix] : $this->_defaultFileExtension);
require $class;
. (isset($this->_fileExtensions[$prefix]) ? $this->_fileExtensions[$prefix] : $this->_defaultFileExtension);
}
}
\ No newline at end of file
......@@ -104,11 +104,9 @@ class IsolatedClassLoader
return false;
}
// Build the class file name
$class = ($this->_basePath !== null ? $this->_basePath . DIRECTORY_SEPARATOR : '')
require ($this->_basePath !== null ? $this->_basePath . DIRECTORY_SEPARATOR : '')
. str_replace($this->_namespaceSeparator, DIRECTORY_SEPARATOR, $className)
. $this->_fileExtension;
require $class;
return true;
}
......
......@@ -22,11 +22,12 @@
namespace Doctrine\DBAL\Schema;
/**
* xxx
* Schema manager for the MySql RDBMS.
*
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
* @author Lukas Smith <smith@pooteeweet.org> (PEAR MDB2 library)
* @author Roman Borschel <roman@code-factory.org>
* @version $Revision$
* @since 2.0
*/
......@@ -85,7 +86,15 @@ class MySqlSchemaManager extends AbstractSchemaManager
{
return $database['Database'];
}
/**
* Gets a portable column definition.
*
* The database type is mapped to a corresponding Doctrine mapping type.
*
* @param $tableColumn
* @return array
*/
protected function _getPortableTableColumnDefinition($tableColumn)
{
$dbType = strtolower($tableColumn['Type']);
......@@ -110,42 +119,36 @@ class MySqlSchemaManager extends AbstractSchemaManager
$values = null;
$scale = null;
// Map db type to Doctrine mapping type
switch ($dbType) {
case 'tinyint':
$type = 'integer';
$type = 'boolean';
if (preg_match('/^(is|has)/', $tableColumn['name'])) {
$type = array_reverse($type);
}
$unsigned = preg_match('/ unsigned/i', $tableColumn['Type']);
$length = 1;
break;
$length = null;
break;
case 'smallint':
$type = 'integer';
$unsigned = preg_match('/ unsigned/i', $tableColumn['Type']);
$length = 2;
break;
$type = 'smallint';
$length = null;
break;
case 'mediumint':
$type = 'integer';
$unsigned = preg_match('/ unsigned/i', $tableColumn['Type']);
$length = 3;
break;
$length = null;
break;
case 'int':
case 'integer':
$type = 'integer';
$unsigned = preg_match('/ unsigned/i', $tableColumn['Type']);
$length = 4;
break;
$length = null;
break;
case 'bigint':
$type = 'integer';
$unsigned = preg_match('/ unsigned/i', $tableColumn['Type']);
$length = 8;
break;
$type = 'bigint';
$length = null;
break;
case 'tinytext':
case 'mediumtext':
case 'longtext':
case 'text':
case 'text':
$type = 'text';
$fixed = false;
break;
case 'varchar':
$fixed = false;
case 'string':
......@@ -156,8 +159,8 @@ class MySqlSchemaManager extends AbstractSchemaManager
if (preg_match('/^(is|has)/', $tableColumn['name'])) {
$type = array_reverse($type);
}
} elseif (strstr($dbType, 'text')) {
$type = 'clob';
} else if (strstr($dbType, 'text')) {
$type = 'text';
if ($decimal == 'binary') {
$type = 'blob';
}
......@@ -165,40 +168,28 @@ class MySqlSchemaManager extends AbstractSchemaManager
if ($fixed !== false) {
$fixed = true;
}
break;
break;
case 'set':
$fixed = false;
$type = 'text';
$type = 'integer';
break;
$type = 'integer'; //FIXME:???
break;
case 'date':
$type = 'date';
$length = null;
break;
break;
case 'datetime':
case 'timestamp':
$type = 'timestamp';
$length = null;
break;
$type = 'datetime';
break;
case 'time':
$type = 'time';
$length = null;
break;
break;
case 'float':
case 'double':
case 'real':
$type = 'float';
$unsigned = preg_match('/ unsigned/i', $tableColumn['type']);
break;
case 'unknown':
case 'decimal':
if ($decimal !== null) {
$scale = $decimal;
}
case 'numeric':
$type = 'decimal';
$unsigned = preg_match('/ unsigned/i', $tableColumn['type']);
break;
break;
case 'tinyblob':
case 'mediumblob':
case 'longblob':
......@@ -207,15 +198,12 @@ class MySqlSchemaManager extends AbstractSchemaManager
case 'varbinary':
$type = 'blob';
$length = null;
break;
break;
case 'year':
$type = 'integer';
$type = 'date';
$length = null;
break;
case 'bit':
$type = 'bit';
break;
break;
case 'geometry':
case 'geometrycollection':
case 'point':
......@@ -226,7 +214,7 @@ class MySqlSchemaManager extends AbstractSchemaManager
case 'multipolygon':
$type = 'blob';
$length = null;
break;
break;
default:
$type = 'string';
$length = null;
......
......@@ -79,13 +79,14 @@ class OracleSchemaManager extends AbstractSchemaManager
switch ($dbType) {
case 'integer':
case 'number':
$type = 'integer';
$length = null;
break;
case 'pls_integer':
case 'binary_integer':
if ($length == '1' && preg_match('/^(is|has)/', $tableColumn['column_name'])) {
$type = 'boolean';
} else {
$type = 'integer';
}
$type = 'boolean';
$length = null;
break;
case 'varchar':
case 'varchar2':
......@@ -104,28 +105,18 @@ class OracleSchemaManager extends AbstractSchemaManager
break;
case 'date':
case 'timestamp':
$type = 'timestamp';
$type = 'datetime';
$length = null;
break;
case 'float':
$type = 'float';
break;
case 'number':
if ( ! empty($tableColumn['data_scale'])) {
$type = 'decimal';
} else {
if ($length == '1' && preg_match('/^(is|has)/', $tableColumn['column_name'])) {
$type = 'boolean';
} else {
$type = 'integer';
}
}
$type = 'decimal';
$length = null;
break;
case 'long':
$type = 'string';
case 'clob':
case 'nclob':
$type = 'clob';
$type = 'text';
break;
case 'blob':
case 'raw':
......
......@@ -103,7 +103,7 @@ class PostgreSqlSchemaManager extends AbstractSchemaManager
$tableColumn['length'] = $length;
}
$matches = array();
$matches = array();
if (preg_match("/^nextval\('(.*)'(::.*)?\)$/", $tableColumn['default'], $matches)) {
$tableColumn['sequence'] = $matches[1];
......@@ -122,7 +122,7 @@ class PostgreSqlSchemaManager extends AbstractSchemaManager
$length = null;
}
$type = array();
$unsigned = $fixed = null;
$fixed = null;
if ( ! isset($tableColumn['name'])) {
$tableColumn['name'] = '';
......@@ -131,23 +131,10 @@ class PostgreSqlSchemaManager extends AbstractSchemaManager
$dbType = strtolower($tableColumn['type']);
switch ($dbType) {
case 'inet':
$type = 'inet';
break;
case 'bit':
case 'varbit':
$type = 'bit';
break;
case 'smallint':
case 'int2':
$type = 'integer';
$unsigned = false;
$length = 2;
if ($length == '2') {
if (preg_match('/^(is|has)/', $tableColumn['name'])) {
$type = 'boolean';
}
}
$type = 'smallint';
$length = null;
break;
case 'int':
case 'int4':
......@@ -155,21 +142,19 @@ class PostgreSqlSchemaManager extends AbstractSchemaManager
case 'serial':
case 'serial4':
$type = 'integer';
$unsigned = false;
$length = 4;
$length = null;
break;
case 'bigint':
case 'int8':
case 'bigserial':
case 'serial8':
$type = 'integer';
$unsigned = false;
$length = 8;
$type = 'bigint';
$length = null;
break;
case 'bool':
case 'boolean':
$type = 'boolean';
$length = 1;
$length = null;
break;
case 'text':
$fixed = false;
......@@ -203,7 +188,7 @@ class PostgreSqlSchemaManager extends AbstractSchemaManager
case 'timestamp':
case 'timetz':
case 'timestamptz':
$type = 'timestamp';
$type = 'datetime';
$length = null;
break;
case 'time':
......@@ -216,8 +201,6 @@ class PostgreSqlSchemaManager extends AbstractSchemaManager
case 'double':
case 'double precision':
case 'real':
$type = 'float';
break;
case 'decimal':
case 'money':
case 'numeric':
......@@ -254,7 +237,6 @@ class PostgreSqlSchemaManager extends AbstractSchemaManager
$decl = array(
'type' => $type,
'length' => $length,
'unsigned' => $unsigned,
'fixed' => $fixed
);
......
......@@ -106,36 +106,24 @@ class SqliteSchemaManager extends AbstractSchemaManager
$type = 'boolean';
break;
case 'tinyint':
if (preg_match('/^(is|has)/', $tableColumn['name'])) {
$type = 'boolean';
} else {
$type = 'integer';
}
$unsigned = preg_match('/ unsigned/i', $tableColumn['type']);
$length = 1;
$type = 'boolean';
$length = null;
break;
case 'smallint':
$type = 'integer';
$unsigned = preg_match('/ unsigned/i', $tableColumn['type']);
$length = 2;
$type = 'smallint';
$length = null;
break;
case 'mediumint':
$type = 'integer';
$unsigned = preg_match('/ unsigned/i', $tableColumn['type']);
$length = 3;
break;
case 'int':
case 'integer':
case 'serial':
$type = 'integer';
$unsigned = preg_match('/ unsigned/i', $tableColumn['type']);
$length = 4;
$length = null;
break;
case 'bigint':
case 'bigserial':
$type = 'integer';
$unsigned = preg_match('/ unsigned/i', $tableColumn['type']);
$length = 8;
$type = 'bigint';
$length = null;
break;
case 'clob':
$fixed = false;
......@@ -145,6 +133,8 @@ class SqliteSchemaManager extends AbstractSchemaManager
case 'mediumtext':
case 'longtext':
case 'text':
$type = 'text';
break;
case 'varchar':
case 'varchar2':
case 'nvarchar':
......@@ -172,7 +162,7 @@ class SqliteSchemaManager extends AbstractSchemaManager
break;
case 'datetime':
case 'timestamp':
$type = 'timestamp';
$type = 'datetime';
$length = null;
break;
case 'time':
......@@ -182,9 +172,6 @@ class SqliteSchemaManager extends AbstractSchemaManager
case 'float':
case 'double':
case 'real':
$type = 'float';
$length = null;
break;
case 'decimal':
case 'numeric':
$type = 'decimal';
......
......@@ -44,11 +44,13 @@ class Configuration extends \Doctrine\DBAL\Configuration
'queryCacheImpl' => null,
'metadataCacheImpl' => null,
'metadataDriverImpl' => null,
'cacheDir' => null,
'allowPartialObjects' => true,
'proxyDir' => null,
'allowPartialObjects' => true, //TODO: Remove
'useCExtension' => false,
'namedQueries' => array(),
'namedNativeQueries' => array()
'namedNativeQueries' => array(),
'autoGenerateProxyClasses' => true,
'proxyNamespace' => null
));
//TODO: Move this to client code to avoid unnecessary work when a different metadata
......@@ -65,6 +67,8 @@ class Configuration extends \Doctrine\DBAL\Configuration
* and you always only get what you explicitly query for.
*
* @return boolean Whether partial objects are allowed.
* @todo Remove
* @deprecated
*/
public function getAllowPartialObjects()
{
......@@ -78,6 +82,8 @@ class Configuration extends \Doctrine\DBAL\Configuration
* and you always only get what you explicitly query for.
*
* @param boolean $allowed Whether partial objects are allowed.
* @todo Remove
* @deprecated
*/
public function setAllowPartialObjects($allowed)
{
......@@ -85,23 +91,55 @@ class Configuration extends \Doctrine\DBAL\Configuration
}
/**
* Sets the directory where Doctrine writes any necessary cache files.
* Sets the directory where Doctrine generates any necessary proxy class files.
*
* @param string $dir
*/
public function setCacheDir($dir)
public function setProxyDir($dir)
{
$this->_attributes['cacheDir'] = $dir;
$this->_attributes['proxyDir'] = $dir;
}
/**
* Gets the directory where Doctrine writes any necessary cache files.
* Gets the directory where Doctrine generates any necessary proxy class files.
*
* @return string
*/
public function getCacheDir()
public function getProxyDir()
{
return $this->_attributes['cacheDir'];
return $this->_attributes['proxyDir'];
}
/**
* Gets a boolean flag that indicates whether proxy classes should always be regenerated
* during each script execution.
*
* @return boolean
*/
public function getAutoGenerateProxyClasses()
{
return $this->_attributes['autoGenerateProxyClasses'];
}
/**
* Sets a boolean flag that indicates whether proxy classes should always be regenerated
* during each script execution.
*
* @param boolean $bool
*/
public function setAutoGenerateProxyClasses($bool)
{
$this->_attributes['autoGenerateProxyClasses'] = $bool;
}
public function getProxyNamespace()
{
return $this->_attributes['proxyNamespace'];
}
public function setProxyNamespace($ns)
{
$this->_attributes['proxyNamespace'] = $ns;
}
/**
......@@ -251,4 +289,24 @@ class Configuration extends \Doctrine\DBAL\Configuration
{
return $this->_attributes['namedNativeQueries'][$name];
}
/**
* Ensures that this Configuration instance contains settings that are
* suitable for a production environment.
*
* @throws DoctrineException If a configuration setting has a value that is not
* suitable for a production environment.
*/
public function ensureProductionSettings()
{
if ( ! $this->_attributes['queryCacheImpl']) {
throw DoctrineException::queryCacheNotConfigured();
}
if ( ! $this->_attributes['metadataCacheImpl']) {
throw DoctrineException::metadataCacheNotConfigured();
}
if ($this->_attributes['autoGenerateProxyClasses']) {
throw DoctrineException::proxyClassesAlwaysRegenerating();
}
}
}
\ No newline at end of file
......@@ -26,17 +26,16 @@ use Doctrine\Common\EventManager,
Doctrine\DBAL\Connection,
Doctrine\ORM\Mapping\ClassMetadata,
Doctrine\ORM\Mapping\ClassMetadataFactory,
Doctrine\ORM\Proxy\ProxyFactory,
Doctrine\ORM\Proxy\ProxyClassGenerator;
Doctrine\ORM\Proxy\ProxyFactory;
/**
* The EntityManager is the central access point to ORM functionality.
*
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link www.doctrine-project.org
* @since 2.0
* @version $Revision$
* @author Roman Borschel <roman@code-factory.org>
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link www.doctrine-project.org
* @since 2.0
* @version $Revision$
* @author Roman Borschel <roman@code-factory.org>
*/
class EntityManager
{
......@@ -146,7 +145,10 @@ class EntityManager
$this->_metadataFactory = new ClassMetadataFactory($this);
$this->_metadataFactory->setCacheDriver($this->_config->getMetadataCacheImpl());
$this->_unitOfWork = new UnitOfWork($this);
$this->_proxyFactory = new ProxyFactory($this, new ProxyClassGenerator($this, $this->_config->getCacheDir()));
$this->_proxyFactory = new ProxyFactory($this,
$config->getProxyDir(),
$config->getProxyNamespace(),
$config->getAutoGenerateProxyClasses());
}
/**
......
......@@ -189,8 +189,7 @@ class OneToOneMapping extends AssociationMapping
* @param object $sourceEntity the entity source of this association
* @param object $targetEntity the entity to load data in
* @param EntityManager $em
* @param array $joinColumnValues values of the join columns of $sourceEntity. There are no fields
* to store this data in $sourceEntity
* @param array $joinColumnValues Values of the join columns of $sourceEntity.
*/
public function load($sourceEntity, $targetEntity, $em, array $joinColumnValues = array())
{
......
This diff is collapsed.
This diff is collapsed.
......@@ -90,6 +90,7 @@ class Cli
'run-sql' => $ns . '\RunSqlTask',
'run-dql' => $ns . '\RunDqlTask',
'convert-mapping' => $ns . '\ConvertMappingTask',
'generate-proxies'=> $ns . '\GenerateProxiesTask'
));
}
......
<?php
namespace Doctrine\ORM\Tools\Cli\Tasks;
/**
* Task to (re)generate the proxy classes used by doctrine.
*
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link www.doctrine-project.org
* @since 2.0
* @version $Revision: 3938 $
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
* @author Jonathan Wage <jonwage@gmail.com>
* @author Roman Borschel <roman@code-factory.org>
*/
class GenerateProxiesTask extends AbstractTask
{
/**
* @inheritdoc
*/
public function extendedHelp()
{
$printer = $this->getPrinter();
$printer->write('Task: ')->writeln('generate-proxies', 'KEYWORD')
->write('Synopsis: ');
$this->_writeSynopsis($printer);
$printer->writeln('Description: Generates proxy classes for entity classes.')
->writeln('Options:')
->write('--to-dir', 'OPT_ARG')
->writeln("\t\tGenerates the classes in the specified directory.")
->write(PHP_EOL);
}
/**
* @inheritdoc
*/
public function basicHelp()
{
$this->_writeSynopsis($this->getPrinter());
}
private function _writeSynopsis($printer)
{
$printer->write('generate-proxies', 'KEYWORD')
->writeln(' [--to-dir=<PATH>]', 'OPT_ARG');
}
/**
* @inheritdoc
*/
public function validate()
{
if ( ! parent::validate()) {
return false;
}
$args = $this->getArguments();
$printer = $this->getPrinter();
if ( ! $this->_requireEntityManager()) {
return false;
}
$metadataDriver = $this->_em->getConfiguration()->getMetadataDriverImpl();
if ($metadataDriver instanceof \Doctrine\ORM\Mapping\Driver\AnnotationDriver) {
if ( ! isset($args['class-dir'])) {
$printer->writeln("The supplied configuration uses the annotation metadata driver."
. " The 'class-dir' argument is required for this driver.", 'ERROR');
return false;
} else {
$metadataDriver->setClassDirectory($args['class-dir']);
}
}
return true;
}
/**
* Executes the task.
*/
public function run()
{
$args = $this->getArguments();
$cmf = $this->_em->getMetadataFactory();
$driver = $this->_em->getConfiguration()->getMetadataDriverImpl();
$classes = array();
$preloadedClasses = $driver->preload(true);
foreach ($preloadedClasses as $className) {
$classes[] = $cmf->getMetadataFor($className);
}
$printer = $this->getPrinter();
$factory = $this->_em->getProxyFactory();
if (empty($classes)) {
$printer->writeln('No classes to process.', 'INFO');
return;
}
$factory->generateProxyClasses($classes, isset($args['to-dir']) ? $args['to-dir'] : null);
$printer->writeln('Proxy classes generated to: ' .
(isset($args['to-dir']) ? $args['to-dir'] : $this->_em->getConfiguration()->getProxyDir())
);
}
}
\ No newline at end of file
......@@ -1331,12 +1331,10 @@ class UnitOfWork implements PropertyChangedListener
} else {
$assoc2 = $class->associationMappings[$name];
if ($assoc2->isOneToOne() && ! $assoc2->isCascadeMerge) {
//TODO: Only do this when allowPartialObjects == false?
$targetClass = $this->_em->getClassMetadata($assoc2->targetEntityName);
$prop->setValue($managedCopy, $this->_em->getProxyFactory()
->getReferenceProxy($assoc2->targetEntityName, $targetClass->getIdentifierValues($entity)));
} else {
//TODO: Only do this when allowPartialObjects == false?
$coll = new PersistentCollection($this->_em,
$this->_em->getClassMetadata($assoc2->targetEntityName),
new ArrayCollection
......
......@@ -54,7 +54,7 @@ class MySqlSchemaManagerTest extends SchemaManagerFunctionalTestCase
$this->assertEquals('id', $columns[0]['name']);
$this->assertEquals(true, $columns[0]['primary']);
$this->assertEquals('Doctrine\DBAL\Types\IntegerType', get_class($columns[0]['type']));
$this->assertEquals(4, $columns[0]['length']);
$this->assertEquals(null, $columns[0]['length']);
$this->assertEquals(false, $columns[0]['unsigned']);
$this->assertEquals(false, $columns[0]['fixed']);
$this->assertEquals(true, $columns[0]['notnull']);
......
......@@ -52,8 +52,7 @@ class PostgreSqlSchemaManagerTest extends SchemaManagerFunctionalTestCase
$this->assertEquals('id', $columns[0]['name']);
$this->assertEquals(true, $columns[0]['primary']);
$this->assertEquals('Doctrine\DBAL\Types\IntegerType', get_class($columns[0]['type']));
$this->assertEquals(4, $columns[0]['length']);
$this->assertEquals(false, $columns[0]['unsigned']);
$this->assertEquals(null, $columns[0]['length']);
$this->assertEquals(false, $columns[0]['fixed']);
$this->assertEquals(true, $columns[0]['notnull']);
$this->assertEquals(null, $columns[0]['default']);
......@@ -62,7 +61,6 @@ class PostgreSqlSchemaManagerTest extends SchemaManagerFunctionalTestCase
$this->assertEquals(false, $columns[1]['primary']);
$this->assertEquals('Doctrine\DBAL\Types\StringType', get_class($columns[1]['type']));
$this->assertEquals(255, $columns[1]['length']);
$this->assertEquals(false, $columns[1]['unsigned']);
$this->assertEquals(false, $columns[1]['fixed']);
$this->assertEquals(false, $columns[1]['notnull']);
$this->assertEquals(null, $columns[1]['default']);
......
......@@ -58,7 +58,7 @@ class SqliteSchemaManagerTest extends SchemaManagerFunctionalTestCase
$this->assertEquals('id', $tableColumns[0]['name']);
$this->assertEquals(true, $tableColumns[0]['primary']);
$this->assertEquals('Doctrine\DBAL\Types\IntegerType', get_class($tableColumns[0]['type']));
$this->assertEquals(4, $tableColumns[0]['length']);
$this->assertEquals(null, $tableColumns[0]['length']);
$this->assertEquals(false, $tableColumns[0]['unsigned']);
$this->assertEquals(false, $tableColumns[0]['fixed']);
$this->assertEquals(true, $tableColumns[0]['notnull']);
......@@ -140,7 +140,7 @@ class SqliteSchemaManagerTest extends SchemaManagerFunctionalTestCase
$this->assertEquals('id', $tableColumns[0]['name']);
$this->assertEquals(true, $tableColumns[0]['primary']);
$this->assertEquals('Doctrine\DBAL\Types\IntegerType', get_class($tableColumns[0]['type']));
$this->assertEquals(4, $tableColumns[0]['length']);
$this->assertEquals(null, $tableColumns[0]['length']);
$this->assertEquals(false, $tableColumns[0]['unsigned']);
$this->assertEquals(false, $tableColumns[0]['fixed']);
$this->assertEquals(true, $tableColumns[0]['notnull']);
......
......@@ -20,6 +20,7 @@
*/
namespace Doctrine\Tests\Mocks;
use Doctrine\ORM\Proxy\ProxyFactory;
/**
......@@ -75,6 +76,8 @@ class EntityManagerMock extends \Doctrine\ORM\EntityManager
{
if (is_null($config)) {
$config = new \Doctrine\ORM\Configuration();
$config->setProxyDir(__DIR__ . '/../Proxies');
$config->setProxyNamespace('Doctrine\Tests\Proxies');
}
if (is_null($eventManager)) {
$eventManager = new \Doctrine\Common\EventManager();
......
......@@ -92,6 +92,7 @@ class OneToOneBidirectionalAssociationTest extends \Doctrine\Tests\OrmFunctional
$this->assertNull($customer->getMentor());
$this->assertTrue($customer->getCart() instanceof ECommerceCart);
$this->assertTrue($customer->getCart() instanceof \Doctrine\ORM\Proxy\Proxy);
$this->assertEquals('paypal', $customer->getCart()->getPayment());
}
......
......@@ -20,7 +20,11 @@ class ReferenceProxyTest extends \Doctrine\Tests\OrmFunctionalTestCase
{
$this->useModelSet('ecommerce');
parent::setUp();
$this->_factory = new ProxyFactory($this->_em, new ProxyClassGenerator($this->_em));
$this->_factory = new ProxyFactory(
$this->_em,
__DIR__ . '/../../Proxies',
'Doctrine\Tests\Proxies',
true);
}
public function testLazyLoadsFieldValuesFromDatabase()
......
......@@ -18,6 +18,8 @@ class ClassMetadataFactoryTest extends \Doctrine\Tests\OrmTestCase
{
$driverMock = new DriverMock();
$config = new \Doctrine\ORM\Configuration();
$config->setProxyDir(__DIR__ . '/../../Proxies');
$config->setProxyNamespace('Doctrine\Tests\Proxies');
$eventManager = new EventManager();
$conn = new ConnectionMock(array(), $driverMock, $config, $eventManager);
$mockDriver = new MetadataDriverMock();
......
......@@ -167,6 +167,8 @@ class OrmFunctionalTestCase extends OrmTestCase
$config = new \Doctrine\ORM\Configuration();
$config->setMetadataCacheImpl(self::$_metadataCacheImpl);
$config->setQueryCacheImpl(self::$_queryCacheImpl);
$config->setProxyDir(__DIR__ . '/Proxies');
$config->setProxyNamespace('Doctrine\Tests\Proxies');
$conn = $this->sharedFixture['conn'];
return \Doctrine\ORM\EntityManager::create($conn, $config);
......
......@@ -27,6 +27,8 @@ class OrmTestCase extends DoctrineTestCase
$config = new \Doctrine\ORM\Configuration();
$config->setMetadataCacheImpl(self::getSharedMetadataCacheImpl());
$config->setQueryCacheImpl(self::getSharedQueryCacheImpl());
$config->setProxyDir(__DIR__ . '/Proxies');
$config->setProxyNamespace('Doctrine\Tests\Proxies');
$eventManager = new \Doctrine\Common\EventManager();
if ($conn === null) {
$conn = array(
......
......@@ -19,8 +19,14 @@ $classLoader = new \Doctrine\Common\IsolatedClassLoader('Entities');
$classLoader->setBasePath(__DIR__);
$classLoader->register();
$classLoader = new \Doctrine\Common\IsolatedClassLoader('Proxies');
$classLoader->setBasePath(__DIR__);
$classLoader->register();
$config = new \Doctrine\ORM\Configuration();
$config->setMetadataCacheImpl(new \Doctrine\Common\Cache\ArrayCache);
$config->setProxyDir(__DIR__ . '/Proxies');
$config->setProxyNamespace('Proxies');
$connectionOptions = array(
'driver' => 'pdo_sqlite',
......
<?php
/**
* Welcome to Doctrine 2.
*
* This is the index file of the sandbox. The first section of this file
* demonstrates the bootstrapping and configuration procedure of Doctrine 2.
* Below that section you can place your test code and experiment.
*/
namespace Sandbox;
use Entities\User, Entities\Address;
use Doctrine\ORM\Configuration,
Doctrine\ORM\EntityManager,
Doctrine\Common\Cache\ApcCache,
Entities\User, Entities\Address;
require '../../lib/Doctrine/Common/GlobalClassLoader.php';
// Set up class loading, we could alternatively use 2 IsolatedClassLoaders
// Set up class loading, we could alternatively use several IsolatedClassLoaders.
// You could also use different autoloaders, provided by your favorite framework.
$classLoader = new \Doctrine\Common\GlobalClassLoader();
$classLoader->registerNamespace('Doctrine', realpath(__DIR__ . '/../../lib'));
$classLoader->registerNamespace('Entities', __DIR__);
$classLoader->registerNamespace('Proxies', __DIR__);
$classLoader->register();
// Set up caches
$config = new \Doctrine\ORM\Configuration;
$cache = new \Doctrine\Common\Cache\ApcCache;
$config = new Configuration;
$cache = new ApcCache;
$config->setMetadataCacheImpl($cache);
$config->setQueryCacheImpl($cache);
// Proxy configuration
$config->setProxyDir(__DIR__ . '/Proxies');
$config->setProxyNamespace('Proxies');
// Database connection information
$connectionOptions = array(
'driver' => 'pdo_sqlite',
......@@ -25,11 +41,11 @@ $connectionOptions = array(
);
// Create EntityManager
$em = \Doctrine\ORM\EntityManager::create($connectionOptions, $config);
$em = EntityManager::create($connectionOptions, $config);
## PUT YOUR TEST CODE BELOW
$user = new User;
$address = new Address;
echo 'Hello World!';
\ No newline at end of file
echo 'Hello World!' . PHP_EOL;
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment