Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
D
doctrine-dbal
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Tomáš Trávníček
doctrine-dbal
Commits
f3c672a2
Commit
f3c672a2
authored
Apr 14, 2010
by
Roman S. Borschel
Browse files
Options
Browse Files
Download
Plain Diff
Merged from upstream/master.
parents
10acab65
d6565667
Changes
11
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
292 additions
and
535 deletions
+292
-535
ClassMetadataFactory.php
lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php
+21
-14
ClassMetadataReader.php
lib/Doctrine/ORM/Tools/ClassMetadataReader.php
+0
-287
ConvertMappingCommand.php
...trine/ORM/Tools/Console/Command/ConvertMappingCommand.php
+5
-2
GenerateEntitiesCommand.php
...ine/ORM/Tools/Console/Command/GenerateEntitiesCommand.php
+4
-2
ConvertDoctrine1Schema.php
lib/Doctrine/ORM/Tools/ConvertDoctrine1Schema.php
+1
-1
DisconnectedClassMetadataFactory.php
lib/Doctrine/ORM/Tools/DisconnectedClassMetadataFactory.php
+59
-0
ClassMetadataExporter.php
lib/Doctrine/ORM/Tools/Export/ClassMetadataExporter.php
+3
-66
AbstractExporter.php
lib/Doctrine/ORM/Tools/Export/Driver/AbstractExporter.php
+7
-7
DatabaseDriverTest.php
tests/Doctrine/Tests/ORM/Functional/DatabaseDriverTest.php
+7
-11
ConvertDoctrine1SchemaTest.php
...s/Doctrine/Tests/ORM/Tools/ConvertDoctrine1SchemaTest.php
+42
-17
AbstractClassMetadataExporterTest.php
...ts/ORM/Tools/Export/AbstractClassMetadataExporterTest.php
+143
-128
No files found.
lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php
View file @
f3c672a2
<?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
...
...
@@ -30,10 +28,7 @@ use Doctrine\ORM\ORMException,
* metadata mapping informations of a class which describes how a class should be mapped
* to a relational database.
*
* @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>
...
...
@@ -190,7 +185,25 @@ class ClassMetadataFactory
{
$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
* is still not loaded.
...
...
@@ -206,13 +219,7 @@ class ClassMetadataFactory
$loaded
=
array
();
// 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
;
}
}
$parentClasses
=
$this
->
_getParentClasses
(
$name
);
$parentClasses
[]
=
$name
;
// Move down the hierarchy of parent classes, starting from the topmost class
...
...
@@ -353,7 +360,7 @@ class ClassMetadataFactory
*
* @param Doctrine\ORM\Mapping\ClassMetadata $class
*/
private
function
_completeIdGeneratorMapping
(
ClassMetadata
$class
)
private
function
_completeIdGeneratorMapping
(
ClassMetadata
Info
$class
)
{
$idGenType
=
$class
->
generatorType
;
if
(
$idGenType
==
ClassMetadata
::
GENERATOR_TYPE_AUTO
)
{
...
...
lib/Doctrine/ORM/Tools/ClassMetadataReader.php
deleted
100644 → 0
View file @
10acab65
<?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
;
}
}
}
\ No newline at end of file
lib/Doctrine/ORM/Tools/Console/Command/ConvertMappingCommand.php
View file @
f3c672a2
...
...
@@ -25,7 +25,9 @@ use Symfony\Components\Console\Input\InputArgument,
Symfony\Components\Console\Input\InputOption
,
Symfony\Components\Console
,
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.
...
...
@@ -94,7 +96,8 @@ EOT
);
}
$metadatas
=
$em
->
getMetadataFactory
()
->
getAllMetadata
();
$cmf
=
new
DisconnectedClassMetadataFactory
(
$em
);
$metadatas
=
$cmf
->
getAllMetadata
();
$metadatas
=
MetadataFilter
::
filter
(
$metadatas
,
$input
->
getOption
(
'filter'
));
// Process destination directory
...
...
lib/Doctrine/ORM/Tools/Console/Command/GenerateEntitiesCommand.php
View file @
f3c672a2
...
...
@@ -25,7 +25,8 @@ use Symfony\Components\Console\Input\InputArgument,
Symfony\Components\Console\Input\InputOption
,
Symfony\Components\Console
,
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.
...
...
@@ -95,7 +96,8 @@ EOT
{
$em
=
$this
->
getHelper
(
'em'
)
->
getEntityManager
();
$metadatas
=
$em
->
getMetadataFactory
()
->
getAllMetadata
();
$cmf
=
new
DisconnectedClassMetadataFactory
(
$em
);
$metadatas
=
$cmf
->
getAllMetadata
();
$metadatas
=
MetadataFilter
::
filter
(
$metadatas
,
$input
->
getOption
(
'filter'
));
// Process destination directory
...
...
lib/Doctrine/ORM/Tools/ConvertDoctrine1Schema.php
View file @
f3c672a2
...
...
@@ -62,7 +62,7 @@ class ConvertDoctrine1Schema
*
* @return array $metadatas An array of ClassMetadataInfo instances
*/
public
function
getMetadata
s
()
public
function
getMetadata
()
{
$schema
=
array
();
foreach
(
$this
->
_from
as
$path
)
{
...
...
lib/Doctrine/ORM/Tools/DisconnectedClassMetadataFactory.php
0 → 100644
View file @
f3c672a2
<?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
();
}
}
\ No newline at end of file
lib/Doctrine/ORM/Tools/Export/ClassMetadataExporter.php
View file @
f3c672a2
...
...
@@ -22,29 +22,13 @@
namespace
Doctrine\ORM\Tools\Export
;
use
Doctrine\ORM\Tools\ClassMetadataReader
,
Doctrine\ORM\Tools\Export\ExportException
,
use
Doctrine\ORM\Tools\Export\ExportException
,
Doctrine\ORM\EntityManager
;
/**
* Class used for converting your mapping information between the
* 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
* @link www.doctrine-project.org
* @since 2.0
...
...
@@ -61,11 +45,6 @@ class ClassMetadataExporter
'annotation'
=>
'Doctrine\ORM\Tools\Export\Driver\AnnotationExporter'
);
public
function
__construct
()
{
$this
->
_reader
=
new
ClassMetadataReader
();
}
/**
* Register a new exporter driver class under a specified name
*
...
...
@@ -77,18 +56,6 @@ class ClassMetadataExporter
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
*
...
...
@@ -96,7 +63,7 @@ class ClassMetadataExporter
* @param string $source The directory where the exporter will export to
* @return AbstractExporter $exporter
*/
public
function
getExporter
(
$type
,
$
source
=
null
)
public
function
getExporter
(
$type
,
$
dest
)
{
if
(
!
isset
(
self
::
$_exporterDrivers
[
$type
]))
{
throw
ExportException
::
invalidExporterDriverType
(
$type
);
...
...
@@ -104,36 +71,6 @@ class ClassMetadataExporter
$class
=
self
::
$_exporterDrivers
[
$type
];
return
new
$class
(
$source
);
}
/**
* 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
();
return
new
$class
(
$dest
);
}
}
\ No newline at end of file
lib/Doctrine/ORM/Tools/Export/Driver/AbstractExporter.php
View file @
f3c672a2
...
...
@@ -36,7 +36,7 @@ use Doctrine\ORM\Mapping\ClassMetadataInfo;
*/
abstract
class
AbstractExporter
{
protected
$_metadata
s
=
array
();
protected
$_metadata
=
array
();
protected
$_outputDir
;
protected
$_extension
;
...
...
@@ -57,12 +57,12 @@ abstract class AbstractExporter
/**
* Set the array of ClassMetadataInfo instances to export
*
* @param array $metadata
s
* @param array $metadata
* @return void
*/
public
function
setMetadata
s
(
array
$metadatas
)
public
function
setMetadata
(
array
$metadata
)
{
$this
->
_metadata
s
=
$metadatas
;
$this
->
_metadata
=
$metadata
;
}
/**
...
...
@@ -79,7 +79,7 @@ abstract class AbstractExporter
* Set the directory to output the mapping files to
*
* [php]
* $exporter = new YamlExporter($metadata
s
);
* $exporter = new YamlExporter($metadata);
* $exporter->setOutputDir(__DIR__ . '/yaml');
* $exporter->export();
*
...
...
@@ -103,7 +103,7 @@ abstract class AbstractExporter
mkdir
(
$this
->
_outputDir
,
0777
,
true
);
}
foreach
(
$this
->
_metadata
s
as
$metadata
)
{
foreach
(
$this
->
_metadata
as
$metadata
)
{
$output
=
$this
->
exportClassMetadata
(
$metadata
);
$path
=
$this
->
_generateOutputPath
(
$metadata
);
$dir
=
dirname
(
$path
);
...
...
@@ -129,7 +129,7 @@ abstract class AbstractExporter
* Set the directory to output the mapping files to
*
* [php]
* $exporter = new YamlExporter($metadata
s
, __DIR__ . '/yaml');
* $exporter = new YamlExporter($metadata, __DIR__ . '/yaml');
* $exporter->setExtension('.yml');
* $exporter->export();
*
...
...
tests/Doctrine/Tests/ORM/Functional/DatabaseDriverTest.php
View file @
f3c672a2
...
...
@@ -4,7 +4,7 @@ namespace Doctrine\Tests\ORM\Functional;
require_once
__DIR__
.
'/../../TestInit.php'
;
use
Doctrine\ORM\
Tools\ClassMetadataReader
;
use
Doctrine\ORM\
Mapping\ClassMetadataInfo
;
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'
]);
}
/**
*
* @param string $className
...
...
@@ -88,15 +87,12 @@ class DatabaseDriverTest extends \Doctrine\Tests\OrmFunctionalTestCase
*/
protected
function
extractClassMetadata
(
$className
)
{
$cm
=
new
ClassMetadataReader
();
$cm
->
addMappingSource
(
new
\Doctrine\ORM\Mapping\Driver\DatabaseDriver
(
$this
->
_sm
));
$metadatas
=
$cm
->
getMetadatas
();
$output
=
false
;
foreach
(
$metadatas
AS
$metadata
)
{
if
(
strtolower
(
$metadata
->
name
)
==
strtolower
(
$className
))
{
return
$metadata
;
$driver
=
new
\Doctrine\ORM\Mapping\Driver\DatabaseDriver
(
$this
->
_sm
);
foreach
(
$driver
->
getAllClassNames
()
as
$dbClassName
)
{
$class
=
new
ClassMetadataInfo
(
$dbClassName
);
$driver
->
loadMetadataForClass
(
$dbClassName
,
$class
);
if
(
strtolower
(
$class
->
name
)
==
strtolower
(
$className
))
{
return
$class
;
}
}
...
...
tests/Doctrine/Tests/ORM/Tools/ConvertDoctrine1SchemaTest.php
View file @
f3c672a2
...
...
@@ -21,8 +21,15 @@
namespace
Doctrine\Tests\ORM\Tools
;
use
Doctrine\ORM\Tools\Export\ClassMetadataExporter
,
Doctrine\ORM\Tools\ConvertDoctrine1Schema
;
use
Doctrine\ORM\Tools\Export\ClassMetadataExporter
;
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'
;
...
...
@@ -38,9 +45,23 @@ require_once __DIR__ . '/../../TestInit.php';
*/
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
()
{
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.'
);
}
...
...
@@ -48,28 +69,32 @@ class ConvertDoctrine1SchemaTest extends \Doctrine\Tests\OrmTestCase
$converter
=
new
ConvertDoctrine1Schema
(
__DIR__
.
'/doctrine1schema'
);
$exporter
=
$cme
->
getExporter
(
'yml'
,
__DIR__
.
'/convert'
);
$exporter
->
setMetadata
s
(
$converter
->
getMetadatas
());
$exporter
->
setMetadata
(
$converter
->
getMetadata
());
$exporter
->
export
();
$this
->
assertTrue
(
file_exists
(
__DIR__
.
'/convert/User.dcm.yml'
));
$this
->
assertTrue
(
file_exists
(
__DIR__
.
'/convert/Profile.dcm.yml'
));
$cme
->
addMappingSource
(
__DIR__
.
'/convert'
);
$metadatas
=
$cme
->
getMetadatas
();
$metadataDriver
=
new
\Doctrine\ORM\Mapping\Driver\YamlDriver
(
__DIR__
.
'/convert'
);
$em
=
$this
->
_createEntityManager
(
$metadataDriver
);
$cmf
=
new
DisconnectedClassMetadataFactory
(
$em
);
$metadata
=
$cmf
->
getAllMetadata
();
$profileClass
=
$metadata
[
0
];
$userClass
=
$metadata
[
1
];
$this
->
assertEquals
(
2
,
count
(
$metadata
s
));
$this
->
assertEquals
(
'Profile'
,
$
metadatas
[
'Profile'
]
->
name
);
$this
->
assertEquals
(
'User'
,
$
metadatas
[
'User'
]
->
name
);
$this
->
assertEquals
(
4
,
count
(
$
metadatas
[
'Profile'
]
->
fieldMappings
));
$this
->
assertEquals
(
5
,
count
(
$
metadatas
[
'User'
]
->
fieldMappings
));
$this
->
assertEquals
(
'text'
,
$
metadatas
[
'User'
]
->
fieldMappings
[
'clob'
][
'type'
]);
$this
->
assertEquals
(
'test_alias'
,
$
metadatas
[
'User'
]
->
fieldMappings
[
'theAlias'
][
'columnName'
]);
$this
->
assertEquals
(
'theAlias'
,
$
metadatas
[
'User'
]
->
fieldMappings
[
'theAlias'
][
'fieldName'
]);
$this
->
assertEquals
(
2
,
count
(
$metadata
));
$this
->
assertEquals
(
'Profile'
,
$
profileClass
->
name
);
$this
->
assertEquals
(
'User'
,
$
userClass
->
name
);
$this
->
assertEquals
(
4
,
count
(
$
profileClass
->
fieldMappings
));
$this
->
assertEquals
(
5
,
count
(
$
userClass
->
fieldMappings
));
$this
->
assertEquals
(
'text'
,
$
userClass
->
fieldMappings
[
'clob'
][
'type'
]);
$this
->
assertEquals
(
'test_alias'
,
$
userClass
->
fieldMappings
[
'theAlias'
][
'columnName'
]);
$this
->
assertEquals
(
'theAlias'
,
$
userClass
->
fieldMappings
[
'theAlias'
][
'fieldName'
]);
$this
->
assertEquals
(
'Profile'
,
$
metadatas
[
'Profile'
]
->
associationMappings
[
'User'
]
->
sourceEntityName
);
$this
->
assertEquals
(
'User'
,
$
metadatas
[
'Profile'
]
->
associationMappings
[
'User'
]
->
targetEntityName
);
$this
->
assertEquals
(
'Profile'
,
$
profileClass
->
associationMappings
[
'User'
]
->
sourceEntityName
);
$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/Profile.dcm.yml'
);
...
...
tests/Doctrine/Tests/ORM/Tools/Export/AbstractClassMetadataExporterTest.php
View file @
f3c672a2
...
...
@@ -21,9 +21,17 @@
namespace
Doctrine\Tests\ORM\Tools\Export
;
use
Doctrine\ORM\Tools\Export\ClassMetadataExporter
,
Doctrine\ORM\Mapping\ClassMetadataInfo
,
Doctrine\ORM\Tools\EntityGenerator
;
use
Doctrine\ORM\Tools\Export\ClassMetadataExporter
;
use
Doctrine\ORM\Mapping\ClassMetadataInfo
;
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'
;
...
...
@@ -43,59 +51,64 @@ abstract class AbstractClassMetadataExporterTest extends \Doctrine\Tests\OrmTest
abstract
protected
function
_getType
();
protected
function
_
getTestEntityName
(
)
protected
function
_
createEntityManager
(
$metadataDriver
)
{
if
(
$this
->
_getType
()
==
'annotation'
)
{
return
'Doctrine\Tests\ORM\Tools\Export\User2'
;
$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
);
}
protected
function
_createMetadataDriver
(
$type
,
$path
)
{
$class
=
'Doctrine\ORM\Mapping\Driver\\'
.
ucfirst
(
$type
)
.
'Driver'
;
if
(
$type
===
'annotation'
)
{
$driver
=
$class
::
create
(
$path
);
}
else
{
return
'Doctrine\Tests\ORM\Tools\Export\User'
;
$driver
=
new
$class
(
$path
)
;
}
return
$driver
;
}
protected
function
_
loadClassMetadataExporter
(
)
protected
function
_
createClassMetadataFactory
(
$em
,
$type
)
{
$type
=
$this
->
_getType
();
$cme
=
new
ClassMetadataExporter
();
$cme
->
addMappingSource
(
__DIR__
.
'/'
.
$type
,
$type
);
return
$cme
;
if
(
$type
===
'annotation'
)
{
return
new
ClassMetadataFactory
(
$em
);
}
else
{
return
new
DisconnectedClassMetadataFactory
(
$em
);
}
}
public
function
test
GetMetadatasForMappingSources
()
public
function
test
ExportDirectoryAndFilesAreCreated
()
{
$type
=
$this
->
_getType
();
$cme
=
$this
->
_loadClassMetadataExporter
();
$metadataInstances
=
$cme
->
getMetadatas
();
$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
Instances
[
'Doctrine\Tests\ORM\Tools\Export\User'
]
->
name
);
$this
->
assertEquals
(
'Doctrine\Tests\ORM\Tools\Export\User'
,
$metadata
[
0
]
->
name
);
return
$cme
;
}
/**
* @depends testGetMetadatasForMappingSources
* @param ClassMetadataExporter $cme
*/
public
function
testExportDirectoryAndFilesAreCreated
(
$cme
)
{
$type
=
$this
->
_getType
();
$cme
=
new
ClassMetadataExporter
();
$exporter
=
$cme
->
getExporter
(
$type
,
__DIR__
.
'/export/'
.
$type
);
if
(
$type
===
'annotation'
)
{
$entityGenerator
=
new
EntityGenerator
();
$exporter
->
setEntityGenerator
(
$entityGenerator
);
}
$this
->
_extension
=
$exporter
->
getExtension
();
$metadatas
=
$cme
->
getMetadatas
();
if
(
$type
==
'annotation'
)
{
$metadatas
[
'Doctrine\Tests\ORM\Tools\Export\User'
]
->
name
=
$this
->
_getTestEntityName
();
}
$exporter
->
setMetadata
s
(
$metadatas
);
$exporter
->
setMetadata
(
$metadata
);
$exporter
->
export
();
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
{
$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
()
{
$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
();
$metadata
=
current
(
$metadataInstances
);
$class
=
current
(
$metadata
);
$this
->
assertEquals
(
$this
->
_getTestEntityName
(),
$metadata
->
name
);
$this
->
assertEquals
(
'Doctrine\Tests\ORM\Tools\Export\User'
,
$class
->
name
);
return
$
metadata
;
return
$
class
;
}
/**
* @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
* @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
* @param ClassMetadataInfo $
metadata
* @param ClassMetadataInfo $
class
*/
public
function
testIdentifierIsExported
(
$
metadata
)
public
function
testIdentifierIsExported
(
$
class
)
{
$this
->
assertEquals
(
ClassMetadataInfo
::
GENERATOR_TYPE_
AUTO
,
$metadata
->
generatorType
);
$this
->
assertEquals
(
array
(
'id'
),
$
metadata
->
identifier
);
$this
->
assertTrue
(
isset
(
$
metadata
->
fieldMappings
[
'id'
][
'id'
])
&&
$metadata
->
fieldMappings
[
'id'
][
'id'
]
===
true
);
$this
->
assertEquals
(
ClassMetadataInfo
::
GENERATOR_TYPE_
IDENTITY
,
$class
->
generatorType
);
$this
->
assertEquals
(
array
(
'id'
),
$
class
->
identifier
);
$this
->
assertTrue
(
isset
(
$
class
->
fieldMappings
[
'id'
][
'id'
])
&&
$class
->
fieldMappings
[
'id'
][
'id'
]
===
true
);
return
$
metadata
;
return
$
class
;
}
/**
* @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
->
assertEquals
(
'id'
,
$
metadata
->
fieldMappings
[
'id'
][
'fieldName'
]);
$this
->
assertEquals
(
'integer'
,
$
metadata
->
fieldMappings
[
'id'
][
'type'
]);
$this
->
assertEquals
(
'id'
,
$
metadata
->
fieldMappings
[
'id'
][
'columnName'
]);
$this
->
assertEquals
(
'name'
,
$
metadata
->
fieldMappings
[
'name'
][
'fieldName'
]);
$this
->
assertEquals
(
'string'
,
$
metadata
->
fieldMappings
[
'name'
][
'type'
]);
$this
->
assertEquals
(
50
,
$
metadata
->
fieldMappings
[
'name'
][
'length'
]);
$this
->
assertEquals
(
'name'
,
$
metadata
->
fieldMappings
[
'name'
][
'columnName'
]);
$this
->
assertEquals
(
'email'
,
$
metadata
->
fieldMappings
[
'email'
][
'fieldName'
]);
$this
->
assertEquals
(
'string'
,
$
metadata
->
fieldMappings
[
'email'
][
'type'
]);
$this
->
assertEquals
(
'user_email'
,
$
metadata
->
fieldMappings
[
'email'
][
'columnName'
]);
$this
->
assertEquals
(
'CHAR(32) NOT NULL'
,
$
metadata
->
fieldMappings
[
'email'
][
'columnDefinition'
]);
return
$
metadata
;
$this
->
assertTrue
(
isset
(
$
class
->
fieldMappings
[
'id'
][
'id'
])
&&
$class
->
fieldMappings
[
'id'
][
'id'
]
===
true
);
$this
->
assertEquals
(
'id'
,
$
class
->
fieldMappings
[
'id'
][
'fieldName'
]);
$this
->
assertEquals
(
'integer'
,
$
class
->
fieldMappings
[
'id'
][
'type'
]);
$this
->
assertEquals
(
'id'
,
$
class
->
fieldMappings
[
'id'
][
'columnName'
]);
$this
->
assertEquals
(
'name'
,
$
class
->
fieldMappings
[
'name'
][
'fieldName'
]);
$this
->
assertEquals
(
'string'
,
$
class
->
fieldMappings
[
'name'
][
'type'
]);
$this
->
assertEquals
(
50
,
$
class
->
fieldMappings
[
'name'
][
'length'
]);
$this
->
assertEquals
(
'name'
,
$
class
->
fieldMappings
[
'name'
][
'columnName'
]);
$this
->
assertEquals
(
'email'
,
$
class
->
fieldMappings
[
'email'
][
'fieldName'
]);
$this
->
assertEquals
(
'string'
,
$
class
->
fieldMappings
[
'email'
][
'type'
]);
$this
->
assertEquals
(
'user_email'
,
$
class
->
fieldMappings
[
'email'
][
'columnName'
]);
$this
->
assertEquals
(
'CHAR(32) NOT NULL'
,
$
class
->
fieldMappings
[
'email'
][
'columnDefinition'
]);
return
$
class
;
}
/**
* @depends testFieldsAreExpored
* @param ClassMetadataInfo $
metadata
* @param ClassMetadataInfo $
class
*/
public
function
testOneToOneAssociationsAreExported
(
$
metadata
)
public
function
testOneToOneAssociationsAreExported
(
$
class
)
{
$this
->
assertTrue
(
isset
(
$
metadata
->
associationMappings
[
'address'
]));
$this
->
assertTrue
(
$
metadata
->
associationMappings
[
'address'
]
instanceof
\Doctrine\ORM\Mapping\OneToOneMapping
);
$this
->
assertEquals
(
'Doctrine\Tests\ORM\Tools\Export\Address'
,
$
metadata
->
associationMappings
[
'address'
]
->
targetEntityName
);
$this
->
assertEquals
(
'address_id'
,
$
metadata
->
associationMappings
[
'address'
]
->
joinColumns
[
0
][
'name'
]);
$this
->
assertEquals
(
'id'
,
$
metadata
->
associationMappings
[
'address'
]
->
joinColumns
[
0
][
'referencedColumnName'
]);
$this
->
assertEquals
(
'CASCADE'
,
$
metadata
->
associationMappings
[
'address'
]
->
joinColumns
[
0
][
'onDelete'
]);
$this
->
assertEquals
(
'CASCADE'
,
$
metadata
->
associationMappings
[
'address'
]
->
joinColumns
[
0
][
'onUpdate'
]);
$this
->
assertTrue
(
$
metadata
->
associationMappings
[
'address'
]
->
isCascadeRemove
);
$this
->
assertFalse
(
$
metadata
->
associationMappings
[
'address'
]
->
isCascadePersist
);
$this
->
assertFalse
(
$
metadata
->
associationMappings
[
'address'
]
->
isCascadeRefresh
);
$this
->
assertFalse
(
$
metadata
->
associationMappings
[
'address'
]
->
isCascadeMerge
);
$this
->
assertFalse
(
$
metadata
->
associationMappings
[
'address'
]
->
isCascadeDetach
);
return
$
metadata
;
$this
->
assertTrue
(
isset
(
$
class
->
associationMappings
[
'address'
]));
$this
->
assertTrue
(
$
class
->
associationMappings
[
'address'
]
instanceof
\Doctrine\ORM\Mapping\OneToOneMapping
);
$this
->
assertEquals
(
'Doctrine\Tests\ORM\Tools\Export\Address'
,
$
class
->
associationMappings
[
'address'
]
->
targetEntityName
);
$this
->
assertEquals
(
'address_id'
,
$
class
->
associationMappings
[
'address'
]
->
joinColumns
[
0
][
'name'
]);
$this
->
assertEquals
(
'id'
,
$
class
->
associationMappings
[
'address'
]
->
joinColumns
[
0
][
'referencedColumnName'
]);
$this
->
assertEquals
(
'CASCADE'
,
$
class
->
associationMappings
[
'address'
]
->
joinColumns
[
0
][
'onDelete'
]);
$this
->
assertEquals
(
'CASCADE'
,
$
class
->
associationMappings
[
'address'
]
->
joinColumns
[
0
][
'onUpdate'
]);
$this
->
assertTrue
(
$
class
->
associationMappings
[
'address'
]
->
isCascadeRemove
);
$this
->
assertFalse
(
$
class
->
associationMappings
[
'address'
]
->
isCascadePersist
);
$this
->
assertFalse
(
$
class
->
associationMappings
[
'address'
]
->
isCascadeRefresh
);
$this
->
assertFalse
(
$
class
->
associationMappings
[
'address'
]
->
isCascadeMerge
);
$this
->
assertFalse
(
$
class
->
associationMappings
[
'address'
]
->
isCascadeDetach
);
return
$
class
;
}
/**
* @depends testOneToOneAssociationsAreExported
* @param ClassMetadataInfo $
metadata
* @param ClassMetadataInfo $
class
*/
public
function
testOneToManyAssociationsAreExported
(
$
metadata
)
public
function
testOneToManyAssociationsAreExported
(
$
class
)
{
$this
->
assertTrue
(
isset
(
$
metadata
->
associationMappings
[
'phonenumbers'
]));
$this
->
assertTrue
(
$
metadata
->
associationMappings
[
'phonenumbers'
]
instanceof
\Doctrine\ORM\Mapping\OneToManyMapping
);
$this
->
assertEquals
(
'Doctrine\Tests\ORM\Tools\Export\Phonenumber'
,
$
metadata
->
associationMappings
[
'phonenumbers'
]
->
targetEntityName
);
$this
->
assertEquals
(
'user'
,
$
metadata
->
associationMappings
[
'phonenumbers'
]
->
mappedBy
);
$this
->
assertEquals
(
array
(
'number'
=>
'ASC'
),
$
metadata
->
associationMappings
[
'phonenumbers'
]
->
orderBy
);
$this
->
assertFalse
(
$
metadata
->
associationMappings
[
'phonenumbers'
]
->
isCascadeRemove
);
$this
->
assertTrue
(
$
metadata
->
associationMappings
[
'phonenumbers'
]
->
isCascadePersist
);
$this
->
assertFalse
(
$
metadata
->
associationMappings
[
'phonenumbers'
]
->
isCascadeRefresh
);
$this
->
assertFalse
(
$
metadata
->
associationMappings
[
'phonenumbers'
]
->
isCascadeMerge
);
$this
->
assertFalse
(
$
metadata
->
associationMappings
[
'phonenumbers'
]
->
isCascadeDetach
);
$this
->
assertTrue
(
isset
(
$
class
->
associationMappings
[
'phonenumbers'
]));
$this
->
assertTrue
(
$
class
->
associationMappings
[
'phonenumbers'
]
instanceof
\Doctrine\ORM\Mapping\OneToManyMapping
);
$this
->
assertEquals
(
'Doctrine\Tests\ORM\Tools\Export\Phonenumber'
,
$
class
->
associationMappings
[
'phonenumbers'
]
->
targetEntityName
);
$this
->
assertEquals
(
'user'
,
$
class
->
associationMappings
[
'phonenumbers'
]
->
mappedBy
);
$this
->
assertEquals
(
array
(
'number'
=>
'ASC'
),
$
class
->
associationMappings
[
'phonenumbers'
]
->
orderBy
);
$this
->
assertFalse
(
$
class
->
associationMappings
[
'phonenumbers'
]
->
isCascadeRemove
);
$this
->
assertTrue
(
$
class
->
associationMappings
[
'phonenumbers'
]
->
isCascadePersist
);
$this
->
assertFalse
(
$
class
->
associationMappings
[
'phonenumbers'
]
->
isCascadeRefresh
);
$this
->
assertFalse
(
$
class
->
associationMappings
[
'phonenumbers'
]
->
isCascadeMerge
);
$this
->
assertFalse
(
$
class
->
associationMappings
[
'phonenumbers'
]
->
isCascadeDetach
);
return
$
metadata
;
return
$
class
;
}
/**
* @depends testOneToManyAssociationsAreExported
* @param ClassMetadataInfo $metadata
*/
public
function
testManyToManyAssociationsAreExported
(
$
metadata
)
public
function
testManyToManyAssociationsAreExported
(
$
class
)
{
$this
->
assertTrue
(
isset
(
$
metadata
->
associationMappings
[
'groups'
]));
$this
->
assertTrue
(
$
metadata
->
associationMappings
[
'groups'
]
instanceof
\Doctrine\ORM\Mapping\ManyToManyMapping
);
$this
->
assertEquals
(
'Doctrine\Tests\ORM\Tools\Export\Group'
,
$
metadata
->
associationMappings
[
'groups'
]
->
targetEntityName
);
$this
->
assertEquals
(
'cms_users_groups'
,
$
metadata
->
associationMappings
[
'groups'
]
->
joinTable
[
'name'
]);
$this
->
assertTrue
(
isset
(
$
class
->
associationMappings
[
'groups'
]));
$this
->
assertTrue
(
$
class
->
associationMappings
[
'groups'
]
instanceof
\Doctrine\ORM\Mapping\ManyToManyMapping
);
$this
->
assertEquals
(
'Doctrine\Tests\ORM\Tools\Export\Group'
,
$
class
->
associationMappings
[
'groups'
]
->
targetEntityName
);
$this
->
assertEquals
(
'cms_users_groups'
,
$
class
->
associationMappings
[
'groups'
]
->
joinTable
[
'name'
]);
$this
->
assertEquals
(
'user_id'
,
$
metadata
->
associationMappings
[
'groups'
]
->
joinTable
[
'joinColumns'
][
0
][
'name'
]);
$this
->
assertEquals
(
'id'
,
$
metadata
->
associationMappings
[
'groups'
]
->
joinTable
[
'joinColumns'
][
0
][
'referencedColumnName'
]);
$this
->
assertEquals
(
'user_id'
,
$
class
->
associationMappings
[
'groups'
]
->
joinTable
[
'joinColumns'
][
0
][
'name'
]);
$this
->
assertEquals
(
'id'
,
$
class
->
associationMappings
[
'groups'
]
->
joinTable
[
'joinColumns'
][
0
][
'referencedColumnName'
]);
$this
->
assertEquals
(
'group_id'
,
$
metadata
->
associationMappings
[
'groups'
]
->
joinTable
[
'inverseJoinColumns'
][
0
][
'name'
]);
$this
->
assertEquals
(
'id'
,
$
metadata
->
associationMappings
[
'groups'
]
->
joinTable
[
'inverseJoinColumns'
][
0
][
'referencedColumnName'
]);
$this
->
assertEquals
(
'INT NULL'
,
$
metadata
->
associationMappings
[
'groups'
]
->
joinTable
[
'inverseJoinColumns'
][
0
][
'columnDefinition'
]);
$this
->
assertEquals
(
'group_id'
,
$
class
->
associationMappings
[
'groups'
]
->
joinTable
[
'inverseJoinColumns'
][
0
][
'name'
]);
$this
->
assertEquals
(
'id'
,
$
class
->
associationMappings
[
'groups'
]
->
joinTable
[
'inverseJoinColumns'
][
0
][
'referencedColumnName'
]);
$this
->
assertEquals
(
'INT NULL'
,
$
class
->
associationMappings
[
'groups'
]
->
joinTable
[
'inverseJoinColumns'
][
0
][
'columnDefinition'
]);
$this
->
assertTrue
(
$
metadata
->
associationMappings
[
'groups'
]
->
isCascadeRemove
);
$this
->
assertTrue
(
$
metadata
->
associationMappings
[
'groups'
]
->
isCascadePersist
);
$this
->
assertTrue
(
$
metadata
->
associationMappings
[
'groups'
]
->
isCascadeRefresh
);
$this
->
assertTrue
(
$
metadata
->
associationMappings
[
'groups'
]
->
isCascadeMerge
);
$this
->
assertTrue
(
$
metadata
->
associationMappings
[
'groups'
]
->
isCascadeDetach
);
$this
->
assertTrue
(
$
class
->
associationMappings
[
'groups'
]
->
isCascadeRemove
);
$this
->
assertTrue
(
$
class
->
associationMappings
[
'groups'
]
->
isCascadePersist
);
$this
->
assertTrue
(
$
class
->
associationMappings
[
'groups'
]
->
isCascadeRefresh
);
$this
->
assertTrue
(
$
class
->
associationMappings
[
'groups'
]
->
isCascadeMerge
);
$this
->
assertTrue
(
$
class
->
associationMappings
[
'groups'
]
->
isCascadeDetach
);
return
$
metadata
;
return
$
class
;
}
/**
* @depends testManyToManyAssociationsAreExported
* @param ClassMetadataInfo $
metadata
* @param ClassMetadataInfo $
class
*/
public
function
testLifecycleCallbacksAreExported
(
$
metadata
)
public
function
testLifecycleCallbacksAreExported
(
$
class
)
{
$this
->
assertTrue
(
isset
(
$
metadata
->
lifecycleCallbacks
[
'prePersist'
]));
$this
->
assertEquals
(
2
,
count
(
$
metadata
->
lifecycleCallbacks
[
'prePersist'
]));
$this
->
assertEquals
(
'doStuffOnPrePersist'
,
$
metadata
->
lifecycleCallbacks
[
'prePersist'
][
0
]);
$this
->
assertEquals
(
'doOtherStuffOnPrePersistToo'
,
$
metadata
->
lifecycleCallbacks
[
'prePersist'
][
1
]);
$this
->
assertTrue
(
isset
(
$
class
->
lifecycleCallbacks
[
'prePersist'
]));
$this
->
assertEquals
(
2
,
count
(
$
class
->
lifecycleCallbacks
[
'prePersist'
]));
$this
->
assertEquals
(
'doStuffOnPrePersist'
,
$
class
->
lifecycleCallbacks
[
'prePersist'
][
0
]);
$this
->
assertEquals
(
'doOtherStuffOnPrePersistToo'
,
$
class
->
lifecycleCallbacks
[
'prePersist'
][
1
]);
$this
->
assertTrue
(
isset
(
$
metadata
->
lifecycleCallbacks
[
'postPersist'
]));
$this
->
assertEquals
(
1
,
count
(
$
metadata
->
lifecycleCallbacks
[
'postPersist'
]));
$this
->
assertEquals
(
'doStuffOnPostPersist'
,
$
metadata
->
lifecycleCallbacks
[
'postPersist'
][
0
]);
$this
->
assertTrue
(
isset
(
$
class
->
lifecycleCallbacks
[
'postPersist'
]));
$this
->
assertEquals
(
1
,
count
(
$
class
->
lifecycleCallbacks
[
'postPersist'
]));
$this
->
assertEquals
(
'doStuffOnPostPersist'
,
$
class
->
lifecycleCallbacks
[
'postPersist'
][
0
]);
return
$
metadata
;
return
$
class
;
}
public
function
__destruct
()
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment