[2.0] Improving test coverage for mapping exporters as well as adding missing functionality
This commit is contained in:
parent
1d60c65daf
commit
770d00abe9
@ -66,6 +66,6 @@ class PhpDriver extends AbstractFileDriver
|
|||||||
protected function _loadMappingFile($file)
|
protected function _loadMappingFile($file)
|
||||||
{
|
{
|
||||||
$metadata = $this->_metadata;
|
$metadata = $this->_metadata;
|
||||||
require_once $file;
|
include $file;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -80,7 +80,7 @@ abstract class AbstractExporter
|
|||||||
public function export()
|
public function export()
|
||||||
{
|
{
|
||||||
if ( ! is_dir($this->_outputDir)) {
|
if ( ! is_dir($this->_outputDir)) {
|
||||||
mkdir($this->_outputDir, 0777);
|
mkdir($this->_outputDir, 0777, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($this->_metadatas as $metadata) {
|
foreach ($this->_metadatas as $metadata) {
|
||||||
|
@ -232,17 +232,40 @@ class AnnotationExporter extends AbstractExporter
|
|||||||
|
|
||||||
private function _getEntityAnnotation($metadata)
|
private function _getEntityAnnotation($metadata)
|
||||||
{
|
{
|
||||||
if ($metadata->isMappedSuperclass) {
|
$lines = array();
|
||||||
return '@MappedSupperClass';
|
$lines[] = '/**';
|
||||||
|
|
||||||
|
$methods = array(
|
||||||
|
'_getTableAnnotation',
|
||||||
|
'_getInheritanceAnnotation',
|
||||||
|
'_getDiscriminatorColumnAnnotation',
|
||||||
|
'_getDiscriminatorMapAnnotation'
|
||||||
|
);
|
||||||
|
|
||||||
|
foreach ($methods as $method) {
|
||||||
|
if ($code = $this->$method($metadata)) {
|
||||||
|
$lines[] = ' * ' . $code;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$str = '@Entity';
|
if ($metadata->isMappedSuperclass) {
|
||||||
|
$lines[] = ' * @MappedSupperClass';
|
||||||
|
} else {
|
||||||
|
$lines[] = ' * @Entity';
|
||||||
|
}
|
||||||
|
|
||||||
if ($metadata->customRepositoryClassName) {
|
if ($metadata->customRepositoryClassName) {
|
||||||
$str .= '(repositoryClass="' . $metadata->customRepositoryClassName . '")';
|
$lines[count($lines) - 1] .= '(repositoryClass="' . $metadata->customRepositoryClassName . '")';
|
||||||
}
|
}
|
||||||
|
|
||||||
return $str;
|
if (isset($metadata->lifecycleCallbacks) && $metadata->lifecycleCallbacks) {
|
||||||
|
$lines[] = ' * @HasLifecycleCallbacks';
|
||||||
|
}
|
||||||
|
|
||||||
|
$lines[] = ' */';
|
||||||
|
$lines[] = '';
|
||||||
|
|
||||||
|
return implode("\n", $lines);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function _getTableAnnotation($metadata)
|
private function _getTableAnnotation($metadata)
|
||||||
@ -350,6 +373,23 @@ class AnnotationExporter extends AbstractExporter
|
|||||||
$methods[] = implode("\n", $method);
|
$methods[] = implode("\n", $method);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function _addLifecycleCallbackMethod($name, $methodName, $metadata, array &$methods)
|
||||||
|
{
|
||||||
|
if ($this->_hasMethod($methodName, $metadata)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$method = array();
|
||||||
|
$method[] = $this->_spaces . '/**';
|
||||||
|
$method[] = $this->_spaces . ' * @'.$name;
|
||||||
|
$method[] = $this->_spaces . ' */';
|
||||||
|
$method[] = $this->_spaces . 'public function ' . $methodName . '()';
|
||||||
|
$method[] = $this->_spaces . '{';
|
||||||
|
$method[] = $this->_spaces . '}';
|
||||||
|
|
||||||
|
$methods[] = implode("\n", $method)."\n\n";
|
||||||
|
}
|
||||||
|
|
||||||
private function _getMethods($metadata)
|
private function _getMethods($metadata)
|
||||||
{
|
{
|
||||||
$methods = array();
|
$methods = array();
|
||||||
@ -380,6 +420,14 @@ class AnnotationExporter extends AbstractExporter
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (isset($metadata->lifecycleCallbacks) && $metadata->lifecycleCallbacks) {
|
||||||
|
foreach ($metadata->lifecycleCallbacks as $name => $callbacks) {
|
||||||
|
foreach ($callbacks as $callback) {
|
||||||
|
$this->_addLifecycleCallbackMethod($name, $callback, $metadata, $methods);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return $methods;
|
return $methods;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -404,6 +452,9 @@ class AnnotationExporter extends AbstractExporter
|
|||||||
if (isset($joinColumn['onUpdate'])) {
|
if (isset($joinColumn['onUpdate'])) {
|
||||||
$joinColumnAnnot[] = 'onUpdate=' . ($joinColumn['onUpdate'] ? 'true' : 'false');
|
$joinColumnAnnot[] = 'onUpdate=' . ($joinColumn['onUpdate'] ? 'true' : 'false');
|
||||||
}
|
}
|
||||||
|
if (isset($joinColumn['columnDefinition'])) {
|
||||||
|
$joinColumnAnnot[] = 'columnDefinition="' . $joinColumn['columnDefinition'] . '"';
|
||||||
|
}
|
||||||
return '@JoinColumn(' . implode(', ', $joinColumnAnnot) . ')';
|
return '@JoinColumn(' . implode(', ', $joinColumnAnnot) . ')';
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -472,6 +523,15 @@ class AnnotationExporter extends AbstractExporter
|
|||||||
$lines[] = $this->_spaces . ' * )';
|
$lines[] = $this->_spaces . ' * )';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (isset($associationMapping->orderBy)) {
|
||||||
|
$lines[] = $this->_spaces . ' * @OrderBy({';
|
||||||
|
foreach ($associationMapping->orderBy as $name => $direction) {
|
||||||
|
$lines[] = $this->_spaces . ' * "' . $name . '"="' . $direction . '",';
|
||||||
|
}
|
||||||
|
$lines[count($lines) - 1] = substr($lines[count($lines) - 1], 0, strlen($lines[count($lines) - 1]) - 1);
|
||||||
|
$lines[] = $this->_spaces . ' * })';
|
||||||
|
}
|
||||||
|
|
||||||
$lines[] = $this->_spaces . ' */';
|
$lines[] = $this->_spaces . ' */';
|
||||||
|
|
||||||
return implode("\n", $lines);
|
return implode("\n", $lines);
|
||||||
@ -501,6 +561,9 @@ class AnnotationExporter extends AbstractExporter
|
|||||||
if (isset($fieldMapping['nullable'])) {
|
if (isset($fieldMapping['nullable'])) {
|
||||||
$column[] = 'nullable=' . var_export($fieldMapping['nullable'], true);
|
$column[] = 'nullable=' . var_export($fieldMapping['nullable'], true);
|
||||||
}
|
}
|
||||||
|
if (isset($fieldMapping['columnDefinition'])) {
|
||||||
|
$column[] = 'columnDefinition="' . $fieldMapping['columnDefinition'] . '"';
|
||||||
|
}
|
||||||
if (isset($fieldMapping['options'])) {
|
if (isset($fieldMapping['options'])) {
|
||||||
$options = array();
|
$options = array();
|
||||||
foreach ($fieldMapping['options'] as $key => $value) {
|
foreach ($fieldMapping['options'] as $key => $value) {
|
||||||
|
@ -160,6 +160,9 @@ class XmlExporter extends AbstractExporter
|
|||||||
if (isset($field['version'])) {
|
if (isset($field['version'])) {
|
||||||
$fieldXml->addAttribute('version', $field['version']);
|
$fieldXml->addAttribute('version', $field['version']);
|
||||||
}
|
}
|
||||||
|
if (isset($field['columnDefinition'])) {
|
||||||
|
$fieldXml->addAttribute('column-definition', $field['columnDefinition']);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -204,9 +207,63 @@ class XmlExporter extends AbstractExporter
|
|||||||
$joinColumnXml = $joinColumnsXml->addChild('join-column');
|
$joinColumnXml = $joinColumnsXml->addChild('join-column');
|
||||||
$joinColumnXml->addAttribute('name', $joinColumn['name']);
|
$joinColumnXml->addAttribute('name', $joinColumn['name']);
|
||||||
$joinColumnXml->addAttribute('referenced-column-name', $joinColumn['referencedColumnName']);
|
$joinColumnXml->addAttribute('referenced-column-name', $joinColumn['referencedColumnName']);
|
||||||
|
if (isset($joinColumn['onDelete'])) {
|
||||||
|
$joinColumnXml->addAttribute('on-delete', $joinColumn['onDelete']);
|
||||||
|
}
|
||||||
|
if (isset($joinColumn['onUpdate'])) {
|
||||||
|
$joinColumnXml->addAttribute('on-update', $joinColumn['onUpdate']);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$inverseJoinColumnsXml = $joinTableXml->addChild('inverse-join-columns');
|
||||||
|
foreach ($associationMapping->joinTable['inverseJoinColumns'] as $inverseJoinColumn) {
|
||||||
|
$inverseJoinColumnXml = $inverseJoinColumnsXml->addChild('join-column');
|
||||||
|
$inverseJoinColumnXml->addAttribute('name', $inverseJoinColumn['name']);
|
||||||
|
$inverseJoinColumnXml->addAttribute('referenced-column-name', $inverseJoinColumn['referencedColumnName']);
|
||||||
|
if (isset($inverseJoinColumn['onDelete'])) {
|
||||||
|
$inverseJoinColumnXml->addAttribute('on-delete', $inverseJoinColumn['onDelete']);
|
||||||
|
}
|
||||||
|
if (isset($inverseJoinColumn['onUpdate'])) {
|
||||||
|
$inverseJoinColumnXml->addAttribute('on-update', $inverseJoinColumn['onUpdate']);
|
||||||
|
}
|
||||||
|
if (isset($inverseJoinColumn['columnDefinition'])) {
|
||||||
|
$inverseJoinColumnXml->addAttribute('column-definition', $inverseJoinColumn['columnDefinition']);
|
||||||
|
}
|
||||||
|
if (isset($inverseJoinColumn['nullable'])) {
|
||||||
|
$inverseJoinColumnXml->addAttribute('nullable', $inverseJoinColumn['nullable']);
|
||||||
|
}
|
||||||
|
if (isset($inverseJoinColumn['orderBy'])) {
|
||||||
|
$inverseJoinColumnXml->addAttribute('order-by', $inverseJoinColumn['orderBy']);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (isset($associationMapping->joinColumns)) {
|
||||||
|
$joinColumnsXml = $associationMappingXml->addChild('join-columns');
|
||||||
|
foreach ($associationMapping->joinColumns as $joinColumn) {
|
||||||
|
$joinColumnXml = $joinColumnsXml->addChild('join-column');
|
||||||
|
$joinColumnXml->addAttribute('name', $joinColumn['name']);
|
||||||
|
$joinColumnXml->addAttribute('referenced-column-name', $joinColumn['referencedColumnName']);
|
||||||
|
if (isset($joinColumn['onDelete'])) {
|
||||||
|
$joinColumnXml->addAttribute('on-delete', $joinColumn['onDelete']);
|
||||||
|
}
|
||||||
|
if (isset($joinColumn['onUpdate'])) {
|
||||||
|
$joinColumnXml->addAttribute('on-update', $joinColumn['onUpdate']);
|
||||||
|
}
|
||||||
|
if (isset($joinColumn['columnDefinition'])) {
|
||||||
|
$joinColumnXml->addAttribute('column-definition', $joinColumn['columnDefinition']);
|
||||||
|
}
|
||||||
|
if (isset($joinColumn['nullable'])) {
|
||||||
|
$joinColumnXml->addAttribute('nullable', $joinColumn['nullable']);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (isset($associationMapping->orderBy)) {
|
||||||
|
$orderByXml = $associationMappingXml->addChild('order-by');
|
||||||
|
foreach ($associationMapping->orderBy as $name => $direction) {
|
||||||
|
$orderByFieldXml = $orderByXml->addChild('order-by-field');
|
||||||
|
$orderByFieldXml->addAttribute('name', $name);
|
||||||
|
$orderByFieldXml->addAttribute('direction', $direction);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$cascade = array();
|
$cascade = array();
|
||||||
if ($associationMapping->isCascadeRemove) {
|
if ($associationMapping->isCascadeRemove) {
|
||||||
$cascade[] = 'remove';
|
$cascade[] = 'remove';
|
||||||
@ -231,6 +288,17 @@ class XmlExporter extends AbstractExporter
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (isset($metadata->lifecycleCallbacks)) {
|
||||||
|
$lifecycleCallbacksXml = $root->addChild('lifecycle-callbacks');
|
||||||
|
foreach ($metadata->lifecycleCallbacks as $name => $methods) {
|
||||||
|
foreach ($methods as $method) {
|
||||||
|
$lifecycleCallbackXml = $lifecycleCallbacksXml->addChild('lifecycle-callback');
|
||||||
|
$lifecycleCallbackXml->addAttribute('type', $name);
|
||||||
|
$lifecycleCallbackXml->addAttribute('method', $method);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return $this->_asXml($xml);
|
return $this->_asXml($xml);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -133,15 +133,25 @@ class YamlExporter extends AbstractExporter
|
|||||||
|
|
||||||
$associations = array();
|
$associations = array();
|
||||||
foreach ($metadata->associationMappings as $name => $associationMapping) {
|
foreach ($metadata->associationMappings as $name => $associationMapping) {
|
||||||
|
$cascade = array();
|
||||||
|
if ($associationMapping->isCascadeRemove) {
|
||||||
|
$cascade[] = 'remove';
|
||||||
|
}
|
||||||
|
if ($associationMapping->isCascadePersist) {
|
||||||
|
$cascade[] = 'persist';
|
||||||
|
}
|
||||||
|
if ($associationMapping->isCascadeRefresh) {
|
||||||
|
$cascade[] = 'refresh';
|
||||||
|
}
|
||||||
|
if ($associationMapping->isCascadeMerge) {
|
||||||
|
$cascade[] = 'merge';
|
||||||
|
}
|
||||||
|
if ($associationMapping->isCascadeDetach) {
|
||||||
|
$cascade[] = 'detach';
|
||||||
|
}
|
||||||
$associationMappingArray = array(
|
$associationMappingArray = array(
|
||||||
'targetEntity' => $associationMapping->targetEntityName,
|
'targetEntity' => $associationMapping->targetEntityName,
|
||||||
'cascade' => array(
|
'cascade' => $cascade,
|
||||||
'remove' => $associationMapping->isCascadeRemove,
|
|
||||||
'persist' => $associationMapping->isCascadePersist,
|
|
||||||
'refresh' => $associationMapping->isCascadeRefresh,
|
|
||||||
'merge' => $associationMapping->isCascadeMerge,
|
|
||||||
'detach' => $associationMapping->isCascadeDetach,
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
|
|
||||||
if ($associationMapping instanceof OneToOneMapping) {
|
if ($associationMapping instanceof OneToOneMapping) {
|
||||||
@ -149,6 +159,12 @@ class YamlExporter extends AbstractExporter
|
|||||||
$newJoinColumns = array();
|
$newJoinColumns = array();
|
||||||
foreach ($joinColumns as $joinColumn) {
|
foreach ($joinColumns as $joinColumn) {
|
||||||
$newJoinColumns[$joinColumn['name']]['referencedColumnName'] = $joinColumn['referencedColumnName'];
|
$newJoinColumns[$joinColumn['name']]['referencedColumnName'] = $joinColumn['referencedColumnName'];
|
||||||
|
if (isset($joinColumn['onDelete'])) {
|
||||||
|
$newJoinColumns[$joinColumn['name']]['onDelete'] = $joinColumn['onDelete'];
|
||||||
|
}
|
||||||
|
if (isset($joinColumn['onUpdate'])) {
|
||||||
|
$newJoinColumns[$joinColumn['name']]['onUpdate'] = $joinColumn['onUpdate'];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
$oneToOneMappingArray = array(
|
$oneToOneMappingArray = array(
|
||||||
'mappedBy' => $associationMapping->mappedBy,
|
'mappedBy' => $associationMapping->mappedBy,
|
||||||
@ -162,6 +178,7 @@ class YamlExporter extends AbstractExporter
|
|||||||
$oneToManyMappingArray = array(
|
$oneToManyMappingArray = array(
|
||||||
'mappedBy' => $associationMapping->mappedBy,
|
'mappedBy' => $associationMapping->mappedBy,
|
||||||
'orphanRemoval' => $associationMapping->orphanRemoval,
|
'orphanRemoval' => $associationMapping->orphanRemoval,
|
||||||
|
'orderBy' => $associationMapping->orderBy
|
||||||
);
|
);
|
||||||
|
|
||||||
$associationMappingArray = array_merge($associationMappingArray, $oneToManyMappingArray);
|
$associationMappingArray = array_merge($associationMappingArray, $oneToManyMappingArray);
|
||||||
@ -170,12 +187,16 @@ class YamlExporter extends AbstractExporter
|
|||||||
$manyToManyMappingArray = array(
|
$manyToManyMappingArray = array(
|
||||||
'mappedBy' => $associationMapping->mappedBy,
|
'mappedBy' => $associationMapping->mappedBy,
|
||||||
'joinTable' => $associationMapping->joinTable,
|
'joinTable' => $associationMapping->joinTable,
|
||||||
|
'orderBy' => $associationMapping->orderBy
|
||||||
);
|
);
|
||||||
|
|
||||||
$associationMappingArray = array_merge($associationMappingArray, $manyToManyMappingArray);
|
$associationMappingArray = array_merge($associationMappingArray, $manyToManyMappingArray);
|
||||||
$array['manyToMany'][$name] = $associationMappingArray;
|
$array['manyToMany'][$name] = $associationMappingArray;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (isset($metadata->lifecycleCallbacks)) {
|
||||||
|
$array['lifecycleCallbacks'] = $metadata->lifecycleCallbacks;
|
||||||
|
}
|
||||||
|
|
||||||
return \Symfony\Components\Yaml\Yaml::dump(array($metadata->name => $array), 10);
|
return \Symfony\Components\Yaml\Yaml::dump(array($metadata->name => $array), 10);
|
||||||
}
|
}
|
||||||
|
@ -8,14 +8,8 @@ namespace <?php echo $this->_getNamespace($metadata) ?>;
|
|||||||
use <?php echo $this->_getClassToExtendNamespace() ?>;
|
use <?php echo $this->_getClassToExtendNamespace() ?>;
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
|
|
||||||
/**
|
<?php echo $this->_getEntityAnnotation($metadata) ?>
|
||||||
* <?php echo $this->_getEntityAnnotation($metadata)."\n"; ?>
|
class <?php echo $this->_getClassName($metadata); ?><?php if ($this->_extendsClass()): ?> extends <?php echo $this->_getClassToExtendName() ?><?php endif; ?>
|
||||||
* <?php echo $this->_getTableAnnotation($metadata)."\n" ?>
|
|
||||||
* <?php echo $this->_getInheritanceAnnotation($metadata)."\n" ?>
|
|
||||||
* <?php echo $this->_getDiscriminatorColumnAnnotation($metadata)."\n" ?>
|
|
||||||
* <?php echo $this->_getDiscriminatorMapAnnotation($metadata)."\n" ?>
|
|
||||||
*/
|
|
||||||
class <?php echo $this->_getClassName($metadata); ?><?php if ($this->_extendsClass()): ?> extends <?php echo $this->_getClassToExtendName() ?><?php endif; ?>
|
|
||||||
{
|
{
|
||||||
<?php include('annotation_body.tpl.php') ?>
|
<?php include('annotation_body.tpl.php') ?>
|
||||||
}
|
}
|
@ -210,7 +210,7 @@ abstract class AbstractMappingDriverTest extends \Doctrine\Tests\OrmTestCase
|
|||||||
*/
|
*/
|
||||||
class User
|
class User
|
||||||
{
|
{
|
||||||
/** @Id @Column(type="int") @generatedValue(strategy="AUTO") */
|
/** @Id @Column(type="integer") @generatedValue(strategy="AUTO") */
|
||||||
public $id;
|
public $id;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -20,7 +20,10 @@ class AllTests
|
|||||||
{
|
{
|
||||||
$suite = new \Doctrine\Tests\DoctrineTestSuite('Doctrine Orm Tools');
|
$suite = new \Doctrine\Tests\DoctrineTestSuite('Doctrine Orm Tools');
|
||||||
|
|
||||||
$suite->addTestSuite('Doctrine\Tests\ORM\Tools\Export\ClassMetadataExporterTest');
|
$suite->addTestSuite('Doctrine\Tests\ORM\Tools\Export\YamlClassMetadataExporterTest');
|
||||||
|
$suite->addTestSuite('Doctrine\Tests\ORM\Tools\Export\XmlClassMetadataExporterTest');
|
||||||
|
$suite->addTestSuite('Doctrine\Tests\ORM\Tools\Export\PhpClassMetadataExporterTest');
|
||||||
|
$suite->addTestSuite('Doctrine\Tests\ORM\Tools\Export\AnnotationClassMetadataExporterTest');
|
||||||
$suite->addTestSuite('Doctrine\Tests\ORM\Tools\ConvertDoctrine1SchemaTest');
|
$suite->addTestSuite('Doctrine\Tests\ORM\Tools\ConvertDoctrine1SchemaTest');
|
||||||
$suite->addTestSuite('Doctrine\Tests\ORM\Tools\SchemaToolTest');
|
$suite->addTestSuite('Doctrine\Tests\ORM\Tools\SchemaToolTest');
|
||||||
|
|
||||||
|
@ -0,0 +1,281 @@
|
|||||||
|
<?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\Tests\ORM\Tools\Export;
|
||||||
|
|
||||||
|
use Doctrine\ORM\Tools\Export\ClassMetadataExporter,
|
||||||
|
Doctrine\ORM\Mapping\ClassMetadataInfo;
|
||||||
|
|
||||||
|
require_once __DIR__ . '/../../../TestInit.php';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test case for ClassMetadataExporter
|
||||||
|
*
|
||||||
|
* @author Jonathan H. Wage <jonwage@gmail.com>
|
||||||
|
* @author Roman Borschel <roman@code-factory.org
|
||||||
|
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
|
||||||
|
* @link http://www.phpdoctrine.org
|
||||||
|
* @since 2.0
|
||||||
|
* @version $Revision$
|
||||||
|
*/
|
||||||
|
abstract class AbstractClassMetadataExporterTest extends \Doctrine\Tests\OrmTestCase
|
||||||
|
{
|
||||||
|
protected $_extension;
|
||||||
|
|
||||||
|
abstract protected function _getType();
|
||||||
|
|
||||||
|
protected function _getTestEntityName()
|
||||||
|
{
|
||||||
|
if ($this->_getType() == 'annotation') {
|
||||||
|
return 'Doctrine\Tests\ORM\Tools\Export\User2';
|
||||||
|
} else {
|
||||||
|
return 'Doctrine\Tests\ORM\Tools\Export\User';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function _loadClassMetadataExporter()
|
||||||
|
{
|
||||||
|
$type = $this->_getType();
|
||||||
|
|
||||||
|
$cme = new ClassMetadataExporter();
|
||||||
|
$cme->addMappingSource(__DIR__ . '/' . $type, $type);
|
||||||
|
|
||||||
|
return $cme;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testGetMetadatasForMappingSources()
|
||||||
|
{
|
||||||
|
$type = $this->_getType();
|
||||||
|
$cme = $this->_loadClassMetadataExporter();
|
||||||
|
$metadataInstances = $cme->getMetadatasForMappingSources();
|
||||||
|
|
||||||
|
$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);
|
||||||
|
$this->_extension = $exporter->getExtension();
|
||||||
|
$metadatas = $cme->getMetadatasForMappingSources();
|
||||||
|
if ($type == 'annotation') {
|
||||||
|
$metadatas['Doctrine\Tests\ORM\Tools\Export\User']->name = $this->_getTestEntityName();
|
||||||
|
}
|
||||||
|
|
||||||
|
$exporter->setMetadatas($metadatas);
|
||||||
|
$exporter->export();
|
||||||
|
|
||||||
|
if ($type == 'annotation') {
|
||||||
|
$this->assertTrue(file_exists(__DIR__ . '/export/' . $type . '/'.str_replace('\\', '/', $this->_getTestEntityName()).$this->_extension));
|
||||||
|
} else {
|
||||||
|
$this->assertTrue(file_exists(__DIR__ . '/export/' . $type . '/Doctrine.Tests.ORM.Tools.Export.User'.$this->_extension));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @depends testExportDirectoryAndFilesAreCreated
|
||||||
|
*/
|
||||||
|
public function testExportedMetadataCanBeReadBackIn()
|
||||||
|
{
|
||||||
|
$type = $this->_getType();
|
||||||
|
$cme = new ClassMetadataExporter();
|
||||||
|
$cme->addMappingSource(__DIR__ . '/export/' . $type, $type);
|
||||||
|
$metadataInstances = $cme->getMetadatasForMappingSources();
|
||||||
|
$metadata = current($metadataInstances);
|
||||||
|
|
||||||
|
$this->assertEquals($this->_getTestEntityName(), $metadata->name);
|
||||||
|
|
||||||
|
return $metadata;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @depends testExportedMetadataCanBeReadBackIn
|
||||||
|
* @param ClassMetadataInfo $metadata
|
||||||
|
*/
|
||||||
|
public function testTableIsExported($metadata)
|
||||||
|
{
|
||||||
|
$this->assertEquals('cms_users', $metadata->primaryTable['name']);
|
||||||
|
|
||||||
|
return $metadata;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @depends testTableIsExported
|
||||||
|
* @param ClassMetadataInfo $metadata
|
||||||
|
*/
|
||||||
|
public function testTypeIsExported($metadata)
|
||||||
|
{
|
||||||
|
$this->assertFalse($metadata->isMappedSuperclass);
|
||||||
|
|
||||||
|
return $metadata;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @depends testTypeIsExported
|
||||||
|
* @param ClassMetadataInfo $metadata
|
||||||
|
*/
|
||||||
|
public function testIdentifierIsExported($metadata)
|
||||||
|
{
|
||||||
|
$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);
|
||||||
|
|
||||||
|
return $metadata;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @depends testIdentifierIsExported
|
||||||
|
* @param ClassMetadataInfo $metadata
|
||||||
|
*/
|
||||||
|
public function testFieldsAreExpored($metadata)
|
||||||
|
{
|
||||||
|
$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;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @depends testFieldsAreExpored
|
||||||
|
* @param ClassMetadataInfo $metadata
|
||||||
|
*/
|
||||||
|
public function testOneToOneAssociationsAreExported($metadata)
|
||||||
|
{
|
||||||
|
$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;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @depends testOneToOneAssociationsAreExported
|
||||||
|
* @param ClassMetadataInfo $metadata
|
||||||
|
*/
|
||||||
|
public function testOneToManyAssociationsAreExported($metadata)
|
||||||
|
{
|
||||||
|
$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);
|
||||||
|
|
||||||
|
return $metadata;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @depends testOneToManyAssociationsAreExported
|
||||||
|
* @param ClassMetadataInfo $metadata
|
||||||
|
*/
|
||||||
|
public function testManyToManyAssociationsAreExported($metadata)
|
||||||
|
{
|
||||||
|
$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->assertEquals('user_id', $metadata->associationMappings['groups']->joinTable['joinColumns'][0]['name']);
|
||||||
|
$this->assertEquals('id', $metadata->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->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);
|
||||||
|
|
||||||
|
return $metadata;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @depends testManyToManyAssociationsAreExported
|
||||||
|
* @param ClassMetadataInfo $metadata
|
||||||
|
*/
|
||||||
|
public function testLifecycleCallbacksAreExported($metadata)
|
||||||
|
{
|
||||||
|
$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($metadata->lifecycleCallbacks['postPersist']));
|
||||||
|
$this->assertEquals(1, count($metadata->lifecycleCallbacks['postPersist']));
|
||||||
|
$this->assertEquals('doStuffOnPostPersist', $metadata->lifecycleCallbacks['postPersist'][0]);
|
||||||
|
|
||||||
|
return $metadata;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function __destruct()
|
||||||
|
{
|
||||||
|
$type = $this->_getType();
|
||||||
|
$this->_deleteDirectory(__DIR__ . '/export/'.$this->_getType());
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function _deleteDirectory($path)
|
||||||
|
{
|
||||||
|
if (is_file($path)) {
|
||||||
|
return unlink($path);
|
||||||
|
} else if (is_dir($path)) {
|
||||||
|
$files = glob(rtrim($path,'/').'/*');
|
||||||
|
foreach ($files as $file){
|
||||||
|
$this->_deleteDirectory($file);
|
||||||
|
}
|
||||||
|
return rmdir($path);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,42 @@
|
|||||||
|
<?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\Tests\ORM\Tools\Export;
|
||||||
|
|
||||||
|
require_once __DIR__ . '/../../../TestInit.php';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test case for AnnotationClassMetadataExporterTest
|
||||||
|
*
|
||||||
|
* @author Jonathan H. Wage <jonwage@gmail.com>
|
||||||
|
* @author Roman Borschel <roman@code-factory.org
|
||||||
|
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
|
||||||
|
* @link http://www.phpdoctrine.org
|
||||||
|
* @since 2.0
|
||||||
|
* @version $Revision$
|
||||||
|
*/
|
||||||
|
class AnnotationClassMetadataExporterTest extends AbstractClassMetadataExporterTest
|
||||||
|
{
|
||||||
|
protected function _getType()
|
||||||
|
{
|
||||||
|
return 'annotation';
|
||||||
|
}
|
||||||
|
}
|
@ -1,151 +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\Tests\ORM\Tools\Export;
|
|
||||||
|
|
||||||
use Doctrine\ORM\Tools\Export\ClassMetadataExporter;
|
|
||||||
|
|
||||||
require_once __DIR__ . '/../../../TestInit.php';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Test case for ClassMetadataExporter
|
|
||||||
*
|
|
||||||
* @author Jonathan H. Wage <jonwage@gmail.com>
|
|
||||||
* @author Roman Borschel <roman@code-factory.org
|
|
||||||
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
|
|
||||||
* @link http://www.phpdoctrine.org
|
|
||||||
* @since 2.0
|
|
||||||
* @version $Revision$
|
|
||||||
*/
|
|
||||||
class ClassMetadataExporterTest extends \Doctrine\Tests\OrmTestCase
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Test that we can get the different types of exporters
|
|
||||||
*/
|
|
||||||
public function testGetExporter()
|
|
||||||
{
|
|
||||||
$cme = new ClassMetadataExporter();
|
|
||||||
|
|
||||||
$exporter = $cme->getExporter('xml');
|
|
||||||
$this->assertTrue($exporter instanceof \Doctrine\ORM\Tools\Export\Driver\XmlExporter);
|
|
||||||
|
|
||||||
$exporter = $cme->getExporter('yml');
|
|
||||||
$this->assertTrue($exporter instanceof \Doctrine\ORM\Tools\Export\Driver\YamlExporter);
|
|
||||||
|
|
||||||
$exporter = $cme->getExporter('annotation');
|
|
||||||
$this->assertTrue($exporter instanceof \Doctrine\ORM\Tools\Export\Driver\AnnotationExporter);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Test that we can add mapping directories for the different types of
|
|
||||||
* mapping information.
|
|
||||||
*/
|
|
||||||
public function testAddMappingDirectory()
|
|
||||||
{
|
|
||||||
$cme = new ClassMetadataExporter();
|
|
||||||
$cme->addMappingSource(__DIR__ . '/annotation', 'annotation');
|
|
||||||
$cme->addMappingSource(__DIR__ . '/php', 'php');
|
|
||||||
$cme->addMappingSource(__DIR__ . '/xml', 'xml');
|
|
||||||
$cme->addMappingSource(__DIR__ . '/yml', 'yml');
|
|
||||||
|
|
||||||
$mappingSources = $cme->getMappingSources();
|
|
||||||
$this->assertEquals(4, count($mappingSources));
|
|
||||||
|
|
||||||
$this->assertEquals($mappingSources[0][0], __DIR__.'/annotation');
|
|
||||||
$this->assertTrue($mappingSources[0][1] instanceof \Doctrine\ORM\Mapping\Driver\AnnotationDriver);
|
|
||||||
|
|
||||||
$this->assertEquals($mappingSources[1][0], __DIR__.'/php');
|
|
||||||
$this->assertTrue($mappingSources[1][1] instanceof \Doctrine\ORM\Mapping\Driver\PhpDriver);
|
|
||||||
|
|
||||||
$this->assertEquals($mappingSources[2][0], __DIR__.'/xml');
|
|
||||||
$this->assertTrue($mappingSources[2][1] instanceof \Doctrine\ORM\Mapping\Driver\XmlDriver);
|
|
||||||
|
|
||||||
$this->assertEquals($mappingSources[3][0], __DIR__.'/yml');
|
|
||||||
$this->assertTrue($mappingSources[3][1] instanceof \Doctrine\ORM\Mapping\Driver\YamlDriver);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Test that we can add mapping directories then retrieve all the defined
|
|
||||||
* ClassMetadata instances that are defined in the directories
|
|
||||||
*/
|
|
||||||
public function testGetMetadataInstances()
|
|
||||||
{
|
|
||||||
$cme = new ClassMetadataExporter();
|
|
||||||
$cme->addMappingSource(__DIR__ . '/php', 'php');
|
|
||||||
$cme->addMappingSource(__DIR__ . '/xml', 'xml');
|
|
||||||
$cme->addMappingSource(__DIR__ . '/yml', 'yml');
|
|
||||||
|
|
||||||
$metadataInstances = $cme->getMetadatasForMappingSources();
|
|
||||||
|
|
||||||
$this->assertEquals(3, count($metadataInstances));
|
|
||||||
$this->assertEquals('PhpTest', $metadataInstances['PhpTest']->name);
|
|
||||||
$this->assertEquals('XmlTest', $metadataInstances['XmlTest']->name);
|
|
||||||
$this->assertEquals('YmlTest', $metadataInstances['YmlTest']->name);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Test that we can export mapping directories to another format and that
|
|
||||||
* the exported data can then be read back in properly.
|
|
||||||
*/
|
|
||||||
public function testExport()
|
|
||||||
{
|
|
||||||
$exportDir = __DIR__ . '/export';
|
|
||||||
|
|
||||||
if ( ! is_dir($exportDir)) {
|
|
||||||
mkdir($exportDir, 0777, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
$types = array('annotation', 'php', 'xml', 'yml');
|
|
||||||
|
|
||||||
$cme = new ClassMetadataExporter();
|
|
||||||
$cme->addMappingSource(__DIR__ . '/php', 'php');
|
|
||||||
$cme->addMappingSource(__DIR__ . '/xml', 'xml');
|
|
||||||
$cme->addMappingSource(__DIR__ . '/yml', 'yml');
|
|
||||||
|
|
||||||
foreach ($types as $type) {
|
|
||||||
// Export the above mapping directories to the type
|
|
||||||
$exporter = $cme->getExporter($type, __DIR__ . '/export/' . $type);
|
|
||||||
$exporter->setMetadatas($cme->getMetadatasForMappingSources());
|
|
||||||
$exporter->export();
|
|
||||||
|
|
||||||
// Make sure the files were written
|
|
||||||
$this->assertTrue(file_exists(__DIR__ . '/export/' . $type . '/PhpTest'.$exporter->getExtension()));
|
|
||||||
$this->assertTrue(file_exists(__DIR__ . '/export/' . $type . '/XmlTest'.$exporter->getExtension()));
|
|
||||||
$this->assertTrue(file_exists(__DIR__ . '/export/' . $type . '/YmlTest'.$exporter->getExtension()));
|
|
||||||
|
|
||||||
// Try and read back in the exported mapping files to make sure they are valid
|
|
||||||
$cme2 = new ClassMetadataExporter();
|
|
||||||
$cme2->addMappingSource(__DIR__ . '/export/' . $type, $type);
|
|
||||||
$metadataInstances = $cme2->getMetadatasForMappingSources();
|
|
||||||
$this->assertEquals(3, count($metadataInstances));
|
|
||||||
$this->assertEquals('PhpTest', $metadataInstances['PhpTest']->name);
|
|
||||||
$this->assertEquals('XmlTest', $metadataInstances['XmlTest']->name);
|
|
||||||
$this->assertEquals('YmlTest', $metadataInstances['YmlTest']->name);
|
|
||||||
|
|
||||||
// Cleanup
|
|
||||||
unlink(__DIR__ . '/export/' . $type . '/PhpTest'.$exporter->getExtension());
|
|
||||||
unlink(__DIR__ . '/export/' . $type . '/XmlTest'.$exporter->getExtension());
|
|
||||||
unlink(__DIR__ . '/export/' . $type . '/YmlTest'.$exporter->getExtension());
|
|
||||||
rmdir(__DIR__ . '/export/'.$type);
|
|
||||||
}
|
|
||||||
rmdir(__DIR__ . '/export');
|
|
||||||
}
|
|
||||||
}
|
|
@ -0,0 +1,42 @@
|
|||||||
|
<?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\Tests\ORM\Tools\Export;
|
||||||
|
|
||||||
|
require_once __DIR__ . '/../../../TestInit.php';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test case for PhpClassMetadataExporterTest
|
||||||
|
*
|
||||||
|
* @author Jonathan H. Wage <jonwage@gmail.com>
|
||||||
|
* @author Roman Borschel <roman@code-factory.org
|
||||||
|
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
|
||||||
|
* @link http://www.phpdoctrine.org
|
||||||
|
* @since 2.0
|
||||||
|
* @version $Revision$
|
||||||
|
*/
|
||||||
|
class PhpClassMetadataExporterTest extends AbstractClassMetadataExporterTest
|
||||||
|
{
|
||||||
|
protected function _getType()
|
||||||
|
{
|
||||||
|
return 'php';
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,42 @@
|
|||||||
|
<?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\Tests\ORM\Tools\Export;
|
||||||
|
|
||||||
|
require_once __DIR__ . '/../../../TestInit.php';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test case for XmlClassMetadataExporterTest
|
||||||
|
*
|
||||||
|
* @author Jonathan H. Wage <jonwage@gmail.com>
|
||||||
|
* @author Roman Borschel <roman@code-factory.org
|
||||||
|
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
|
||||||
|
* @link http://www.phpdoctrine.org
|
||||||
|
* @since 2.0
|
||||||
|
* @version $Revision$
|
||||||
|
*/
|
||||||
|
class XmlClassMetadataExporterTest extends AbstractClassMetadataExporterTest
|
||||||
|
{
|
||||||
|
protected function _getType()
|
||||||
|
{
|
||||||
|
return 'xml';
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,42 @@
|
|||||||
|
<?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\Tests\ORM\Tools\Export;
|
||||||
|
|
||||||
|
require_once __DIR__ . '/../../../TestInit.php';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test case for YamlClassMetadataExporterTest
|
||||||
|
*
|
||||||
|
* @author Jonathan H. Wage <jonwage@gmail.com>
|
||||||
|
* @author Roman Borschel <roman@code-factory.org
|
||||||
|
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
|
||||||
|
* @link http://www.phpdoctrine.org
|
||||||
|
* @since 2.0
|
||||||
|
* @version $Revision$
|
||||||
|
*/
|
||||||
|
class YamlClassMetadataExporterTest extends AbstractClassMetadataExporterTest
|
||||||
|
{
|
||||||
|
protected function _getType()
|
||||||
|
{
|
||||||
|
return 'yaml';
|
||||||
|
}
|
||||||
|
}
|
@ -1,52 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @Entity
|
|
||||||
* @Table(name="annotation_test")
|
|
||||||
*/
|
|
||||||
class AnnotationTest
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* @Column(type="integer")
|
|
||||||
* @Id
|
|
||||||
* @GeneratedValue(strategy="AUTO")
|
|
||||||
*/
|
|
||||||
private $id;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @Column(type="string", length=50)
|
|
||||||
*/
|
|
||||||
private $name;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set id
|
|
||||||
*/
|
|
||||||
public function setId($value)
|
|
||||||
{
|
|
||||||
$this->id = $value;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get id
|
|
||||||
*/
|
|
||||||
public function getId()
|
|
||||||
{
|
|
||||||
return $this->id;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set name
|
|
||||||
*/
|
|
||||||
public function setName($value)
|
|
||||||
{
|
|
||||||
$this->name = $value;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get name
|
|
||||||
*/
|
|
||||||
public function getName()
|
|
||||||
{
|
|
||||||
return $this->name;
|
|
||||||
}
|
|
||||||
}
|
|
@ -0,0 +1,68 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Doctrine\Tests\ORM\Tools\Export;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Entity
|
||||||
|
* @HasLifecycleCallbacks
|
||||||
|
* @Table(name="cms_users")
|
||||||
|
*/
|
||||||
|
class User
|
||||||
|
{
|
||||||
|
/** @Id @Column(type="integer") @generatedValue(strategy="AUTO") */
|
||||||
|
public $id;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Column(length=50, nullable=true, unique=true)
|
||||||
|
*/
|
||||||
|
public $name;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Column(name="user_email", columnDefinition="CHAR(32) NOT NULL")
|
||||||
|
*/
|
||||||
|
public $email;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @OneToOne(targetEntity="Doctrine\Tests\ORM\Tools\Export\Address", cascade={"remove"})
|
||||||
|
* @JoinColumn(name="address_id", onDelete="CASCADE", onUpdate="CASCADE")
|
||||||
|
*/
|
||||||
|
public $address;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @OneToMany(targetEntity="Doctrine\Tests\ORM\Tools\Export\Phonenumber", mappedBy="user", cascade={"persist"})
|
||||||
|
* @OrderBy({"number"="ASC"})
|
||||||
|
*/
|
||||||
|
public $phonenumbers;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ManyToMany(targetEntity="Doctrine\Tests\ORM\Tools\Export\Group", cascade={"all"})
|
||||||
|
* @JoinTable(name="cms_users_groups",
|
||||||
|
* joinColumns={@JoinColumn(name="user_id", referencedColumnName="id", nullable=false, unique=false)},
|
||||||
|
* inverseJoinColumns={@JoinColumn(name="group_id", referencedColumnName="id", columnDefinition="INT NULL")}
|
||||||
|
* )
|
||||||
|
*/
|
||||||
|
public $groups;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @PrePersist
|
||||||
|
*/
|
||||||
|
public function doStuffOnPrePersist()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @PrePersist
|
||||||
|
*/
|
||||||
|
public function doOtherStuffOnPrePersistToo()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @PostPersist
|
||||||
|
*/
|
||||||
|
public function doStuffOnPostPersist()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,104 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Doctrine\ORM\Mapping\ClassMetadataInfo;
|
||||||
|
|
||||||
|
$metadata->setInheritanceType(ClassMetadataInfo::INHERITANCE_TYPE_NONE);
|
||||||
|
$metadata->setPrimaryTable(array(
|
||||||
|
'name' => 'cms_users',
|
||||||
|
));
|
||||||
|
$metadata->setChangeTrackingPolicy(ClassMetadataInfo::CHANGETRACKING_DEFERRED_IMPLICIT);
|
||||||
|
$metadata->addLifecycleCallback('doStuffOnPrePersist', 'prePersist');
|
||||||
|
$metadata->addLifecycleCallback('doOtherStuffOnPrePersistToo', 'prePersist');
|
||||||
|
$metadata->addLifecycleCallback('doStuffOnPostPersist', 'postPersist');
|
||||||
|
$metadata->mapField(array(
|
||||||
|
'id' => true,
|
||||||
|
'fieldName' => 'id',
|
||||||
|
'type' => 'integer',
|
||||||
|
'columnName' => 'id',
|
||||||
|
));
|
||||||
|
$metadata->mapField(array(
|
||||||
|
'fieldName' => 'name',
|
||||||
|
'type' => 'string',
|
||||||
|
'length' => 50,
|
||||||
|
'unique' => true,
|
||||||
|
'nullable' => true,
|
||||||
|
'columnName' => 'name',
|
||||||
|
));
|
||||||
|
$metadata->mapField(array(
|
||||||
|
'fieldName' => 'email',
|
||||||
|
'type' => 'string',
|
||||||
|
'columnName' => 'user_email',
|
||||||
|
'columnDefinition' => 'CHAR(32) NOT NULL',
|
||||||
|
));
|
||||||
|
$metadata->setIdGeneratorType(ClassMetadataInfo::GENERATOR_TYPE_AUTO);
|
||||||
|
$metadata->mapOneToOne(array(
|
||||||
|
'fieldName' => 'address',
|
||||||
|
'targetEntity' => 'Doctrine\\Tests\\ORM\\Tools\\Export\\Address',
|
||||||
|
'cascade' =>
|
||||||
|
array(
|
||||||
|
0 => 'remove',
|
||||||
|
),
|
||||||
|
'mappedBy' => NULL,
|
||||||
|
'joinColumns' =>
|
||||||
|
array(
|
||||||
|
0 =>
|
||||||
|
array(
|
||||||
|
'name' => 'address_id',
|
||||||
|
'referencedColumnName' => 'id',
|
||||||
|
'onDelete' => 'CASCADE',
|
||||||
|
'onUpdate' => 'CASCADE'
|
||||||
|
),
|
||||||
|
),
|
||||||
|
'orphanRemoval' => false,
|
||||||
|
));
|
||||||
|
$metadata->mapOneToMany(array(
|
||||||
|
'fieldName' => 'phonenumbers',
|
||||||
|
'targetEntity' => 'Doctrine\\Tests\\ORM\\Tools\\Export\\Phonenumber',
|
||||||
|
'cascade' =>
|
||||||
|
array(
|
||||||
|
1 => 'persist',
|
||||||
|
),
|
||||||
|
'mappedBy' => 'user',
|
||||||
|
'orphanRemoval' => false,
|
||||||
|
'orderBy' =>
|
||||||
|
array(
|
||||||
|
'number' => 'ASC',
|
||||||
|
),
|
||||||
|
));
|
||||||
|
$metadata->mapManyToMany(array(
|
||||||
|
'fieldName' => 'groups',
|
||||||
|
'targetEntity' => 'Doctrine\\Tests\\ORM\\Tools\\Export\\Group',
|
||||||
|
'cascade' =>
|
||||||
|
array(
|
||||||
|
0 => 'remove',
|
||||||
|
1 => 'persist',
|
||||||
|
2 => 'refresh',
|
||||||
|
3 => 'merge',
|
||||||
|
4 => 'detach',
|
||||||
|
),
|
||||||
|
'mappedBy' => NULL,
|
||||||
|
'joinTable' =>
|
||||||
|
array(
|
||||||
|
'name' => 'cms_users_groups',
|
||||||
|
'joinColumns' =>
|
||||||
|
array(
|
||||||
|
0 =>
|
||||||
|
array(
|
||||||
|
'name' => 'user_id',
|
||||||
|
'referencedColumnName' => 'id',
|
||||||
|
'unique' => false,
|
||||||
|
'nullable' => false,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
'inverseJoinColumns' =>
|
||||||
|
array(
|
||||||
|
0 =>
|
||||||
|
array(
|
||||||
|
'name' => 'group_id',
|
||||||
|
'referencedColumnName' => 'id',
|
||||||
|
'columnDefinition' => 'INT NULL',
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
'orderBy' => NULL,
|
||||||
|
));
|
@ -1,23 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
use Doctrine\ORM\Mapping\ClassMetadataInfo;
|
|
||||||
|
|
||||||
$metadata = new ClassMetadataInfo('PhpTest');
|
|
||||||
$metadata->setInheritanceType(ClassMetadataInfo::INHERITANCE_TYPE_NONE);
|
|
||||||
$metadata->setPrimaryTable(array(
|
|
||||||
'name' => 'php_test',
|
|
||||||
));
|
|
||||||
$metadata->setChangeTrackingPolicy(ClassMetadataInfo::CHANGETRACKING_DEFERRED_IMPLICIT);
|
|
||||||
$metadata->mapField(array(
|
|
||||||
'id' => true,
|
|
||||||
'fieldName' => 'id',
|
|
||||||
'type' => 'integer',
|
|
||||||
'columnName' => 'id',
|
|
||||||
));
|
|
||||||
$metadata->mapField(array(
|
|
||||||
'fieldName' => 'name',
|
|
||||||
'type' => 'string',
|
|
||||||
'length' => 50,
|
|
||||||
'columnName' => 'name',
|
|
||||||
));
|
|
||||||
$metadata->setIdGeneratorType(ClassMetadataInfo::GENERATOR_TYPE_AUTO);
|
|
@ -0,0 +1,53 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
|
||||||
|
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping
|
||||||
|
http://www.doctrine-project.org/schemas/orm/doctrine-mapping.xsd">
|
||||||
|
|
||||||
|
<entity name="Doctrine\Tests\ORM\Tools\Export\User" table="cms_users">
|
||||||
|
|
||||||
|
<lifecycle-callbacks>
|
||||||
|
<lifecycle-callback type="prePersist" method="doStuffOnPrePersist"/>
|
||||||
|
<lifecycle-callback type="prePersist" method="doOtherStuffOnPrePersistToo"/>
|
||||||
|
<lifecycle-callback type="postPersist" method="doStuffOnPostPersist"/>
|
||||||
|
</lifecycle-callbacks>
|
||||||
|
|
||||||
|
<id name="id" type="integer" column="id">
|
||||||
|
<generator strategy="AUTO"/>
|
||||||
|
</id>
|
||||||
|
|
||||||
|
<field name="name" column="name" type="string" length="50" nullable="true" unique="true" />
|
||||||
|
<field name="email" column="user_email" type="string" column-definition="CHAR(32) NOT NULL" />
|
||||||
|
|
||||||
|
<one-to-one field="address" target-entity="Doctrine\Tests\ORM\Tools\Export\Address">
|
||||||
|
<cascade><cascade-remove /></cascade>
|
||||||
|
<join-column name="address_id" referenced-column-name="id" on-delete="CASCADE" on-update="CASCADE"/>
|
||||||
|
</one-to-one>
|
||||||
|
|
||||||
|
<one-to-many field="phonenumbers" target-entity="Doctrine\Tests\ORM\Tools\Export\Phonenumber" mapped-by="user">
|
||||||
|
<order-by>
|
||||||
|
<order-by-field name="number" direction="ASC" />
|
||||||
|
</order-by>
|
||||||
|
<cascade>
|
||||||
|
<cascade-persist/>
|
||||||
|
</cascade>
|
||||||
|
</one-to-many>
|
||||||
|
|
||||||
|
<many-to-many field="groups" target-entity="Doctrine\Tests\ORM\Tools\Export\Group">
|
||||||
|
<cascade>
|
||||||
|
<cascade-all/>
|
||||||
|
</cascade>
|
||||||
|
<join-table name="cms_users_groups">
|
||||||
|
<join-columns>
|
||||||
|
<join-column name="user_id" referenced-column-name="id" nullable="false" unique="false" />
|
||||||
|
</join-columns>
|
||||||
|
<inverse-join-columns>
|
||||||
|
<join-column name="group_id" referenced-column-name="id" column-definition="INT NULL" />
|
||||||
|
</inverse-join-columns>
|
||||||
|
</join-table>
|
||||||
|
</many-to-many>
|
||||||
|
|
||||||
|
</entity>
|
||||||
|
|
||||||
|
</doctrine-mapping>
|
@ -1,2 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping" xsi="http://www.w3.org/2001/XMLSchema-instance" schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd"><entity name="XmlTest" table="xml_test"><change-tracking-policy>DEFERRED_IMPLICIT</change-tracking-policy><field name="name" type="string" column="name" length="50"/><id name="id" type="integer" column="id"><generator strategy="AUTO"/></id></entity></doctrine-mapping>
|
|
@ -0,0 +1,53 @@
|
|||||||
|
Doctrine\Tests\ORM\Tools\Export\User:
|
||||||
|
type: entity
|
||||||
|
table: cms_users
|
||||||
|
id:
|
||||||
|
id:
|
||||||
|
type: integer
|
||||||
|
generator:
|
||||||
|
strategy: AUTO
|
||||||
|
fields:
|
||||||
|
name:
|
||||||
|
type: string
|
||||||
|
length: 50
|
||||||
|
nullable: true
|
||||||
|
unique: true
|
||||||
|
email:
|
||||||
|
type: string
|
||||||
|
column: user_email
|
||||||
|
columnDefinition: CHAR(32) NOT NULL
|
||||||
|
oneToOne:
|
||||||
|
address:
|
||||||
|
targetEntity: Doctrine\Tests\ORM\Tools\Export\Address
|
||||||
|
joinColumn:
|
||||||
|
name: address_id
|
||||||
|
referencedColumnName: id
|
||||||
|
onDelete: CASCADE
|
||||||
|
onUpdate: CASCADE
|
||||||
|
cascade: [ remove ]
|
||||||
|
oneToMany:
|
||||||
|
phonenumbers:
|
||||||
|
targetEntity: Doctrine\Tests\ORM\Tools\Export\Phonenumber
|
||||||
|
mappedBy: user
|
||||||
|
orderBy:
|
||||||
|
number: ASC
|
||||||
|
cascade: [ persist ]
|
||||||
|
manyToMany:
|
||||||
|
groups:
|
||||||
|
targetEntity: Doctrine\Tests\ORM\Tools\Export\Group
|
||||||
|
joinTable:
|
||||||
|
name: cms_users_groups
|
||||||
|
joinColumns:
|
||||||
|
user_id:
|
||||||
|
referencedColumnName: id
|
||||||
|
nullable: false
|
||||||
|
unique: false
|
||||||
|
inverseJoinColumns:
|
||||||
|
group_id:
|
||||||
|
referencedColumnName: id
|
||||||
|
columnDefinition: INT NULL
|
||||||
|
cascade:
|
||||||
|
- all
|
||||||
|
lifecycleCallbacks:
|
||||||
|
prePersist: [ doStuffOnPrePersist, doOtherStuffOnPrePersistToo ]
|
||||||
|
postPersist: [ doStuffOnPostPersist ]
|
@ -1,12 +0,0 @@
|
|||||||
YmlTest:
|
|
||||||
type: entity
|
|
||||||
table: yml_test
|
|
||||||
id:
|
|
||||||
id:
|
|
||||||
type: integer
|
|
||||||
generator:
|
|
||||||
strategy: AUTO
|
|
||||||
fields:
|
|
||||||
name:
|
|
||||||
type: string
|
|
||||||
length: 50
|
|
Loading…
Reference in New Issue
Block a user