1
0
mirror of synced 2024-12-14 07:06:04 +03:00

Merged from upstream/master.

This commit is contained in:
Roman S. Borschel 2010-04-14 17:21:15 +02:00
commit f3c672a2e5
11 changed files with 290 additions and 533 deletions

View File

@ -1,7 +1,5 @@
<?php <?php
/* /*
* $Id$
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
@ -30,10 +28,7 @@ use Doctrine\ORM\ORMException,
* metadata mapping informations of a class which describes how a class should be mapped * metadata mapping informations of a class which describes how a class should be mapped
* to a relational database. * to a relational database.
* *
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link www.doctrine-project.org
* @since 2.0 * @since 2.0
* @version $Revision$
* @author Benjamin Eberlei <kontakt@beberlei.de> * @author Benjamin Eberlei <kontakt@beberlei.de>
* @author Guilherme Blanco <guilhermeblanco@hotmail.com> * @author Guilherme Blanco <guilhermeblanco@hotmail.com>
* @author Jonathan Wage <jonwage@gmail.com> * @author Jonathan Wage <jonwage@gmail.com>
@ -190,7 +185,25 @@ class ClassMetadataFactory
{ {
$this->_loadedMetadata[$className] = $class; $this->_loadedMetadata[$className] = $class;
} }
/**
* Get array of parent classes for the given entity class
*
* @param string $name
* @return array $parentClasses
*/
protected function _getParentClasses($name)
{
// Collect parent classes, ignoring transient (not-mapped) classes.
$parentClasses = array();
foreach (array_reverse(class_parents($name)) as $parentClass) {
if ( ! $this->_driver->isTransient($parentClass)) {
$parentClasses[] = $parentClass;
}
}
return $parentClasses;
}
/** /**
* Loads the metadata of the class in question and all it's ancestors whose metadata * Loads the metadata of the class in question and all it's ancestors whose metadata
* is still not loaded. * is still not loaded.
@ -206,13 +219,7 @@ class ClassMetadataFactory
$loaded = array(); $loaded = array();
// Collect parent classes, ignoring transient (not-mapped) classes. $parentClasses = $this->_getParentClasses($name);
$parentClasses = array();
foreach (array_reverse(class_parents($name)) as $parentClass) {
if ( ! $this->_driver->isTransient($parentClass)) {
$parentClasses[] = $parentClass;
}
}
$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
@ -353,7 +360,7 @@ class ClassMetadataFactory
* *
* @param Doctrine\ORM\Mapping\ClassMetadata $class * @param Doctrine\ORM\Mapping\ClassMetadata $class
*/ */
private function _completeIdGeneratorMapping(ClassMetadata $class) private function _completeIdGeneratorMapping(ClassMetadataInfo $class)
{ {
$idGenType = $class->generatorType; $idGenType = $class->generatorType;
if ($idGenType == ClassMetadata::GENERATOR_TYPE_AUTO) { if ($idGenType == ClassMetadata::GENERATOR_TYPE_AUTO) {

View File

@ -1,287 +0,0 @@
<?php
/*
* $Id$
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information, see
* <http://www.doctrine-project.org>.
*/
namespace Doctrine\ORM\Tools;
use Doctrine\ORM\Mapping\ClassMetadataInfo,
Doctrine\ORM\Mapping\ClassMetadata,
Doctrine\ORM\Mapping\MappingException,
Doctrine\ORM\Mapping\Driver\Driver,
Doctrine\ORM\Mapping\Driver\AnnotationDriver,
Doctrine\ORM\EntityManager,
Doctrine\ORM\Tools\Export\ExportException;
/**
* Class to read metadata mapping information from multiple sources into an array
* of ClassMetadataInfo instances.
*
* The difference between this class and the ClassMetadataFactory is that this
* is just a tool for reading in the mapping information from files without
* having it bound to the actual ORM and the mapping information referenced by
* the EntityManager. This allows us to read any source of mapping information
* and return a single array of aggregated ClassMetadataInfo instances.
*
* These arrays are used for exporting the mapping information to the supported
* mapping drivers, generating entities, generating repositories, etc.
*
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link www.doctrine-project.org
* @since 2.0
* @version $Revision$
* @author Benjamin Eberlei <kontakt@beberlei.de>
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
* @author Jonathan Wage <jonwage@gmail.com>
* @author Roman Borschel <roman@code-factory.org>
*/
class ClassMetadataReader
{
private static $_mappingDrivers = array(
'annotation' => 'Doctrine\ORM\Mapping\Driver\AnnotationDriver',
'yaml' => 'Doctrine\ORM\Mapping\Driver\YamlDriver',
'yml' => 'Doctrine\ORM\Mapping\Driver\YamlDriver',
'xml' => 'Doctrine\ORM\Mapping\Driver\XmlDriver',
'php' => 'Doctrine\ORM\Mapping\Driver\PhpDriver',
'database' => 'Doctrine\ORM\Mapping\Driver\DatabaseDriver'
);
private $_mappingSources = array();
private $_em;
/**
* Register a new mapping driver class under a specified name
*
* @param string $name
* @param string $class
*/
public static function registerMappingDriver($name, $class)
{
self::$_mappingDrivers[$name] = $class;
}
/**
* Optionally set the EntityManager instance to get the AnnotationDriver
* from instead of creating a new instance of the AnnotationDriver
*
* @param EntityManager $em
* @return void
*/
public function setEntityManager(EntityManager $em)
{
$this->_em = $em;
}
/**
* Get an array of ClassMetadataInfo instances for all the configured mapping
* directories. Reads the mapping directories and populates ClassMetadataInfo
* instances.
*
* If you specify $autoload = true then this method will return ClassMetadata
* instances instead of ClassMetadataInfo instances. Keep in mind that if you
* specify it to autoload and it doesn't find the class your autoloader may
* throw an error.
*
* @param bool $autoload Whether or to try and autoload the classes
* @return array $classes
*/
public function getMetadatas($autoload = false)
{
$classes = array();
foreach ($this->_mappingSources as $d) {
list($source, $driver) = $d;
$allClasses = $driver->getAllClassNames();
foreach ($allClasses as $className) {
if (class_exists($className, $autoload)) {
$metadata = new ClassMetadata($className);
} else {
$metadata = new ClassMetadataInfo($className);
}
$driver->loadMetadataForClass($className, $metadata);
if ( ! $metadata->isMappedSuperclass) {
$classes[$metadata->name] = $metadata;
}
}
}
return $classes;
}
/**
* Add a new mapping directory to the array of directories to convert and export
* to another format
*
* @param string $source The source for the mapping
* @param string $type The type of mapping files (yml, xml, etc.)
* @return void
*/
public function addMappingSource($source, $type = null)
{
if ($type === null) {
$type = $this->_determineSourceType($source);
}
if ( ! isset(self::$_mappingDrivers[$type])) {
throw ExportException::invalidMappingDriverType($type);
}
$source = $this->_getSourceByType($type, $source);
$driver = $this->_getMappingDriver($type, $source);
$this->_mappingSources[] = array($source, $driver);
}
/**
* Get an instance of a mapping driver
*
* @param string $type The type of mapping driver (yaml, xml, annotation, etc.)
* @param string $source The source for the driver
* @return AbstractDriver $driver
*/
private function _getMappingDriver($type, $source = null)
{
if ($source instanceof \Doctrine\ORM\Mapping\Driver\Driver) {
return $source;
}
if ( ! isset(self::$_mappingDrivers[$type])) {
return false;
}
$class = self::$_mappingDrivers[$type];
if (is_subclass_of($class, 'Doctrine\ORM\Mapping\Driver\AbstractFileDriver')) {
if (is_null($source)) {
throw MappingException::fileMappingDriversRequireConfiguredDirectoryPath();
}
$driver = new $class($source);
} else if ($class == 'Doctrine\ORM\Mapping\Driver\AnnotationDriver') {
$reader = new \Doctrine\Common\Annotations\AnnotationReader(new \Doctrine\Common\Cache\ArrayCache);
$reader->setDefaultAnnotationNamespace('Doctrine\ORM\Mapping\\');
$driver = new \Doctrine\ORM\Mapping\Driver\AnnotationDriver($reader, $source);
} else {
$driver = new $class($source);
}
return $driver;
}
private function _determineSourceType($source)
{
if ($source instanceof \Doctrine\ORM\Mapping\Driver\Driver) {
$type = array_search(get_class($source), self::$_mappingDrivers);
return $type;
// If the --from=<VALUE> is a directory lets determine if it is
// annotations, yaml, xml, etc.
} else if (is_dir($source)) {
$source = realpath($source);
// Find the files in the directory
$files = glob($source . '/*.*');
if ( ! $files) {
throw new \InvalidArgumentException(
sprintf('No mapping files found in "%s"', $source)
);
}
// Get the contents of the first file
$contents = file_get_contents($files[0]);
// Check if it has a class definition in it for annotations
if (preg_match("/class (.*)/", $contents)) {
return 'annotation';
// Otherwise lets determine the type based on the extension of the
// first file in the directory (yml, xml, etc)
} else {
$info = pathinfo($files[0]);
return $info['extension'];
}
// Nothing special for database
} else if ($source == 'database') {
return 'database';
}
}
private function _getSourceByType($type, $source)
{
// If --from==database then the source is an instance of SchemaManager
// for the current EntityManager
if ($type == 'database') {
if ($source instanceof \Doctrine\ORM\Mapping\Driver\DatabaseDriver) {
return $source;
} else if ($this->_em) {
return $this->_em->getConnection()->getSchemaManager();
}
// If source is annotation then lets try and find the existing annotation
// driver for the source instead of re-creating a new instance
} else if ($type == 'annotation') {
if ($this->_em) {
$metadataDriverImpl = $this->_em->getConfiguration()->getMetadataDriverImpl();
// Find the annotation driver in the chain of drivers
if ($metadataDriverImpl instanceof DriverChain) {
foreach ($metadataDriverImpl->getDrivers() as $namespace => $driver) {
if ($this->_isAnnotationDriverForPath($driver, $source)) {
return $driver;
}
}
} else if ($this->_isAnnotationDriverForPath($metadataDriverImpl, $source)) {
return $metadataDriverImpl;
} else if ($metadataDriverImpl instanceof AnnotationDriver) {
$metadataDriverImpl->addPaths(array($source));
return $metadataDriverImpl;
} else {
return $source;
}
} else {
return $source;
}
} else {
return $source;
}
}
/**
* Check to see if the given metadata driver is the annotation driver for the
* given directory path
*
* @param Driver $driver
* @param string $path
* @return boolean
*/
private function _isAnnotationDriverForPath(Driver $driver, $path)
{
if ( ! $driver instanceof AnnotationDriver) {
return false;
}
if (in_array(realpath($path), $driver->getPaths())) {
return true;
} else {
return false;
}
}
}

View File

@ -25,7 +25,9 @@ use Symfony\Components\Console\Input\InputArgument,
Symfony\Components\Console\Input\InputOption, Symfony\Components\Console\Input\InputOption,
Symfony\Components\Console, Symfony\Components\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\DisconnectedClassMetadataFactory;
/** /**
* Command to convert your mapping information between the various formats. * Command to convert your mapping information between the various formats.
@ -94,7 +96,8 @@ EOT
); );
} }
$metadatas = $em->getMetadataFactory()->getAllMetadata(); $cmf = new DisconnectedClassMetadataFactory($em);
$metadatas = $cmf->getAllMetadata();
$metadatas = MetadataFilter::filter($metadatas, $input->getOption('filter')); $metadatas = MetadataFilter::filter($metadatas, $input->getOption('filter'));
// Process destination directory // Process destination directory

View File

@ -25,7 +25,8 @@ use Symfony\Components\Console\Input\InputArgument,
Symfony\Components\Console\Input\InputOption, Symfony\Components\Console\Input\InputOption,
Symfony\Components\Console, Symfony\Components\Console,
Doctrine\ORM\Tools\Console\MetadataFilter, Doctrine\ORM\Tools\Console\MetadataFilter,
Doctrine\ORM\Tools\EntityGenerator; Doctrine\ORM\Tools\EntityGenerator,
Doctrine\ORM\Tools\DisconnectedClassMetadataFactory;
/** /**
* Command to generate entity classes and method stubs from your mapping information. * Command to generate entity classes and method stubs from your mapping information.
@ -95,7 +96,8 @@ EOT
{ {
$em = $this->getHelper('em')->getEntityManager(); $em = $this->getHelper('em')->getEntityManager();
$metadatas = $em->getMetadataFactory()->getAllMetadata(); $cmf = new DisconnectedClassMetadataFactory($em);
$metadatas = $cmf->getAllMetadata();
$metadatas = MetadataFilter::filter($metadatas, $input->getOption('filter')); $metadatas = MetadataFilter::filter($metadatas, $input->getOption('filter'));
// Process destination directory // Process destination directory

View File

@ -62,7 +62,7 @@ class ConvertDoctrine1Schema
* *
* @return array $metadatas An array of ClassMetadataInfo instances * @return array $metadatas An array of ClassMetadataInfo instances
*/ */
public function getMetadatas() public function getMetadata()
{ {
$schema = array(); $schema = array();
foreach ($this->_from as $path) { foreach ($this->_from as $path) {

View File

@ -0,0 +1,59 @@
<?php
/*
* $Id$
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information, see
* <http://www.doctrine-project.org>.
*/
namespace Doctrine\ORM\Tools;
use Doctrine\ORM\Mapping\ClassMetadataFactory;
use Doctrine\ORM\Mapping\ClassMetadataInfo;
/**
* The DisconnectedClassMetadataFactory is used to create ClassMetadataInfo objects
* that do not require the entity class actually exist. This allows us to
* load some mapping information and use it to do things like generate code
* from the mapping information.
*
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link www.doctrine-project.org
* @since 2.0
* @version $Revision$
* @author Benjamin Eberlei <kontakt@beberlei.de>
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
* @author Jonathan Wage <jonwage@gmail.com>
* @author Roman Borschel <roman@code-factory.org>
*/
class DisconnectedClassMetadataFactory extends ClassMetadataFactory
{
/**
* @override
*/
protected function _newClassMetadataInstance($className)
{
return new ClassMetadataInfo($className);
}
/**
* @override
*/
protected function _getParentClasses($name)
{
return array();
}
}

View File

@ -22,29 +22,13 @@
namespace Doctrine\ORM\Tools\Export; namespace Doctrine\ORM\Tools\Export;
use Doctrine\ORM\Tools\ClassMetadataReader, use Doctrine\ORM\Tools\Export\ExportException,
Doctrine\ORM\Tools\Export\ExportException,
Doctrine\ORM\EntityManager; Doctrine\ORM\EntityManager;
/** /**
* Class used for converting your mapping information between the * Class used for converting your mapping information between the
* supported formats: yaml, xml, and php/annotation. * supported formats: yaml, xml, and php/annotation.
* *
* [php]
* // Unify all your mapping information which is written in php, xml, yml
* // and convert it to a single set of yaml files.
*
* $cme = new Doctrine\ORM\Tools\Export\ClassMetadataExporter();
* $cme->addMappingSource(__DIR__ . '/Entities');
* $cme->addMappingSource(__DIR__ . '/xml');
* $cme->addMappingSource(__DIR__ . '/yaml');
*
* $exporter = $cme->getExporter('yaml');
* $exporter->setOutputDir(__DIR__ . '/new_yaml');
*
* $exporter->setMetadatas($cme->getMetadatas());
* $exporter->export();
*
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL * @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link www.doctrine-project.org * @link www.doctrine-project.org
* @since 2.0 * @since 2.0
@ -61,11 +45,6 @@ class ClassMetadataExporter
'annotation' => 'Doctrine\ORM\Tools\Export\Driver\AnnotationExporter' 'annotation' => 'Doctrine\ORM\Tools\Export\Driver\AnnotationExporter'
); );
public function __construct()
{
$this->_reader = new ClassMetadataReader();
}
/** /**
* Register a new exporter driver class under a specified name * Register a new exporter driver class under a specified name
* *
@ -77,18 +56,6 @@ class ClassMetadataExporter
self::$_exporterDrivers[$name] = $class; self::$_exporterDrivers[$name] = $class;
} }
/**
* Optionally set the EntityManager instance to get the AnnotationDriver
* from instead of creating a new instance of the AnnotationDriver
*
* @param EntityManager $em
* @return void
*/
public function setEntityManager(EntityManager $em)
{
$this->_reader->setEntityManager($em);
}
/** /**
* Get a exporter driver instance * Get a exporter driver instance
* *
@ -96,7 +63,7 @@ class ClassMetadataExporter
* @param string $source The directory where the exporter will export to * @param string $source The directory where the exporter will export to
* @return AbstractExporter $exporter * @return AbstractExporter $exporter
*/ */
public function getExporter($type, $source = null) public function getExporter($type, $dest)
{ {
if ( ! isset(self::$_exporterDrivers[$type])) { if ( ! isset(self::$_exporterDrivers[$type])) {
throw ExportException::invalidExporterDriverType($type); throw ExportException::invalidExporterDriverType($type);
@ -104,36 +71,6 @@ class ClassMetadataExporter
$class = self::$_exporterDrivers[$type]; $class = self::$_exporterDrivers[$type];
return new $class($source); return new $class($dest);
}
/**
* Add a new mapping directory to the array of directories to convert and export
* to another format
*
* [php]
* $cme = new Doctrine\ORM\Tools\Export\ClassMetadataExporter();
* $cme->addMappingSource(__DIR__ . '/yaml');
* $cme->addMappingSource($schemaManager);
*
* @param string $source The source for the mapping files
* @param string $type The type of mapping files (yml, xml, etc.)
* @return void
*/
public function addMappingSource($source, $type = null)
{
$this->_reader->addMappingSource($source, $type);
}
/**
* Get an array of ClassMetadataInfo instances for all the configured mapping
* directories. Reads the mapping directories and populates ClassMetadataInfo
* instances.
*
* @return array $classes
*/
public function getMetadatas()
{
return $this->_reader->getMetadatas();
} }
} }

View File

@ -36,7 +36,7 @@ use Doctrine\ORM\Mapping\ClassMetadataInfo;
*/ */
abstract class AbstractExporter abstract class AbstractExporter
{ {
protected $_metadatas = array(); protected $_metadata = array();
protected $_outputDir; protected $_outputDir;
protected $_extension; protected $_extension;
@ -57,12 +57,12 @@ abstract class AbstractExporter
/** /**
* Set the array of ClassMetadataInfo instances to export * Set the array of ClassMetadataInfo instances to export
* *
* @param array $metadatas * @param array $metadata
* @return void * @return void
*/ */
public function setMetadatas(array $metadatas) public function setMetadata(array $metadata)
{ {
$this->_metadatas = $metadatas; $this->_metadata = $metadata;
} }
/** /**
@ -79,7 +79,7 @@ abstract class AbstractExporter
* Set the directory to output the mapping files to * Set the directory to output the mapping files to
* *
* [php] * [php]
* $exporter = new YamlExporter($metadatas); * $exporter = new YamlExporter($metadata);
* $exporter->setOutputDir(__DIR__ . '/yaml'); * $exporter->setOutputDir(__DIR__ . '/yaml');
* $exporter->export(); * $exporter->export();
* *
@ -103,7 +103,7 @@ abstract class AbstractExporter
mkdir($this->_outputDir, 0777, true); mkdir($this->_outputDir, 0777, true);
} }
foreach ($this->_metadatas as $metadata) { foreach ($this->_metadata as $metadata) {
$output = $this->exportClassMetadata($metadata); $output = $this->exportClassMetadata($metadata);
$path = $this->_generateOutputPath($metadata); $path = $this->_generateOutputPath($metadata);
$dir = dirname($path); $dir = dirname($path);
@ -129,7 +129,7 @@ abstract class AbstractExporter
* Set the directory to output the mapping files to * Set the directory to output the mapping files to
* *
* [php] * [php]
* $exporter = new YamlExporter($metadatas, __DIR__ . '/yaml'); * $exporter = new YamlExporter($metadata, __DIR__ . '/yaml');
* $exporter->setExtension('.yml'); * $exporter->setExtension('.yml');
* $exporter->export(); * $exporter->export();
* *

View File

@ -4,7 +4,7 @@ namespace Doctrine\Tests\ORM\Functional;
require_once __DIR__ . '/../../TestInit.php'; require_once __DIR__ . '/../../TestInit.php';
use Doctrine\ORM\Tools\ClassMetadataReader; use Doctrine\ORM\Mapping\ClassMetadataInfo;
class DatabaseDriverTest extends \Doctrine\Tests\OrmFunctionalTestCase class DatabaseDriverTest extends \Doctrine\Tests\OrmFunctionalTestCase
{ {
@ -80,7 +80,6 @@ class DatabaseDriverTest extends \Doctrine\Tests\OrmFunctionalTestCase
$this->assertType('Doctrine\ORM\Mapping\OneToOneMapping', $metadata->associationMappings['bar']); $this->assertType('Doctrine\ORM\Mapping\OneToOneMapping', $metadata->associationMappings['bar']);
} }
/** /**
* *
* @param string $className * @param string $className
@ -88,15 +87,12 @@ class DatabaseDriverTest extends \Doctrine\Tests\OrmFunctionalTestCase
*/ */
protected function extractClassMetadata($className) protected function extractClassMetadata($className)
{ {
$cm = new ClassMetadataReader(); $driver = new \Doctrine\ORM\Mapping\Driver\DatabaseDriver($this->_sm);
$cm->addMappingSource(new \Doctrine\ORM\Mapping\Driver\DatabaseDriver($this->_sm)); foreach ($driver->getAllClassNames() as $dbClassName) {
$metadatas = $cm->getMetadatas(); $class = new ClassMetadataInfo($dbClassName);
$driver->loadMetadataForClass($dbClassName, $class);
$output = false; if (strtolower($class->name) == strtolower($className)) {
return $class;
foreach ($metadatas AS $metadata) {
if (strtolower($metadata->name) == strtolower($className)) {
return $metadata;
} }
} }

View File

@ -21,8 +21,15 @@
namespace Doctrine\Tests\ORM\Tools; namespace Doctrine\Tests\ORM\Tools;
use Doctrine\ORM\Tools\Export\ClassMetadataExporter, use Doctrine\ORM\Tools\Export\ClassMetadataExporter;
Doctrine\ORM\Tools\ConvertDoctrine1Schema; use Doctrine\ORM\Tools\ConvertDoctrine1Schema;
use Doctrine\Tests\Mocks\MetadataDriverMock;
use Doctrine\Tests\Mocks\DatabasePlatformMock;
use Doctrine\Tests\Mocks\EntityManagerMock;
use Doctrine\Tests\Mocks\ConnectionMock;
use Doctrine\Tests\Mocks\DriverMock;
use Doctrine\Common\EventManager;
use Doctrine\ORM\Tools\DisconnectedClassMetadataFactory;
require_once __DIR__ . '/../../TestInit.php'; require_once __DIR__ . '/../../TestInit.php';
@ -38,9 +45,23 @@ require_once __DIR__ . '/../../TestInit.php';
*/ */
class ConvertDoctrine1SchemaTest extends \Doctrine\Tests\OrmTestCase class ConvertDoctrine1SchemaTest extends \Doctrine\Tests\OrmTestCase
{ {
protected function _createEntityManager($metadataDriver)
{
$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();
$config->setMetadataDriverImpl($metadataDriver);
return EntityManagerMock::create($conn, $config, $eventManager);
}
public function testTest() public function testTest()
{ {
if (!class_exists('Symfony\Components\Yaml\Yaml', true)) { if ( ! class_exists('Symfony\Components\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.');
} }
@ -48,28 +69,32 @@ class ConvertDoctrine1SchemaTest extends \Doctrine\Tests\OrmTestCase
$converter = new ConvertDoctrine1Schema(__DIR__ . '/doctrine1schema'); $converter = new ConvertDoctrine1Schema(__DIR__ . '/doctrine1schema');
$exporter = $cme->getExporter('yml', __DIR__ . '/convert'); $exporter = $cme->getExporter('yml', __DIR__ . '/convert');
$exporter->setMetadatas($converter->getMetadatas()); $exporter->setMetadata($converter->getMetadata());
$exporter->export(); $exporter->export();
$this->assertTrue(file_exists(__DIR__ . '/convert/User.dcm.yml')); $this->assertTrue(file_exists(__DIR__ . '/convert/User.dcm.yml'));
$this->assertTrue(file_exists(__DIR__ . '/convert/Profile.dcm.yml')); $this->assertTrue(file_exists(__DIR__ . '/convert/Profile.dcm.yml'));
$cme->addMappingSource(__DIR__ . '/convert'); $metadataDriver = new \Doctrine\ORM\Mapping\Driver\YamlDriver(__DIR__ . '/convert');
$metadatas = $cme->getMetadatas(); $em = $this->_createEntityManager($metadataDriver);
$cmf = new DisconnectedClassMetadataFactory($em);
$metadata = $cmf->getAllMetadata();
$profileClass = $metadata[0];
$userClass = $metadata[1];
$this->assertEquals(2, count($metadatas)); $this->assertEquals(2, count($metadata));
$this->assertEquals('Profile', $metadatas['Profile']->name); $this->assertEquals('Profile', $profileClass->name);
$this->assertEquals('User', $metadatas['User']->name); $this->assertEquals('User', $userClass->name);
$this->assertEquals(4, count($metadatas['Profile']->fieldMappings)); $this->assertEquals(4, count($profileClass->fieldMappings));
$this->assertEquals(5, count($metadatas['User']->fieldMappings)); $this->assertEquals(5, count($userClass->fieldMappings));
$this->assertEquals('text', $metadatas['User']->fieldMappings['clob']['type']); $this->assertEquals('text', $userClass->fieldMappings['clob']['type']);
$this->assertEquals('test_alias', $metadatas['User']->fieldMappings['theAlias']['columnName']); $this->assertEquals('test_alias', $userClass->fieldMappings['theAlias']['columnName']);
$this->assertEquals('theAlias', $metadatas['User']->fieldMappings['theAlias']['fieldName']); $this->assertEquals('theAlias', $userClass->fieldMappings['theAlias']['fieldName']);
$this->assertEquals('Profile', $metadatas['Profile']->associationMappings['User']->sourceEntityName); $this->assertEquals('Profile', $profileClass->associationMappings['User']->sourceEntityName);
$this->assertEquals('User', $metadatas['Profile']->associationMappings['User']->targetEntityName); $this->assertEquals('User', $profileClass->associationMappings['User']->targetEntityName);
$this->assertEquals('username', $metadatas['User']->table['uniqueConstraints']['username']['columns'][0]); $this->assertEquals('username', $userClass->table['uniqueConstraints']['username']['columns'][0]);
unlink(__DIR__ . '/convert/User.dcm.yml'); unlink(__DIR__ . '/convert/User.dcm.yml');
unlink(__DIR__ . '/convert/Profile.dcm.yml'); unlink(__DIR__ . '/convert/Profile.dcm.yml');

View File

@ -21,9 +21,17 @@
namespace Doctrine\Tests\ORM\Tools\Export; namespace Doctrine\Tests\ORM\Tools\Export;
use Doctrine\ORM\Tools\Export\ClassMetadataExporter, use Doctrine\ORM\Tools\Export\ClassMetadataExporter;
Doctrine\ORM\Mapping\ClassMetadataInfo, use Doctrine\ORM\Mapping\ClassMetadataInfo;
Doctrine\ORM\Tools\EntityGenerator; use Doctrine\ORM\Tools\EntityGenerator;
use Doctrine\Tests\Mocks\MetadataDriverMock;
use Doctrine\Tests\Mocks\DatabasePlatformMock;
use Doctrine\Tests\Mocks\EntityManagerMock;
use Doctrine\Tests\Mocks\ConnectionMock;
use Doctrine\Tests\Mocks\DriverMock;
use Doctrine\Common\EventManager;
use Doctrine\ORM\Tools\DisconnectedClassMetadataFactory;
use Doctrine\ORM\Mapping\ClassMetadataFactory;
require_once __DIR__ . '/../../../TestInit.php'; require_once __DIR__ . '/../../../TestInit.php';
@ -43,59 +51,64 @@ abstract class AbstractClassMetadataExporterTest extends \Doctrine\Tests\OrmTest
abstract protected function _getType(); abstract protected function _getType();
protected function _getTestEntityName() protected function _createEntityManager($metadataDriver)
{ {
if ($this->_getType() == 'annotation') { $driverMock = new DriverMock();
return 'Doctrine\Tests\ORM\Tools\Export\User2'; $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();
$config->setMetadataDriverImpl($metadataDriver);
return EntityManagerMock::create($conn, $config, $eventManager);
}
protected function _createMetadataDriver($type, $path)
{
$class = 'Doctrine\ORM\Mapping\Driver\\' . ucfirst($type) . 'Driver';
if ($type === 'annotation') {
$driver = $class::create($path);
} else { } else {
return 'Doctrine\Tests\ORM\Tools\Export\User'; $driver = new $class($path);
}
return $driver;
}
protected function _createClassMetadataFactory($em, $type)
{
if ($type === 'annotation') {
return new ClassMetadataFactory($em);
} else {
return new DisconnectedClassMetadataFactory($em);
} }
} }
protected function _loadClassMetadataExporter() public function testExportDirectoryAndFilesAreCreated()
{ {
$type = $this->_getType(); $type = $this->_getType();
$metadataDriver = $this->_createMetadataDriver($type, __DIR__ . '/' . $type);
$em = $this->_createEntityManager($metadataDriver);
$cmf = $this->_createClassMetadataFactory($em, $type);
$metadata = $cmf->getAllMetadata();
$this->assertEquals('Doctrine\Tests\ORM\Tools\Export\User', $metadata[0]->name);
$type = $this->_getType();
$cme = new ClassMetadataExporter(); $cme = new ClassMetadataExporter();
$cme->addMappingSource(__DIR__ . '/' . $type, $type);
return $cme;
}
public function testGetMetadatasForMappingSources()
{
$type = $this->_getType();
$cme = $this->_loadClassMetadataExporter();
$metadataInstances = $cme->getMetadatas();
$this->assertEquals('Doctrine\Tests\ORM\Tools\Export\User', $metadataInstances['Doctrine\Tests\ORM\Tools\Export\User']->name);
return $cme;
}
/**
* @depends testGetMetadatasForMappingSources
* @param ClassMetadataExporter $cme
*/
public function testExportDirectoryAndFilesAreCreated($cme)
{
$type = $this->_getType();
$exporter = $cme->getExporter($type, __DIR__ . '/export/' . $type); $exporter = $cme->getExporter($type, __DIR__ . '/export/' . $type);
if ($type === 'annotation') { if ($type === 'annotation') {
$entityGenerator = new EntityGenerator(); $entityGenerator = new EntityGenerator();
$exporter->setEntityGenerator($entityGenerator); $exporter->setEntityGenerator($entityGenerator);
} }
$this->_extension = $exporter->getExtension(); $this->_extension = $exporter->getExtension();
$metadatas = $cme->getMetadatas();
if ($type == 'annotation') {
$metadatas['Doctrine\Tests\ORM\Tools\Export\User']->name = $this->_getTestEntityName();
}
$exporter->setMetadatas($metadatas); $exporter->setMetadata($metadata);
$exporter->export(); $exporter->export();
if ($type == 'annotation') { if ($type == 'annotation') {
$this->assertTrue(file_exists(__DIR__ . '/export/' . $type . '/'.str_replace('\\', '/', $this->_getTestEntityName()).$this->_extension)); $this->assertTrue(file_exists(__DIR__ . '/export/' . $type . '/'.str_replace('\\', '/', 'Doctrine\Tests\ORM\Tools\Export\User').$this->_extension));
} else { } else {
$this->assertTrue(file_exists(__DIR__ . '/export/' . $type . '/Doctrine.Tests.ORM.Tools.Export.User'.$this->_extension)); $this->assertTrue(file_exists(__DIR__ . '/export/' . $type . '/Doctrine.Tests.ORM.Tools.Export.User'.$this->_extension));
} }
@ -107,163 +120,165 @@ abstract class AbstractClassMetadataExporterTest extends \Doctrine\Tests\OrmTest
public function testExportedMetadataCanBeReadBackIn() public function testExportedMetadataCanBeReadBackIn()
{ {
$type = $this->_getType(); $type = $this->_getType();
$cme = new ClassMetadataExporter();
$cme->addMappingSource(__DIR__ . '/export/' . $type, $type); $metadataDriver = $this->_createMetadataDriver($type, __DIR__ . '/' . $type);
$em = $this->_createEntityManager($metadataDriver);
$cmf = $this->_createClassMetadataFactory($em, $type);
$metadata = $cmf->getAllMetadata();
$metadataInstances = $cme->getMetadatas(); $class = current($metadata);
$metadata = current($metadataInstances);
$this->assertEquals($this->_getTestEntityName(), $metadata->name); $this->assertEquals('Doctrine\Tests\ORM\Tools\Export\User', $class->name);
return $metadata; return $class;
} }
/** /**
* @depends testExportedMetadataCanBeReadBackIn * @depends testExportedMetadataCanBeReadBackIn
* @param ClassMetadataInfo $metadata * @param ClassMetadataInfo $class
*/ */
public function testTableIsExported($metadata) public function testTableIsExported($class)
{ {
$this->assertEquals('cms_users', $metadata->table['name']); $this->assertEquals('cms_users', $class->table['name']);
return $metadata; return $class;
} }
/** /**
* @depends testTableIsExported * @depends testTableIsExported
* @param ClassMetadataInfo $metadata * @param ClassMetadataInfo $class
*/ */
public function testTypeIsExported($metadata) public function testTypeIsExported($class)
{ {
$this->assertFalse($metadata->isMappedSuperclass); $this->assertFalse($class->isMappedSuperclass);
return $metadata; return $class;
} }
/** /**
* @depends testTypeIsExported * @depends testTypeIsExported
* @param ClassMetadataInfo $metadata * @param ClassMetadataInfo $class
*/ */
public function testIdentifierIsExported($metadata) public function testIdentifierIsExported($class)
{ {
$this->assertEquals(ClassMetadataInfo::GENERATOR_TYPE_AUTO, $metadata->generatorType); $this->assertEquals(ClassMetadataInfo::GENERATOR_TYPE_IDENTITY, $class->generatorType);
$this->assertEquals(array('id'), $metadata->identifier); $this->assertEquals(array('id'), $class->identifier);
$this->assertTrue(isset($metadata->fieldMappings['id']['id']) && $metadata->fieldMappings['id']['id'] === true); $this->assertTrue(isset($class->fieldMappings['id']['id']) && $class->fieldMappings['id']['id'] === true);
return $metadata; return $class;
} }
/** /**
* @depends testIdentifierIsExported * @depends testIdentifierIsExported
* @param ClassMetadataInfo $metadata * @param ClassMetadataInfo $class
*/ */
public function testFieldsAreExpored($metadata) public function testFieldsAreExpored($class)
{ {
$this->assertTrue(isset($metadata->fieldMappings['id']['id']) && $metadata->fieldMappings['id']['id'] === true); $this->assertTrue(isset($class->fieldMappings['id']['id']) && $class->fieldMappings['id']['id'] === true);
$this->assertEquals('id', $metadata->fieldMappings['id']['fieldName']); $this->assertEquals('id', $class->fieldMappings['id']['fieldName']);
$this->assertEquals('integer', $metadata->fieldMappings['id']['type']); $this->assertEquals('integer', $class->fieldMappings['id']['type']);
$this->assertEquals('id', $metadata->fieldMappings['id']['columnName']); $this->assertEquals('id', $class->fieldMappings['id']['columnName']);
$this->assertEquals('name', $metadata->fieldMappings['name']['fieldName']); $this->assertEquals('name', $class->fieldMappings['name']['fieldName']);
$this->assertEquals('string', $metadata->fieldMappings['name']['type']); $this->assertEquals('string', $class->fieldMappings['name']['type']);
$this->assertEquals(50, $metadata->fieldMappings['name']['length']); $this->assertEquals(50, $class->fieldMappings['name']['length']);
$this->assertEquals('name', $metadata->fieldMappings['name']['columnName']); $this->assertEquals('name', $class->fieldMappings['name']['columnName']);
$this->assertEquals('email', $metadata->fieldMappings['email']['fieldName']); $this->assertEquals('email', $class->fieldMappings['email']['fieldName']);
$this->assertEquals('string', $metadata->fieldMappings['email']['type']); $this->assertEquals('string', $class->fieldMappings['email']['type']);
$this->assertEquals('user_email', $metadata->fieldMappings['email']['columnName']); $this->assertEquals('user_email', $class->fieldMappings['email']['columnName']);
$this->assertEquals('CHAR(32) NOT NULL', $metadata->fieldMappings['email']['columnDefinition']); $this->assertEquals('CHAR(32) NOT NULL', $class->fieldMappings['email']['columnDefinition']);
return $metadata; return $class;
} }
/** /**
* @depends testFieldsAreExpored * @depends testFieldsAreExpored
* @param ClassMetadataInfo $metadata * @param ClassMetadataInfo $class
*/ */
public function testOneToOneAssociationsAreExported($metadata) public function testOneToOneAssociationsAreExported($class)
{ {
$this->assertTrue(isset($metadata->associationMappings['address'])); $this->assertTrue(isset($class->associationMappings['address']));
$this->assertTrue($metadata->associationMappings['address'] instanceof \Doctrine\ORM\Mapping\OneToOneMapping); $this->assertTrue($class->associationMappings['address'] instanceof \Doctrine\ORM\Mapping\OneToOneMapping);
$this->assertEquals('Doctrine\Tests\ORM\Tools\Export\Address', $metadata->associationMappings['address']->targetEntityName); $this->assertEquals('Doctrine\Tests\ORM\Tools\Export\Address', $class->associationMappings['address']->targetEntityName);
$this->assertEquals('address_id', $metadata->associationMappings['address']->joinColumns[0]['name']); $this->assertEquals('address_id', $class->associationMappings['address']->joinColumns[0]['name']);
$this->assertEquals('id', $metadata->associationMappings['address']->joinColumns[0]['referencedColumnName']); $this->assertEquals('id', $class->associationMappings['address']->joinColumns[0]['referencedColumnName']);
$this->assertEquals('CASCADE', $metadata->associationMappings['address']->joinColumns[0]['onDelete']); $this->assertEquals('CASCADE', $class->associationMappings['address']->joinColumns[0]['onDelete']);
$this->assertEquals('CASCADE', $metadata->associationMappings['address']->joinColumns[0]['onUpdate']); $this->assertEquals('CASCADE', $class->associationMappings['address']->joinColumns[0]['onUpdate']);
$this->assertTrue($metadata->associationMappings['address']->isCascadeRemove); $this->assertTrue($class->associationMappings['address']->isCascadeRemove);
$this->assertFalse($metadata->associationMappings['address']->isCascadePersist); $this->assertFalse($class->associationMappings['address']->isCascadePersist);
$this->assertFalse($metadata->associationMappings['address']->isCascadeRefresh); $this->assertFalse($class->associationMappings['address']->isCascadeRefresh);
$this->assertFalse($metadata->associationMappings['address']->isCascadeMerge); $this->assertFalse($class->associationMappings['address']->isCascadeMerge);
$this->assertFalse($metadata->associationMappings['address']->isCascadeDetach); $this->assertFalse($class->associationMappings['address']->isCascadeDetach);
return $metadata; return $class;
} }
/** /**
* @depends testOneToOneAssociationsAreExported * @depends testOneToOneAssociationsAreExported
* @param ClassMetadataInfo $metadata * @param ClassMetadataInfo $class
*/ */
public function testOneToManyAssociationsAreExported($metadata) public function testOneToManyAssociationsAreExported($class)
{ {
$this->assertTrue(isset($metadata->associationMappings['phonenumbers'])); $this->assertTrue(isset($class->associationMappings['phonenumbers']));
$this->assertTrue($metadata->associationMappings['phonenumbers'] instanceof \Doctrine\ORM\Mapping\OneToManyMapping); $this->assertTrue($class->associationMappings['phonenumbers'] instanceof \Doctrine\ORM\Mapping\OneToManyMapping);
$this->assertEquals('Doctrine\Tests\ORM\Tools\Export\Phonenumber', $metadata->associationMappings['phonenumbers']->targetEntityName); $this->assertEquals('Doctrine\Tests\ORM\Tools\Export\Phonenumber', $class->associationMappings['phonenumbers']->targetEntityName);
$this->assertEquals('user', $metadata->associationMappings['phonenumbers']->mappedBy); $this->assertEquals('user', $class->associationMappings['phonenumbers']->mappedBy);
$this->assertEquals(array('number' => 'ASC'), $metadata->associationMappings['phonenumbers']->orderBy); $this->assertEquals(array('number' => 'ASC'), $class->associationMappings['phonenumbers']->orderBy);
$this->assertFalse($metadata->associationMappings['phonenumbers']->isCascadeRemove); $this->assertFalse($class->associationMappings['phonenumbers']->isCascadeRemove);
$this->assertTrue($metadata->associationMappings['phonenumbers']->isCascadePersist); $this->assertTrue($class->associationMappings['phonenumbers']->isCascadePersist);
$this->assertFalse($metadata->associationMappings['phonenumbers']->isCascadeRefresh); $this->assertFalse($class->associationMappings['phonenumbers']->isCascadeRefresh);
$this->assertFalse($metadata->associationMappings['phonenumbers']->isCascadeMerge); $this->assertFalse($class->associationMappings['phonenumbers']->isCascadeMerge);
$this->assertFalse($metadata->associationMappings['phonenumbers']->isCascadeDetach); $this->assertFalse($class->associationMappings['phonenumbers']->isCascadeDetach);
return $metadata; return $class;
} }
/** /**
* @depends testOneToManyAssociationsAreExported * @depends testOneToManyAssociationsAreExported
* @param ClassMetadataInfo $metadata * @param ClassMetadataInfo $metadata
*/ */
public function testManyToManyAssociationsAreExported($metadata) public function testManyToManyAssociationsAreExported($class)
{ {
$this->assertTrue(isset($metadata->associationMappings['groups'])); $this->assertTrue(isset($class->associationMappings['groups']));
$this->assertTrue($metadata->associationMappings['groups'] instanceof \Doctrine\ORM\Mapping\ManyToManyMapping); $this->assertTrue($class->associationMappings['groups'] instanceof \Doctrine\ORM\Mapping\ManyToManyMapping);
$this->assertEquals('Doctrine\Tests\ORM\Tools\Export\Group', $metadata->associationMappings['groups']->targetEntityName); $this->assertEquals('Doctrine\Tests\ORM\Tools\Export\Group', $class->associationMappings['groups']->targetEntityName);
$this->assertEquals('cms_users_groups', $metadata->associationMappings['groups']->joinTable['name']); $this->assertEquals('cms_users_groups', $class->associationMappings['groups']->joinTable['name']);
$this->assertEquals('user_id', $metadata->associationMappings['groups']->joinTable['joinColumns'][0]['name']); $this->assertEquals('user_id', $class->associationMappings['groups']->joinTable['joinColumns'][0]['name']);
$this->assertEquals('id', $metadata->associationMappings['groups']->joinTable['joinColumns'][0]['referencedColumnName']); $this->assertEquals('id', $class->associationMappings['groups']->joinTable['joinColumns'][0]['referencedColumnName']);
$this->assertEquals('group_id', $metadata->associationMappings['groups']->joinTable['inverseJoinColumns'][0]['name']); $this->assertEquals('group_id', $class->associationMappings['groups']->joinTable['inverseJoinColumns'][0]['name']);
$this->assertEquals('id', $metadata->associationMappings['groups']->joinTable['inverseJoinColumns'][0]['referencedColumnName']); $this->assertEquals('id', $class->associationMappings['groups']->joinTable['inverseJoinColumns'][0]['referencedColumnName']);
$this->assertEquals('INT NULL', $metadata->associationMappings['groups']->joinTable['inverseJoinColumns'][0]['columnDefinition']); $this->assertEquals('INT NULL', $class->associationMappings['groups']->joinTable['inverseJoinColumns'][0]['columnDefinition']);
$this->assertTrue($metadata->associationMappings['groups']->isCascadeRemove); $this->assertTrue($class->associationMappings['groups']->isCascadeRemove);
$this->assertTrue($metadata->associationMappings['groups']->isCascadePersist); $this->assertTrue($class->associationMappings['groups']->isCascadePersist);
$this->assertTrue($metadata->associationMappings['groups']->isCascadeRefresh); $this->assertTrue($class->associationMappings['groups']->isCascadeRefresh);
$this->assertTrue($metadata->associationMappings['groups']->isCascadeMerge); $this->assertTrue($class->associationMappings['groups']->isCascadeMerge);
$this->assertTrue($metadata->associationMappings['groups']->isCascadeDetach); $this->assertTrue($class->associationMappings['groups']->isCascadeDetach);
return $metadata; return $class;
} }
/** /**
* @depends testManyToManyAssociationsAreExported * @depends testManyToManyAssociationsAreExported
* @param ClassMetadataInfo $metadata * @param ClassMetadataInfo $class
*/ */
public function testLifecycleCallbacksAreExported($metadata) public function testLifecycleCallbacksAreExported($class)
{ {
$this->assertTrue(isset($metadata->lifecycleCallbacks['prePersist'])); $this->assertTrue(isset($class->lifecycleCallbacks['prePersist']));
$this->assertEquals(2, count($metadata->lifecycleCallbacks['prePersist'])); $this->assertEquals(2, count($class->lifecycleCallbacks['prePersist']));
$this->assertEquals('doStuffOnPrePersist', $metadata->lifecycleCallbacks['prePersist'][0]); $this->assertEquals('doStuffOnPrePersist', $class->lifecycleCallbacks['prePersist'][0]);
$this->assertEquals('doOtherStuffOnPrePersistToo', $metadata->lifecycleCallbacks['prePersist'][1]); $this->assertEquals('doOtherStuffOnPrePersistToo', $class->lifecycleCallbacks['prePersist'][1]);
$this->assertTrue(isset($metadata->lifecycleCallbacks['postPersist'])); $this->assertTrue(isset($class->lifecycleCallbacks['postPersist']));
$this->assertEquals(1, count($metadata->lifecycleCallbacks['postPersist'])); $this->assertEquals(1, count($class->lifecycleCallbacks['postPersist']));
$this->assertEquals('doStuffOnPostPersist', $metadata->lifecycleCallbacks['postPersist'][0]); $this->assertEquals('doStuffOnPostPersist', $class->lifecycleCallbacks['postPersist'][0]);
return $metadata; return $class;
} }
public function __destruct() public function __destruct()