diff --git a/lib/Doctrine/ORM/Tools/Export/Driver/XmlExporter.php b/lib/Doctrine/ORM/Tools/Export/Driver/XmlExporter.php index 01309475b..869580613 100644 --- a/lib/Doctrine/ORM/Tools/Export/Driver/XmlExporter.php +++ b/lib/Doctrine/ORM/Tools/Export/Driver/XmlExporter.php @@ -279,6 +279,9 @@ class XmlExporter extends AbstractExporter if ($associationMapping['isCascadeDetach']) { $cascade[] = 'cascade-detach'; } + if (count($cascade) === 5) { + $cascade = array('cascade-all'); + } if ($cascade) { $cascadeXml = $associationMappingXml->addChild('cascade'); foreach ($cascade as $type) { diff --git a/lib/Doctrine/ORM/Tools/Export/Driver/YamlExporter.php b/lib/Doctrine/ORM/Tools/Export/Driver/YamlExporter.php index e8410db2d..de76c7bdd 100644 --- a/lib/Doctrine/ORM/Tools/Export/Driver/YamlExporter.php +++ b/lib/Doctrine/ORM/Tools/Export/Driver/YamlExporter.php @@ -147,6 +147,9 @@ class YamlExporter extends AbstractExporter if ($associationMapping['isCascadeDetach']) { $cascade[] = 'detach'; } + if (count($cascade) === 5) { + $cascade = array('all'); + } $associationMappingArray = array( 'targetEntity' => $associationMapping['targetEntity'], 'cascade' => $cascade, diff --git a/tests/Doctrine/Tests/ORM/Tools/Export/AbstractClassMetadataExporterTest.php b/tests/Doctrine/Tests/ORM/Tools/Export/AbstractClassMetadataExporterTest.php index 2571a1b98..6ff3d1808 100644 --- a/tests/Doctrine/Tests/ORM/Tools/Export/AbstractClassMetadataExporterTest.php +++ b/tests/Doctrine/Tests/ORM/Tools/Export/AbstractClassMetadataExporterTest.php @@ -324,7 +324,33 @@ abstract class AbstractClassMetadataExporterTest extends \Doctrine\Tests\OrmTest { $this->assertEquals('user', $class->associationMappings['address']['inversedBy']); } + /** + * @depends testExportDirectoryAndFilesAreCreated + */ + public function testCascadeAllCollapsed() + { + $type = $this->_getType(); + if ($type == 'xml') { + $xml = simplexml_load_file(__DIR__ . '/export/'.$type.'/Doctrine.Tests.ORM.Tools.Export.ExportedUser.dcm.xml'); + $xml->registerXPathNamespace("d", "http://doctrine-project.org/schemas/orm/doctrine-mapping"); + $nodes = $xml->xpath("/d:doctrine-mapping/d:entity/d:one-to-many[@field='interests']/d:cascade/d:*"); + $this->assertEquals(1, count($nodes)); + + $this->assertEquals('cascade-all', $nodes[0]->getName()); + } elseif ($type == 'yaml') { + + $yaml = new \Symfony\Component\Yaml\Parser(); + $value = $yaml->parse(file_get_contents(__DIR__ . '/export/'.$type.'/Doctrine.Tests.ORM.Tools.Export.ExportedUser.dcm.yml')); + + $this->assertTrue(isset($value['Doctrine\Tests\ORM\Tools\Export\ExportedUser']['oneToMany']['interests']['cascade'])); + $this->assertEquals(1, count($value['Doctrine\Tests\ORM\Tools\Export\ExportedUser']['oneToMany']['interests']['cascade'])); + $this->assertEquals('all', $value['Doctrine\Tests\ORM\Tools\Export\ExportedUser']['oneToMany']['interests']['cascade'][0]); + + } else { + $this->markTestSkipped('Test aviable only for '.$type.' dirver'); + } + } public function __destruct() { # $this->_deleteDirectory(__DIR__ . '/export/'.$this->_getType()); diff --git a/tests/Doctrine/Tests/ORM/Tools/Export/xml/Doctrine.Tests.ORM.Tools.Export.User.dcm.xml b/tests/Doctrine/Tests/ORM/Tools/Export/xml/Doctrine.Tests.ORM.Tools.Export.User.dcm.xml index c562003c6..843882278 100644 --- a/tests/Doctrine/Tests/ORM/Tools/Export/xml/Doctrine.Tests.ORM.Tools.Export.User.dcm.xml +++ b/tests/Doctrine/Tests/ORM/Tools/Export/xml/Doctrine.Tests.ORM.Tools.Export.User.dcm.xml @@ -35,6 +35,16 @@ + + + + + + + + + + diff --git a/tests/Doctrine/Tests/ORM/Tools/Export/yaml/Doctrine.Tests.ORM.Tools.Export.User.dcm.yml b/tests/Doctrine/Tests/ORM/Tools/Export/yaml/Doctrine.Tests.ORM.Tools.Export.User.dcm.yml index 9231bb189..ee48d8511 100644 --- a/tests/Doctrine/Tests/ORM/Tools/Export/yaml/Doctrine.Tests.ORM.Tools.Export.User.dcm.yml +++ b/tests/Doctrine/Tests/ORM/Tools/Export/yaml/Doctrine.Tests.ORM.Tools.Export.User.dcm.yml @@ -34,6 +34,11 @@ Doctrine\Tests\ORM\Tools\Export\User: number: ASC cascade: [ persist, merge ] orphanRemoval: true + interests: + targetEntity: Doctrine\Tests\ORM\Tools\Export\Interests + mappedBy: user + cascade: [ persist, merge, remove, refresh, detach ] + orphanRemoval: true manyToMany: groups: targetEntity: Doctrine\Tests\ORM\Tools\Export\Group