From 97321a1ff2cf0949ba5317522a748558d22b3792 Mon Sep 17 00:00:00 2001 From: Asmir Mustafic Date: Tue, 18 Oct 2011 16:18:25 +0200 Subject: [PATCH 1/5] Collapsed cascade elements, if cascade-all. (better readability for generated xml) --- lib/Doctrine/ORM/Tools/Export/Driver/XmlExporter.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/Doctrine/ORM/Tools/Export/Driver/XmlExporter.php b/lib/Doctrine/ORM/Tools/Export/Driver/XmlExporter.php index f9668c78f..9390f144f 100644 --- a/lib/Doctrine/ORM/Tools/Export/Driver/XmlExporter.php +++ b/lib/Doctrine/ORM/Tools/Export/Driver/XmlExporter.php @@ -276,6 +276,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) { From 1b83fcc46d980f2baa2c98ebf9d14b37778d9b86 Mon Sep 17 00:00:00 2001 From: Asmir Mustafic Date: Mon, 24 Oct 2011 09:20:24 +0200 Subject: [PATCH 2/5] Coding standards --- lib/Doctrine/ORM/Tools/Export/Driver/XmlExporter.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Doctrine/ORM/Tools/Export/Driver/XmlExporter.php b/lib/Doctrine/ORM/Tools/Export/Driver/XmlExporter.php index 9390f144f..5c8d97327 100644 --- a/lib/Doctrine/ORM/Tools/Export/Driver/XmlExporter.php +++ b/lib/Doctrine/ORM/Tools/Export/Driver/XmlExporter.php @@ -276,7 +276,7 @@ class XmlExporter extends AbstractExporter if ($associationMapping['isCascadeDetach']) { $cascade[] = 'cascade-detach'; } - if(count($cascade)==5){ + if(count($cascade) === 5){ $cascade = array('cascade-all'); } if ($cascade) { From cb76222e63db2eb2b3a58f666c12367cb5307c76 Mon Sep 17 00:00:00 2001 From: Asmir Mustafic Date: Mon, 24 Oct 2011 09:54:31 +0200 Subject: [PATCH 3/5] Collapse cascade persist, remove, refresh, detach, merge into cascade-all (implemented currently only for XML annotation) --- .../AbstractClassMetadataExporterTest.php | 18 +++++++++++++++++- ...octrine.Tests.ORM.Tools.Export.User.dcm.xml | 10 ++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/tests/Doctrine/Tests/ORM/Tools/Export/AbstractClassMetadataExporterTest.php b/tests/Doctrine/Tests/ORM/Tools/Export/AbstractClassMetadataExporterTest.php index 2571a1b98..a5f92d870 100644 --- a/tests/Doctrine/Tests/ORM/Tools/Export/AbstractClassMetadataExporterTest.php +++ b/tests/Doctrine/Tests/ORM/Tools/Export/AbstractClassMetadataExporterTest.php @@ -324,7 +324,23 @@ abstract class AbstractClassMetadataExporterTest extends \Doctrine\Tests\OrmTest { $this->assertEquals('user', $class->associationMappings['address']['inversedBy']); } - + /** + * @depends testOneToManyAssociationsAreExported + * @param ClassMetadataInfo $class + */ + public function testCascadeIsDetected($class) + { + if(!isset($class->associationMappings['interests'])){ + $this->markTestSkipped('The "interests" association is not aviable.'); + }else{ + $this->assertTrue($class->associationMappings['interests']['isCascadePersist']); + $this->assertTrue($class->associationMappings['interests']['isCascadeMerge']); + $this->assertTrue($class->associationMappings['interests']['isCascadeRemove']); + $this->assertTrue($class->associationMappings['interests']['isCascadeRefresh']); + $this->assertTrue($class->associationMappings['interests']['isCascadeDetach']); + } + return $class; + } 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 @@ + + + + + + + + + + From 035ca8e500f687b9d62bb555bb40aac69b6195f7 Mon Sep 17 00:00:00 2001 From: Asmir Mustafic Date: Wed, 26 Oct 2011 10:14:59 +0200 Subject: [PATCH 4/5] Collapse cascade all test --- .../AbstractClassMetadataExporterTest.php | 26 ++++++++++--------- 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/tests/Doctrine/Tests/ORM/Tools/Export/AbstractClassMetadataExporterTest.php b/tests/Doctrine/Tests/ORM/Tools/Export/AbstractClassMetadataExporterTest.php index a5f92d870..925e51550 100644 --- a/tests/Doctrine/Tests/ORM/Tools/Export/AbstractClassMetadataExporterTest.php +++ b/tests/Doctrine/Tests/ORM/Tools/Export/AbstractClassMetadataExporterTest.php @@ -325,21 +325,23 @@ abstract class AbstractClassMetadataExporterTest extends \Doctrine\Tests\OrmTest $this->assertEquals('user', $class->associationMappings['address']['inversedBy']); } /** - * @depends testOneToManyAssociationsAreExported - * @param ClassMetadataInfo $class + * @depends testExportDirectoryAndFilesAreCreated */ - public function testCascadeIsDetected($class) + public function testCascadeAllCollapsed() { - if(!isset($class->associationMappings['interests'])){ - $this->markTestSkipped('The "interests" association is not aviable.'); - }else{ - $this->assertTrue($class->associationMappings['interests']['isCascadePersist']); - $this->assertTrue($class->associationMappings['interests']['isCascadeMerge']); - $this->assertTrue($class->associationMappings['interests']['isCascadeRemove']); - $this->assertTrue($class->associationMappings['interests']['isCascadeRefresh']); - $this->assertTrue($class->associationMappings['interests']['isCascadeDetach']); + $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()); + + } else { + $this->markTestSkipped('Test aviable only for XML dirver'); } - return $class; } public function __destruct() { From d09285e9d33128f4059b3166b7340b37d836a002 Mon Sep 17 00:00:00 2001 From: Asmir Mustafic Date: Wed, 26 Oct 2011 10:59:15 +0200 Subject: [PATCH 5/5] Collapse cascade all test (YAML too) --- lib/Doctrine/ORM/Tools/Export/Driver/XmlExporter.php | 2 +- .../ORM/Tools/Export/Driver/YamlExporter.php | 3 +++ .../Export/AbstractClassMetadataExporterTest.php | 12 ++++++++++-- .../Doctrine.Tests.ORM.Tools.Export.User.dcm.yml | 5 +++++ 4 files changed, 19 insertions(+), 3 deletions(-) diff --git a/lib/Doctrine/ORM/Tools/Export/Driver/XmlExporter.php b/lib/Doctrine/ORM/Tools/Export/Driver/XmlExporter.php index 5c8d97327..f4f708e4e 100644 --- a/lib/Doctrine/ORM/Tools/Export/Driver/XmlExporter.php +++ b/lib/Doctrine/ORM/Tools/Export/Driver/XmlExporter.php @@ -276,7 +276,7 @@ class XmlExporter extends AbstractExporter if ($associationMapping['isCascadeDetach']) { $cascade[] = 'cascade-detach'; } - if(count($cascade) === 5){ + if (count($cascade) === 5) { $cascade = array('cascade-all'); } if ($cascade) { 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 925e51550..6ff3d1808 100644 --- a/tests/Doctrine/Tests/ORM/Tools/Export/AbstractClassMetadataExporterTest.php +++ b/tests/Doctrine/Tests/ORM/Tools/Export/AbstractClassMetadataExporterTest.php @@ -338,9 +338,17 @@ abstract class AbstractClassMetadataExporterTest extends \Doctrine\Tests\OrmTest $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 XML dirver'); + $this->markTestSkipped('Test aviable only for '.$type.' dirver'); } } public function __destruct() 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