Commit 770d00ab authored by jwage's avatar jwage

[2.0] Improving test coverage for mapping exporters as well as adding missing functionality

parent 1d60c65d
......@@ -66,6 +66,6 @@ class PhpDriver extends AbstractFileDriver
protected function _loadMappingFile($file)
{
$metadata = $this->_metadata;
require_once $file;
include $file;
}
}
\ No newline at end of file
......@@ -80,7 +80,7 @@ abstract class AbstractExporter
public function export()
{
if ( ! is_dir($this->_outputDir)) {
mkdir($this->_outputDir, 0777);
mkdir($this->_outputDir, 0777, true);
}
foreach ($this->_metadatas as $metadata) {
......
......@@ -232,17 +232,40 @@ class AnnotationExporter extends AbstractExporter
private function _getEntityAnnotation($metadata)
{
if ($metadata->isMappedSuperclass) {
return '@MappedSupperClass';
$lines = array();
$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) {
$str .= '(repositoryClass="' . $metadata->customRepositoryClassName . '")';
$lines[count($lines) - 1] .= '(repositoryClass="' . $metadata->customRepositoryClassName . '")';
}
if (isset($metadata->lifecycleCallbacks) && $metadata->lifecycleCallbacks) {
$lines[] = ' * @HasLifecycleCallbacks';
}
return $str;
$lines[] = ' */';
$lines[] = '';
return implode("\n", $lines);
}
private function _getTableAnnotation($metadata)
......@@ -350,6 +373,23 @@ class AnnotationExporter extends AbstractExporter
$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)
{
$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;
}
......@@ -404,6 +452,9 @@ class AnnotationExporter extends AbstractExporter
if (isset($joinColumn['onUpdate'])) {
$joinColumnAnnot[] = 'onUpdate=' . ($joinColumn['onUpdate'] ? 'true' : 'false');
}
if (isset($joinColumn['columnDefinition'])) {
$joinColumnAnnot[] = 'columnDefinition="' . $joinColumn['columnDefinition'] . '"';
}
return '@JoinColumn(' . implode(', ', $joinColumnAnnot) . ')';
}
......@@ -472,6 +523,15 @@ class AnnotationExporter extends AbstractExporter
$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 . ' */';
return implode("\n", $lines);
......@@ -501,6 +561,9 @@ class AnnotationExporter extends AbstractExporter
if (isset($fieldMapping['nullable'])) {
$column[] = 'nullable=' . var_export($fieldMapping['nullable'], true);
}
if (isset($fieldMapping['columnDefinition'])) {
$column[] = 'columnDefinition="' . $fieldMapping['columnDefinition'] . '"';
}
if (isset($fieldMapping['options'])) {
$options = array();
foreach ($fieldMapping['options'] as $key => $value) {
......
......@@ -160,6 +160,9 @@ class XmlExporter extends AbstractExporter
if (isset($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->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']);
}
}
$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();
if ($associationMapping->isCascadeRemove) {
$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);
}
......
......@@ -133,15 +133,25 @@ class YamlExporter extends AbstractExporter
$associations = array();
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(
'targetEntity' => $associationMapping->targetEntityName,
'cascade' => array(
'remove' => $associationMapping->isCascadeRemove,
'persist' => $associationMapping->isCascadePersist,
'refresh' => $associationMapping->isCascadeRefresh,
'merge' => $associationMapping->isCascadeMerge,
'detach' => $associationMapping->isCascadeDetach,
),
'cascade' => $cascade,
);
if ($associationMapping instanceof OneToOneMapping) {
......@@ -149,6 +159,12 @@ class YamlExporter extends AbstractExporter
$newJoinColumns = array();
foreach ($joinColumns as $joinColumn) {
$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(
'mappedBy' => $associationMapping->mappedBy,
......@@ -162,6 +178,7 @@ class YamlExporter extends AbstractExporter
$oneToManyMappingArray = array(
'mappedBy' => $associationMapping->mappedBy,
'orphanRemoval' => $associationMapping->orphanRemoval,
'orderBy' => $associationMapping->orderBy
);
$associationMappingArray = array_merge($associationMappingArray, $oneToManyMappingArray);
......@@ -170,12 +187,16 @@ class YamlExporter extends AbstractExporter
$manyToManyMappingArray = array(
'mappedBy' => $associationMapping->mappedBy,
'joinTable' => $associationMapping->joinTable,
'orderBy' => $associationMapping->orderBy
);
$associationMappingArray = array_merge($associationMappingArray, $manyToManyMappingArray);
$array['manyToMany'][$name] = $associationMappingArray;
}
}
if (isset($metadata->lifecycleCallbacks)) {
$array['lifecycleCallbacks'] = $metadata->lifecycleCallbacks;
}
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() ?>;
<?php endif; ?>
/**
* <?php echo $this->_getEntityAnnotation($metadata)."\n"; ?>
* <?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 echo $this->_getEntityAnnotation($metadata) ?>
class <?php echo $this->_getClassName($metadata); ?><?php if ($this->_extendsClass()): ?> extends <?php echo $this->_getClassToExtendName() ?><?php endif; ?>
{
<?php include('annotation_body.tpl.php') ?>
}
\ No newline at end of file
......@@ -210,7 +210,7 @@ abstract class AbstractMappingDriverTest extends \Doctrine\Tests\OrmTestCase
*/
class User
{
/** @Id @Column(type="int") @generatedValue(strategy="AUTO") */
/** @Id @Column(type="integer") @generatedValue(strategy="AUTO") */
public $id;
/**
......
......@@ -20,7 +20,10 @@ class AllTests
{
$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\SchemaToolTest');
......
<?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';
}
}
\ No newline at end of file
<?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');
}
}
\ No newline at end of file
<?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';
}
}
\ No newline at end of file
<?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';
}
}
\ No newline at end of file
<?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';
}
}
\ No newline at end of file
<?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;
}
}
\ No newline at end of file
<?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()
{
}
}
\ No newline at end of file
<?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,
));
\ No newline at end of file
<?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);
\ No newline at end of file
<?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>
<?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>
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 ]
\ No newline at end of file
YmlTest:
type: entity
table: yml_test
id:
id:
type: integer
generator:
strategy: AUTO
fields:
name:
type: string
length: 50
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment