From 54476882c7045e39dc309f383945af5508d552ce Mon Sep 17 00:00:00 2001 From: Christian Heinrich Date: Tue, 6 Jul 2010 17:06:31 +0200 Subject: [PATCH 1/6] CLI configured for development purposes --- tools/sandbox/cli-config.php | 61 ++++++++++++++++++++++++++---------- 1 file changed, 44 insertions(+), 17 deletions(-) diff --git a/tools/sandbox/cli-config.php b/tools/sandbox/cli-config.php index c949668e0..8e503e234 100644 --- a/tools/sandbox/cli-config.php +++ b/tools/sandbox/cli-config.php @@ -1,36 +1,63 @@ register(); -$classLoader = new \Doctrine\Common\ClassLoader('Doctrine\DBAL', realpath(__DIR__ . '/../../lib/vendor/doctrine-dbal/lib')); -$classLoader->register(); -$classLoader = new \Doctrine\Common\ClassLoader('Doctrine\Common', realpath(__DIR__ . '/../../lib/vendor/doctrine-common/lib')); -$classLoader->register(); -$classLoader = new \Doctrine\Common\ClassLoader('Symfony', realpath(__DIR__ . '/../../lib/vendor')); -$classLoader->register(); $classLoader = new \Doctrine\Common\ClassLoader('Entities', __DIR__); $classLoader->register(); + $classLoader = new \Doctrine\Common\ClassLoader('Proxies', __DIR__); $classLoader->register(); +require_once '/var/workspaces/nexxone/library/Zend/Acl/Resource/Interface.php'; +require_once '/var/workspaces/nexxone/library/Zend/Acl/Role/Interface.php'; + +$classLoader = new \Doctrine\Common\ClassLoader('Core\Model', '/var/workspaces/nexxone/application/modules/core/models/'); +$classLoader->register(); + +$classLoader = new \Doctrine\Common\ClassLoader('Content\Model', '/var/workspaces/nexxone/application/modules/content/models/'); +$classLoader->register(); + +$classLoader = new \Doctrine\Common\ClassLoader('User\Model', '/var/workspaces/nexxone/application/modules/user/models/'); +$classLoader->register(); + + $config = new \Doctrine\ORM\Configuration(); $config->setMetadataCacheImpl(new \Doctrine\Common\Cache\ArrayCache); -$driverImpl = $config->newDefaultAnnotationDriver(array(__DIR__."/Entities")); -$config->setMetadataDriverImpl($driverImpl); $config->setProxyDir(__DIR__ . '/Proxies'); -$config->setProxyNamespace('Proxies'); -$connectionOptions = array( - 'driver' => 'pdo_sqlite', - 'path' => 'database.sqlite' +$config->setProxyNamespace('LivandoCMSProxies'); +$driver = new Doctrine\ORM\Mapping\Driver\YamlDriver( + array( + '/var/workspaces/nexxone/application/modules/core/config/schema', + '/var/workspaces/nexxone/application/modules/content/config/schema', + '/var/workspaces/nexxone/application/modules/user/config/schema', + ) ); +#$driver = new Doctrine\ORM\Mapping\Driver\YamlDriver(array('./yaml/'), YamlDriver::PRELOAD); +$config->setMetadataDriverImpl($driver); -$em = \Doctrine\ORM\EntityManager::create($connectionOptions, $config); +$conn = new \Doctrine\DBAL\Connection( + array ( + 'pdo' => new PDO( + "mysql:host=localhost;dbname=nexxone;unix_socket=/var/run/mysqld/mysqld.sock", + 'root', + 'mysql5023' + ) + ), + new Doctrine\DBAL\Driver\PDOMySql\Driver(), + $config + ); + +//$connectionOptions = array( +// 'driver' => 'pdo_sqlite', +// 'path' => 'database.sqlite' +//); + +// These are required named variables (names can't change!) +$em = \Doctrine\ORM\EntityManager::create($conn, $config); $helpers = array( 'db' => new \Doctrine\DBAL\Tools\Console\Helper\ConnectionHelper($em->getConnection()), 'em' => new \Doctrine\ORM\Tools\Console\Helper\EntityManagerHelper($em) -); \ No newline at end of file +); From 9b03a1ecdde5b58fc63469016929637511c9eaca Mon Sep 17 00:00:00 2001 From: Christian Heinrich Date: Tue, 6 Jul 2010 20:19:43 +0200 Subject: [PATCH 2/6] Added testcase for #DDC-671 --- .../ORM/Mapping/YamlMappingDriverTest.php | 68 ++++++++++++++++++- ...ts.ORM.Mapping.AbstractContentItem.dcm.yml | 17 +++++ ...ctrine.Tests.ORM.Mapping.Directory.dcm.yml | 17 +++++ .../Doctrine.Tests.ORM.Mapping.Page.dcm.yml | 7 ++ 4 files changed, 108 insertions(+), 1 deletion(-) create mode 100644 tests/Doctrine/Tests/ORM/Mapping/yaml/Doctrine.Tests.ORM.Mapping.AbstractContentItem.dcm.yml create mode 100644 tests/Doctrine/Tests/ORM/Mapping/yaml/Doctrine.Tests.ORM.Mapping.Directory.dcm.yml create mode 100644 tests/Doctrine/Tests/ORM/Mapping/yaml/Doctrine.Tests.ORM.Mapping.Page.dcm.yml diff --git a/tests/Doctrine/Tests/ORM/Mapping/YamlMappingDriverTest.php b/tests/Doctrine/Tests/ORM/Mapping/YamlMappingDriverTest.php index 2aad38645..741621aa9 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/YamlMappingDriverTest.php +++ b/tests/Doctrine/Tests/ORM/Mapping/YamlMappingDriverTest.php @@ -18,4 +18,70 @@ class YamlMappingDriverTest extends AbstractMappingDriverTest return new YamlDriver(__DIR__ . DIRECTORY_SEPARATOR . 'yaml'); } -} \ No newline at end of file + public function testJoinTablesWithMappedSuperclassForYamlDriver() { + $em = $this->_getTestEntityManager(); + $em->getConfiguration()->setMetadataDriverImpl(new \Doctrine\ORM\Mapping\Driver\YamlDriver(__DIR__ .'/yaml/')); + $qb = $em->createQueryBuilder(); + + $qb->select('f') + ->from('Doctrine\Tests\ORM\Mapping\Page', 'f') + ->join('f.parentDirectory', 'd') + ->where( + $qb->expr()->andx( + $qb->expr()->eq('d.url', ':url'), + $qb->expr()->eq('f.extension', ':extension') + ) + ) + ->setParameter('url', "test") + ->setParameter('filename', "filename") + ->setParameter('extension', "extension"); + + // Is there a way to generalize this more? (Instead of a2_., check if the table prefix in the ON clause is set within a FROM or JOIN clause..) + $this->assertTrue(strpos($qb->getQuery()->getSql(), 'a2_.') === false); + } +} + +class Directory extends AbstractContentItem { + + protected $subDirectories; + + /** + * This is a collection of files that are contained in this Directory. Files, for example, could be Pages, but even other files + * like media files (css, images etc) are possible. + * + * @var \Doctrine\Common\Collections\Collection + * @access protected + */ + protected $containedFiles; + + /** + * @var string + */ + protected $url; +} + +class Page + extends AbstractContentItem { + + protected $extension = "html"; +} + +abstract class AbstractContentItem { + /** + * Doctrine2 entity id + * @var integer + */ + private $id; + + /** + * The parent directory + * @var Directory + */ + protected $parentDirectory; + + /** + * Filename (without extension) or directory name + * @var string + */ + protected $name; +} diff --git a/tests/Doctrine/Tests/ORM/Mapping/yaml/Doctrine.Tests.ORM.Mapping.AbstractContentItem.dcm.yml b/tests/Doctrine/Tests/ORM/Mapping/yaml/Doctrine.Tests.ORM.Mapping.AbstractContentItem.dcm.yml new file mode 100644 index 000000000..419eb0449 --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Mapping/yaml/Doctrine.Tests.ORM.Mapping.AbstractContentItem.dcm.yml @@ -0,0 +1,17 @@ +Doctrine\Tests\ORM\Mapping\AbstractContentItem: + type: mappedSuperclass + table: abstract_item + id: + id: + type: integer + unsigned: true + generator: + strategy: AUTO + fields: + # FilesystemIdentifier + manyToOne: + parentDirectory: + targetEntity: Doctrine\Tests\ORM\Mapping\Directory + joinColumn: + name: parent_directory_id + referencedColumnName: id diff --git a/tests/Doctrine/Tests/ORM/Mapping/yaml/Doctrine.Tests.ORM.Mapping.Directory.dcm.yml b/tests/Doctrine/Tests/ORM/Mapping/yaml/Doctrine.Tests.ORM.Mapping.Directory.dcm.yml new file mode 100644 index 000000000..129ae6b28 --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Mapping/yaml/Doctrine.Tests.ORM.Mapping.Directory.dcm.yml @@ -0,0 +1,17 @@ +Doctrine\Tests\ORM\Mapping\Directory: + type: entity + table: core_content_directories + fields: + url: + type: string + length: 255 + oneToMany: + subDirectories: + targetEntity: Doctrine\Tests\ORM\Mapping\Directory + mappedBy: parentDirectory + cascade: + [ all ] + containedFiles: + targetEntity: Doctrine\Tests\ORM\Mapping\Page + mappedBy: parentDirectory + cascade: [ remove ] diff --git a/tests/Doctrine/Tests/ORM/Mapping/yaml/Doctrine.Tests.ORM.Mapping.Page.dcm.yml b/tests/Doctrine/Tests/ORM/Mapping/yaml/Doctrine.Tests.ORM.Mapping.Page.dcm.yml new file mode 100644 index 000000000..a3b0fb836 --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Mapping/yaml/Doctrine.Tests.ORM.Mapping.Page.dcm.yml @@ -0,0 +1,7 @@ +Doctrine\Tests\ORM\Mapping\Page: + type: entity + table: core_content_pages + fields: + extension: + type: string + length: 10 From 72f65c366557bc75231d0caee8a6ba500e2e6114 Mon Sep 17 00:00:00 2001 From: Benjamin Eberlei Date: Mon, 20 Sep 2010 19:23:41 +0200 Subject: [PATCH 3/6] Some changes to the TestCase --- .../ORM/Mapping/YamlMappingDriverTest.php | 26 +++++++++---------- ...ts.ORM.Mapping.AbstractContentItem.dcm.yml | 1 - 2 files changed, 12 insertions(+), 15 deletions(-) diff --git a/tests/Doctrine/Tests/ORM/Mapping/YamlMappingDriverTest.php b/tests/Doctrine/Tests/ORM/Mapping/YamlMappingDriverTest.php index 1a60f7eb7..aa7ce716b 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/YamlMappingDriverTest.php +++ b/tests/Doctrine/Tests/ORM/Mapping/YamlMappingDriverTest.php @@ -23,23 +23,21 @@ class YamlMappingDriverTest extends AbstractMappingDriverTest { $em = $this->_getTestEntityManager(); $em->getConfiguration()->setMetadataDriverImpl(new \Doctrine\ORM\Mapping\Driver\YamlDriver(__DIR__ . '/yaml/')); - $qb = $em->createQueryBuilder(); - $qb->select('f') - ->from('Doctrine\Tests\ORM\Mapping\Page', 'f') - ->join('f.parentDirectory', 'd') - ->where( - $qb->expr()->andx( - $qb->expr()->eq('d.url', ':url'), - $qb->expr()->eq('f.extension', ':extension') - ) - ) - ->setParameter('url', "test") - ->setParameter('filename', "filename") - ->setParameter('extension', "extension"); + var_dump($em->getClassMetadata('Doctrine\Tests\ORM\Mapping\Page')); + var_dump($em->getClassMetadata('Doctrine\Tests\ORM\Mapping\Directory')); + + $dql = "SELECT f FROM Doctrine\Tests\ORM\Mapping\Page f JOIN f.parentDirectory d " . + "WHERE (d.url = :url) AND (f.extension = :extension)"; + + $query = $em->createQuery($dql) + ->setParameter('url', "test") + ->setParameter('extension', "extension"); + + var_dump($query->getSql()); // Is there a way to generalize this more? (Instead of a2_., check if the table prefix in the ON clause is set within a FROM or JOIN clause..) - $this->assertTrue(strpos($qb->getQuery()->getSql(), 'a2_.') === false); + $this->assertTrue(strpos($query->getSql(), 'a2_.') === false); } } diff --git a/tests/Doctrine/Tests/ORM/Mapping/yaml/Doctrine.Tests.ORM.Mapping.AbstractContentItem.dcm.yml b/tests/Doctrine/Tests/ORM/Mapping/yaml/Doctrine.Tests.ORM.Mapping.AbstractContentItem.dcm.yml index 419eb0449..9137619ec 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/yaml/Doctrine.Tests.ORM.Mapping.AbstractContentItem.dcm.yml +++ b/tests/Doctrine/Tests/ORM/Mapping/yaml/Doctrine.Tests.ORM.Mapping.AbstractContentItem.dcm.yml @@ -1,6 +1,5 @@ Doctrine\Tests\ORM\Mapping\AbstractContentItem: type: mappedSuperclass - table: abstract_item id: id: type: integer From 7dc8ef1db9b55ab1a76f416d78e6bd882bbbd1d5 Mon Sep 17 00:00:00 2001 From: Benjamin Eberlei Date: Tue, 21 Sep 2010 23:14:45 +0200 Subject: [PATCH 4/6] Fix DDC-671 - The sourceEntity field has to be corrected to the subclass name when copied from a mapped superclass. Otherwise DQL queries will be wrong, generating wrong table aliases. --- .../ORM/Mapping/ClassMetadataFactory.php | 4 ++ .../ORM/Mapping/AbstractMappingDriverTest.php | 47 ++++++++++++- .../ORM/Mapping/AnnotationDriverTest.php | 28 ++++++++ .../ORM/Mapping/YamlMappingDriverTest.php | 66 ++++--------------- 4 files changed, 92 insertions(+), 53 deletions(-) diff --git a/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php b/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php index 63c869b38..51994f334 100644 --- a/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php +++ b/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php @@ -379,6 +379,10 @@ class ClassMetadataFactory private function addInheritedRelations(ClassMetadata $subClass, ClassMetadata $parentClass) { foreach ($parentClass->associationMappings as $field => $mapping) { + if ($parentClass->isMappedSuperclass) { + $mapping['sourceEntity'] = $subClass->name; + } + //$subclassMapping = $mapping; if ( ! isset($mapping['inherited']) && ! $parentClass->isMappedSuperclass) { $mapping['inherited'] = $parentClass->name; diff --git a/tests/Doctrine/Tests/ORM/Mapping/AbstractMappingDriverTest.php b/tests/Doctrine/Tests/ORM/Mapping/AbstractMappingDriverTest.php index 653cff7d7..ad1fa3d5c 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/AbstractMappingDriverTest.php +++ b/tests/Doctrine/Tests/ORM/Mapping/AbstractMappingDriverTest.php @@ -458,4 +458,49 @@ class User 'initialValue' => 1, )); } -} \ No newline at end of file +} + +abstract class AbstractContentItem +{ + + /** + * Doctrine2 entity id + * @var integer + */ + private $id; + /** + * The parent directory + * @var Directory + */ + protected $parentDirectory; + /** + * Filename (without extension) or directory name + * @var string + */ + protected $name; +} + +class Directory extends AbstractContentItem +{ + + protected $subDirectories; + /** + * This is a collection of files that are contained in this Directory. Files, for example, could be Pages, but even other files + * like media files (css, images etc) are possible. + * + * @var \Doctrine\Common\Collections\Collection + * @access protected + */ + protected $containedFiles; + /** + * @var string + */ + protected $url; +} + +class Page extends AbstractContentItem +{ + + protected $extension = "html"; + +} diff --git a/tests/Doctrine/Tests/ORM/Mapping/AnnotationDriverTest.php b/tests/Doctrine/Tests/ORM/Mapping/AnnotationDriverTest.php index 468ef680d..f28f7a6d4 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/AnnotationDriverTest.php +++ b/tests/Doctrine/Tests/ORM/Mapping/AnnotationDriverTest.php @@ -109,6 +109,34 @@ class AnnotationDriverTest extends AbstractMappingDriverTest { new $entityClassName; } + + /** + * @group DDC-671 + * + * Entities for this test are in AbstractMappingDriverTest + */ + public function testJoinTablesWithMappedSuperclassForAnnotationDriver() + { + $em = $this->_getTestEntityManager(); + $em->getConfiguration()->setMetadataDriverImpl($this->_loadDriver()); + + $classPage = $em->getClassMetadata('Doctrine\Tests\ORM\Mapping\Page'); + $this->assertEquals('Doctrine\Tests\ORM\Mapping\Page', $classPage->associationMappings['parentDirectory']['sourceEntity']); + $classDirectory = $em->getClassMetadata('Doctrine\Tests\ORM\Mapping\Directory'); + $this->assertEquals('Doctrine\Tests\ORM\Mapping\Directory', $classDirectory->associationMappings['parentDirectory']['sourceEntity']); + + $dql = "SELECT f FROM Doctrine\Tests\ORM\Mapping\Page f JOIN f.parentDirectory d " . + "WHERE (d.url = :url) AND (f.extension = :extension)"; + + $query = $em->createQuery($dql) + ->setParameter('url', "test") + ->setParameter('extension', "extension"); + + $this->assertEquals( + 'SELECT c0_.id AS id0, c0_.extension AS extension1, c0_.parent_directory_id AS parent_directory_id2 FROM core_content_pages c0_ INNER JOIN core_content_directories c1_ ON c0_.parent_directory_id = c1_.id WHERE (c1_.url = ?) AND (c0_.extension = ?)', + $query->getSql() + ); + } } /** diff --git a/tests/Doctrine/Tests/ORM/Mapping/YamlMappingDriverTest.php b/tests/Doctrine/Tests/ORM/Mapping/YamlMappingDriverTest.php index aa7ce716b..46e3ff15b 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/YamlMappingDriverTest.php +++ b/tests/Doctrine/Tests/ORM/Mapping/YamlMappingDriverTest.php @@ -19,13 +19,20 @@ class YamlMappingDriverTest extends AbstractMappingDriverTest return new YamlDriver(__DIR__ . DIRECTORY_SEPARATOR . 'yaml'); } + /** + * @group DDC-671 + * + * Entities for this test are in AbstractMappingDriverTest + */ public function testJoinTablesWithMappedSuperclassForYamlDriver() { $em = $this->_getTestEntityManager(); - $em->getConfiguration()->setMetadataDriverImpl(new \Doctrine\ORM\Mapping\Driver\YamlDriver(__DIR__ . '/yaml/')); + $em->getConfiguration()->setMetadataDriverImpl($this->_loadDriver()); - var_dump($em->getClassMetadata('Doctrine\Tests\ORM\Mapping\Page')); - var_dump($em->getClassMetadata('Doctrine\Tests\ORM\Mapping\Directory')); + $classPage = $em->getClassMetadata('Doctrine\Tests\ORM\Mapping\Page'); + $this->assertEquals('Doctrine\Tests\ORM\Mapping\Page', $classPage->associationMappings['parentDirectory']['sourceEntity']); + $classDirectory = $em->getClassMetadata('Doctrine\Tests\ORM\Mapping\Directory'); + $this->assertEquals('Doctrine\Tests\ORM\Mapping\Directory', $classDirectory->associationMappings['parentDirectory']['sourceEntity']); $dql = "SELECT f FROM Doctrine\Tests\ORM\Mapping\Page f JOIN f.parentDirectory d " . "WHERE (d.url = :url) AND (f.extension = :extension)"; @@ -34,55 +41,10 @@ class YamlMappingDriverTest extends AbstractMappingDriverTest ->setParameter('url', "test") ->setParameter('extension', "extension"); - var_dump($query->getSql()); - - // Is there a way to generalize this more? (Instead of a2_., check if the table prefix in the ON clause is set within a FROM or JOIN clause..) - $this->assertTrue(strpos($query->getSql(), 'a2_.') === false); + $this->assertEquals( + 'SELECT c0_.id AS id0, c0_.extension AS extension1, c0_.parent_directory_id AS parent_directory_id2 FROM core_content_pages c0_ INNER JOIN core_content_directories c1_ ON c0_.parent_directory_id = c1_.id WHERE (c1_.url = ?) AND (c0_.extension = ?)', + $query->getSql() + ); } } - -class Directory extends AbstractContentItem -{ - - protected $subDirectories; - /** - * This is a collection of files that are contained in this Directory. Files, for example, could be Pages, but even other files - * like media files (css, images etc) are possible. - * - * @var \Doctrine\Common\Collections\Collection - * @access protected - */ - protected $containedFiles; - /** - * @var string - */ - protected $url; -} - -class Page extends AbstractContentItem -{ - - protected $extension = "html"; - -} - -abstract class AbstractContentItem -{ - - /** - * Doctrine2 entity id - * @var integer - */ - private $id; - /** - * The parent directory - * @var Directory - */ - protected $parentDirectory; - /** - * Filename (without extension) or directory name - * @var string - */ - protected $name; -} From 39f732ab9101ca58f3a8a21a2768680f449f080e Mon Sep 17 00:00:00 2001 From: Benjamin Eberlei Date: Tue, 21 Sep 2010 23:53:26 +0200 Subject: [PATCH 5/6] Refactored DDC-671 model to become a first-class modelset, we dont have one with mapped superclass yet. --- .../DirectoryTree/AbstractContentItem.php | 49 +++++++++++++++++++ .../Tests/Models/DirectoryTree/Directory.php | 39 +++++++++++++++ .../Tests/Models/DirectoryTree/File.php | 30 ++++++++++++ .../ORM/Mapping/AbstractMappingDriverTest.php | 45 ----------------- .../ORM/Mapping/AnnotationDriverTest.php | 27 +++++----- .../ORM/Mapping/YamlMappingDriverTest.php | 27 +++++----- ....DirectoryTree.AbstractContentItem.dcm.yml | 14 ++++++ ...ts.Models.DirectoryTree.Directory.dcm.yml} | 9 ++-- ...e.Tests.Models.DirectoryTree.File.dcm.yml} | 3 +- ...ts.ORM.Mapping.AbstractContentItem.dcm.yml | 16 ------ 10 files changed, 159 insertions(+), 100 deletions(-) create mode 100644 tests/Doctrine/Tests/Models/DirectoryTree/AbstractContentItem.php create mode 100644 tests/Doctrine/Tests/Models/DirectoryTree/Directory.php create mode 100644 tests/Doctrine/Tests/Models/DirectoryTree/File.php create mode 100644 tests/Doctrine/Tests/ORM/Mapping/yaml/Doctrine.Tests.Models.DirectoryTree.AbstractContentItem.dcm.yml rename tests/Doctrine/Tests/ORM/Mapping/yaml/{Doctrine.Tests.ORM.Mapping.Directory.dcm.yml => Doctrine.Tests.Models.DirectoryTree.Directory.dcm.yml} (55%) rename tests/Doctrine/Tests/ORM/Mapping/yaml/{Doctrine.Tests.ORM.Mapping.Page.dcm.yml => Doctrine.Tests.Models.DirectoryTree.File.dcm.yml} (55%) delete mode 100644 tests/Doctrine/Tests/ORM/Mapping/yaml/Doctrine.Tests.ORM.Mapping.AbstractContentItem.dcm.yml diff --git a/tests/Doctrine/Tests/Models/DirectoryTree/AbstractContentItem.php b/tests/Doctrine/Tests/Models/DirectoryTree/AbstractContentItem.php new file mode 100644 index 000000000..16a212c61 --- /dev/null +++ b/tests/Doctrine/Tests/Models/DirectoryTree/AbstractContentItem.php @@ -0,0 +1,49 @@ +. + */ + +namespace Doctrine\Tests\Models\DirectoryTree; + +/** + * @MappedSuperclass + */ +abstract class AbstractContentItem +{ + /** + * @Id @Column(type="integer") @GeneratedValue + */ + private $id; + + /** + * @ManyToOne(targetEntity="Directory") + */ + protected $parentDirectory; + + /** @column(type="string") */ + protected $name; + + public function __get($name) + { + return $this->$name; + } + + public function __set($name, $value) + { + $this->$name = $value; + } +} diff --git a/tests/Doctrine/Tests/Models/DirectoryTree/Directory.php b/tests/Doctrine/Tests/Models/DirectoryTree/Directory.php new file mode 100644 index 000000000..d337389ef --- /dev/null +++ b/tests/Doctrine/Tests/Models/DirectoryTree/Directory.php @@ -0,0 +1,39 @@ +. + */ + +namespace Doctrine\Tests\Models\DirectoryTree; + +/** + * @Entity + */ +class Directory extends AbstractContentItem +{ + /** + * @OneToMany(targetEntity="Directory", mappedBy="parent") + */ + protected $subDirectories; + /** + * @OneToMany(targetEntity="File", mappedBy="parent") + */ + protected $containedFiles; + /** + * @Column(type="string") + */ + protected $path; +} diff --git a/tests/Doctrine/Tests/Models/DirectoryTree/File.php b/tests/Doctrine/Tests/Models/DirectoryTree/File.php new file mode 100644 index 000000000..bae6323e3 --- /dev/null +++ b/tests/Doctrine/Tests/Models/DirectoryTree/File.php @@ -0,0 +1,30 @@ +. + */ + + +namespace Doctrine\Tests\Models\DirectoryTree; + +/** + * @Entity + */ +class File extends AbstractContentItem +{ + /** @Column(type="string") */ + protected $extension = "html"; +} \ No newline at end of file diff --git a/tests/Doctrine/Tests/ORM/Mapping/AbstractMappingDriverTest.php b/tests/Doctrine/Tests/ORM/Mapping/AbstractMappingDriverTest.php index ad1fa3d5c..12ccfb32f 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/AbstractMappingDriverTest.php +++ b/tests/Doctrine/Tests/ORM/Mapping/AbstractMappingDriverTest.php @@ -459,48 +459,3 @@ class User )); } } - -abstract class AbstractContentItem -{ - - /** - * Doctrine2 entity id - * @var integer - */ - private $id; - /** - * The parent directory - * @var Directory - */ - protected $parentDirectory; - /** - * Filename (without extension) or directory name - * @var string - */ - protected $name; -} - -class Directory extends AbstractContentItem -{ - - protected $subDirectories; - /** - * This is a collection of files that are contained in this Directory. Files, for example, could be Pages, but even other files - * like media files (css, images etc) are possible. - * - * @var \Doctrine\Common\Collections\Collection - * @access protected - */ - protected $containedFiles; - /** - * @var string - */ - protected $url; -} - -class Page extends AbstractContentItem -{ - - protected $extension = "html"; - -} diff --git a/tests/Doctrine/Tests/ORM/Mapping/AnnotationDriverTest.php b/tests/Doctrine/Tests/ORM/Mapping/AnnotationDriverTest.php index f28f7a6d4..b34d727a7 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/AnnotationDriverTest.php +++ b/tests/Doctrine/Tests/ORM/Mapping/AnnotationDriverTest.php @@ -117,25 +117,20 @@ class AnnotationDriverTest extends AbstractMappingDriverTest */ public function testJoinTablesWithMappedSuperclassForAnnotationDriver() { + $annotationDriver = $this->_loadDriver(); + $annotationDriver->addPaths(array(__DIR__ . '/../../Models/DirectoryTree/')); + $em = $this->_getTestEntityManager(); - $em->getConfiguration()->setMetadataDriverImpl($this->_loadDriver()); + $em->getConfiguration()->setMetadataDriverImpl($annotationDriver); + $factory = new \Doctrine\ORM\Mapping\ClassMetadataFactory($em); - $classPage = $em->getClassMetadata('Doctrine\Tests\ORM\Mapping\Page'); - $this->assertEquals('Doctrine\Tests\ORM\Mapping\Page', $classPage->associationMappings['parentDirectory']['sourceEntity']); - $classDirectory = $em->getClassMetadata('Doctrine\Tests\ORM\Mapping\Directory'); - $this->assertEquals('Doctrine\Tests\ORM\Mapping\Directory', $classDirectory->associationMappings['parentDirectory']['sourceEntity']); + $classPage = new ClassMetadata('Doctrine\Tests\Models\DirectoryTree\File'); + $classPage = $factory->getMetadataFor('Doctrine\Tests\Models\DirectoryTree\File'); + $this->assertEquals('Doctrine\Tests\Models\DirectoryTree\File', $classPage->associationMappings['parentDirectory']['sourceEntity']); - $dql = "SELECT f FROM Doctrine\Tests\ORM\Mapping\Page f JOIN f.parentDirectory d " . - "WHERE (d.url = :url) AND (f.extension = :extension)"; - - $query = $em->createQuery($dql) - ->setParameter('url', "test") - ->setParameter('extension', "extension"); - - $this->assertEquals( - 'SELECT c0_.id AS id0, c0_.extension AS extension1, c0_.parent_directory_id AS parent_directory_id2 FROM core_content_pages c0_ INNER JOIN core_content_directories c1_ ON c0_.parent_directory_id = c1_.id WHERE (c1_.url = ?) AND (c0_.extension = ?)', - $query->getSql() - ); + $classDirectory = new ClassMetadata('Doctrine\Tests\Models\DirectoryTree\Directory'); + $classDirectory = $factory->getMetadataFor('Doctrine\Tests\Models\DirectoryTree\Directory'); + $this->assertEquals('Doctrine\Tests\Models\DirectoryTree\Directory', $classDirectory->associationMappings['parentDirectory']['sourceEntity']); } } diff --git a/tests/Doctrine/Tests/ORM/Mapping/YamlMappingDriverTest.php b/tests/Doctrine/Tests/ORM/Mapping/YamlMappingDriverTest.php index 46e3ff15b..4e58485f1 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/YamlMappingDriverTest.php +++ b/tests/Doctrine/Tests/ORM/Mapping/YamlMappingDriverTest.php @@ -26,25 +26,20 @@ class YamlMappingDriverTest extends AbstractMappingDriverTest */ public function testJoinTablesWithMappedSuperclassForYamlDriver() { + $yamlDriver = $this->_loadDriver(); + $yamlDriver->addPaths(array(__DIR__ . DIRECTORY_SEPARATOR . 'yaml')); + $em = $this->_getTestEntityManager(); - $em->getConfiguration()->setMetadataDriverImpl($this->_loadDriver()); + $em->getConfiguration()->setMetadataDriverImpl($yamlDriver); + $factory = new \Doctrine\ORM\Mapping\ClassMetadataFactory($em); - $classPage = $em->getClassMetadata('Doctrine\Tests\ORM\Mapping\Page'); - $this->assertEquals('Doctrine\Tests\ORM\Mapping\Page', $classPage->associationMappings['parentDirectory']['sourceEntity']); - $classDirectory = $em->getClassMetadata('Doctrine\Tests\ORM\Mapping\Directory'); - $this->assertEquals('Doctrine\Tests\ORM\Mapping\Directory', $classDirectory->associationMappings['parentDirectory']['sourceEntity']); + $classPage = new ClassMetadata('Doctrine\Tests\Models\DirectoryTree\File'); + $classPage = $factory->getMetadataFor('Doctrine\Tests\Models\DirectoryTree\File'); + $this->assertEquals('Doctrine\Tests\Models\DirectoryTree\File', $classPage->associationMappings['parentDirectory']['sourceEntity']); - $dql = "SELECT f FROM Doctrine\Tests\ORM\Mapping\Page f JOIN f.parentDirectory d " . - "WHERE (d.url = :url) AND (f.extension = :extension)"; - - $query = $em->createQuery($dql) - ->setParameter('url', "test") - ->setParameter('extension', "extension"); - - $this->assertEquals( - 'SELECT c0_.id AS id0, c0_.extension AS extension1, c0_.parent_directory_id AS parent_directory_id2 FROM core_content_pages c0_ INNER JOIN core_content_directories c1_ ON c0_.parent_directory_id = c1_.id WHERE (c1_.url = ?) AND (c0_.extension = ?)', - $query->getSql() - ); + $classDirectory = new ClassMetadata('Doctrine\Tests\Models\DirectoryTree\Directory'); + $classDirectory = $factory->getMetadataFor('Doctrine\Tests\Models\DirectoryTree\Directory'); + $this->assertEquals('Doctrine\Tests\Models\DirectoryTree\Directory', $classDirectory->associationMappings['parentDirectory']['sourceEntity']); } } diff --git a/tests/Doctrine/Tests/ORM/Mapping/yaml/Doctrine.Tests.Models.DirectoryTree.AbstractContentItem.dcm.yml b/tests/Doctrine/Tests/ORM/Mapping/yaml/Doctrine.Tests.Models.DirectoryTree.AbstractContentItem.dcm.yml new file mode 100644 index 000000000..9c573a561 --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Mapping/yaml/Doctrine.Tests.Models.DirectoryTree.AbstractContentItem.dcm.yml @@ -0,0 +1,14 @@ +Doctrine\Tests\Models\DirectoryTree\AbstractContentItem: + type: mappedSuperclass + id: + id: + type: integer + unsigned: true + generator: + strategy: AUTO + fields: + name: + type: string + manyToOne: + parentDirectory: + targetEntity: Doctrine\Tests\Models\DirectoryTree\Directory diff --git a/tests/Doctrine/Tests/ORM/Mapping/yaml/Doctrine.Tests.ORM.Mapping.Directory.dcm.yml b/tests/Doctrine/Tests/ORM/Mapping/yaml/Doctrine.Tests.Models.DirectoryTree.Directory.dcm.yml similarity index 55% rename from tests/Doctrine/Tests/ORM/Mapping/yaml/Doctrine.Tests.ORM.Mapping.Directory.dcm.yml rename to tests/Doctrine/Tests/ORM/Mapping/yaml/Doctrine.Tests.Models.DirectoryTree.Directory.dcm.yml index 129ae6b28..c8393ee0f 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/yaml/Doctrine.Tests.ORM.Mapping.Directory.dcm.yml +++ b/tests/Doctrine/Tests/ORM/Mapping/yaml/Doctrine.Tests.Models.DirectoryTree.Directory.dcm.yml @@ -1,17 +1,16 @@ -Doctrine\Tests\ORM\Mapping\Directory: +Doctrine\Tests\Models\DirectoryTree\Directory: type: entity - table: core_content_directories fields: - url: + path: type: string length: 255 oneToMany: subDirectories: - targetEntity: Doctrine\Tests\ORM\Mapping\Directory + targetEntity: Doctrine\Tests\Models\DirectoryTree\Directory mappedBy: parentDirectory cascade: [ all ] containedFiles: - targetEntity: Doctrine\Tests\ORM\Mapping\Page + targetEntity: Doctrine\Tests\Models\DirectoryTree\File mappedBy: parentDirectory cascade: [ remove ] diff --git a/tests/Doctrine/Tests/ORM/Mapping/yaml/Doctrine.Tests.ORM.Mapping.Page.dcm.yml b/tests/Doctrine/Tests/ORM/Mapping/yaml/Doctrine.Tests.Models.DirectoryTree.File.dcm.yml similarity index 55% rename from tests/Doctrine/Tests/ORM/Mapping/yaml/Doctrine.Tests.ORM.Mapping.Page.dcm.yml rename to tests/Doctrine/Tests/ORM/Mapping/yaml/Doctrine.Tests.Models.DirectoryTree.File.dcm.yml index a3b0fb836..cbc8edfec 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/yaml/Doctrine.Tests.ORM.Mapping.Page.dcm.yml +++ b/tests/Doctrine/Tests/ORM/Mapping/yaml/Doctrine.Tests.Models.DirectoryTree.File.dcm.yml @@ -1,6 +1,5 @@ -Doctrine\Tests\ORM\Mapping\Page: +Doctrine\Tests\Models\DirectoryTree\File: type: entity - table: core_content_pages fields: extension: type: string diff --git a/tests/Doctrine/Tests/ORM/Mapping/yaml/Doctrine.Tests.ORM.Mapping.AbstractContentItem.dcm.yml b/tests/Doctrine/Tests/ORM/Mapping/yaml/Doctrine.Tests.ORM.Mapping.AbstractContentItem.dcm.yml deleted file mode 100644 index 9137619ec..000000000 --- a/tests/Doctrine/Tests/ORM/Mapping/yaml/Doctrine.Tests.ORM.Mapping.AbstractContentItem.dcm.yml +++ /dev/null @@ -1,16 +0,0 @@ -Doctrine\Tests\ORM\Mapping\AbstractContentItem: - type: mappedSuperclass - id: - id: - type: integer - unsigned: true - generator: - strategy: AUTO - fields: - # FilesystemIdentifier - manyToOne: - parentDirectory: - targetEntity: Doctrine\Tests\ORM\Mapping\Directory - joinColumn: - name: parent_directory_id - referencedColumnName: id From 13047aa12e248a7252ba24de6caeae8835030f2b Mon Sep 17 00:00:00 2001 From: Benjamin Eberlei Date: Wed, 22 Sep 2010 00:15:45 +0200 Subject: [PATCH 6/6] Fixed Mappedsuperclass Functional Test to work with new modelset and verify that relevant features work --- .../DirectoryTree/AbstractContentItem.php | 23 +++- .../Tests/Models/DirectoryTree/Directory.php | 18 +-- .../Tests/Models/DirectoryTree/File.php | 15 +++ .../ORM/Functional/MappedSuperclassTest.php | 111 ++++-------------- ...sts.Models.DirectoryTree.Directory.dcm.yml | 10 -- .../Doctrine/Tests/OrmFunctionalTestCase.php | 9 ++ 6 files changed, 76 insertions(+), 110 deletions(-) diff --git a/tests/Doctrine/Tests/Models/DirectoryTree/AbstractContentItem.php b/tests/Doctrine/Tests/Models/DirectoryTree/AbstractContentItem.php index 16a212c61..200a88ab1 100644 --- a/tests/Doctrine/Tests/Models/DirectoryTree/AbstractContentItem.php +++ b/tests/Doctrine/Tests/Models/DirectoryTree/AbstractContentItem.php @@ -37,13 +37,28 @@ abstract class AbstractContentItem /** @column(type="string") */ protected $name; - public function __get($name) + public function __construct(Directory $parentDir = null) { - return $this->$name; + $this->parentDirectory = $parentDir; } - public function __set($name, $value) + public function getId() { - $this->$name = $value; + return $this->id; + } + + public function setName($name) + { + $this->name = $name; + } + + public function getName() + { + return $this->name; + } + + public function getParent() + { + return $this->parentDirectory; } } diff --git a/tests/Doctrine/Tests/Models/DirectoryTree/Directory.php b/tests/Doctrine/Tests/Models/DirectoryTree/Directory.php index d337389ef..f0db778b8 100644 --- a/tests/Doctrine/Tests/Models/DirectoryTree/Directory.php +++ b/tests/Doctrine/Tests/Models/DirectoryTree/Directory.php @@ -24,16 +24,18 @@ namespace Doctrine\Tests\Models\DirectoryTree; */ class Directory extends AbstractContentItem { - /** - * @OneToMany(targetEntity="Directory", mappedBy="parent") - */ - protected $subDirectories; - /** - * @OneToMany(targetEntity="File", mappedBy="parent") - */ - protected $containedFiles; /** * @Column(type="string") */ protected $path; + + public function setPath($path) + { + $this->path = $path; + } + + public function getPath() + { + return $this->path; + } } diff --git a/tests/Doctrine/Tests/Models/DirectoryTree/File.php b/tests/Doctrine/Tests/Models/DirectoryTree/File.php index bae6323e3..353177c81 100644 --- a/tests/Doctrine/Tests/Models/DirectoryTree/File.php +++ b/tests/Doctrine/Tests/Models/DirectoryTree/File.php @@ -27,4 +27,19 @@ class File extends AbstractContentItem { /** @Column(type="string") */ protected $extension = "html"; + + public function __construct(Directory $parent = null) + { + parent::__construct($parent); + } + + public function getExtension() + { + return $this->extension; + } + + public function setExtension($ext) + { + $this->extension = $ext; + } } \ No newline at end of file diff --git a/tests/Doctrine/Tests/ORM/Functional/MappedSuperclassTest.php b/tests/Doctrine/Tests/ORM/Functional/MappedSuperclassTest.php index 90ab33fa3..9b1f8d607 100644 --- a/tests/Doctrine/Tests/ORM/Functional/MappedSuperclassTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/MappedSuperclassTest.php @@ -12,100 +12,35 @@ require_once __DIR__ . '/../../TestInit.php'; class MappedSuperclassTest extends \Doctrine\Tests\OrmFunctionalTestCase { protected function setUp() { + $this->useModelSet('directorytree'); parent::setUp(); - try { - $this->_schemaTool->createSchema(array( - $this->_em->getClassMetadata('Doctrine\Tests\ORM\Functional\EntitySubClass'), - )); - } catch (\Exception $e) { - // Swallow all exceptions. We do not test the schema tool here. - } } public function testCRUD() { - $e = new EntitySubClass; - $e->setId(1); - $e->setName('Roman'); - $e->setMapped1(42); - $e->setMapped2('bar'); - - $this->_em->persist($e); + $root = new \Doctrine\Tests\Models\DirectoryTree\Directory(); + $root->setName('Root'); + $root->setPath('/root'); + + $directory = new \Doctrine\Tests\Models\DirectoryTree\Directory($root); + $directory->setName('TestA'); + $directory->setPath('/root/dir'); + + $file = new \Doctrine\Tests\Models\DirectoryTree\File($directory); + $file->setName('test-b.html'); + + $this->_em->persist($root); + $this->_em->persist($directory); + $this->_em->persist($file); + $this->_em->flush(); $this->_em->clear(); - - $e2 = $this->_em->find('Doctrine\Tests\ORM\Functional\EntitySubClass', 1); - $this->assertEquals(1, $e2->getId()); - $this->assertEquals('Roman', $e2->getName()); - $this->assertNull($e2->getMappedRelated1()); - $this->assertEquals(42, $e2->getMapped1()); - $this->assertEquals('bar', $e2->getMapped2()); + + $cleanFile = $this->_em->find(get_class($file), $file->getId()); + + $this->assertType('Doctrine\Tests\Models\DirectoryTree\Directory', $cleanFile->getParent()); + $this->assertEquals($directory->getId(), $cleanFile->getParent()->getId()); + $this->assertType('Doctrine\Tests\Models\DirectoryTree\Directory', $cleanFile->getParent()->getParent()); + $this->assertEquals($root->getId(), $cleanFile->getParent()->getParent()->getId()); } } - -/** @MappedSuperclass */ -class MappedSuperclassBase { - /** @Column(type="integer") */ - private $mapped1; - /** @Column(type="string") */ - private $mapped2; - /** - * @OneToOne(targetEntity="MappedSuperclassRelated1") - * @JoinColumn(name="related1_id", referencedColumnName="id") - */ - private $mappedRelated1; - private $transient; - - public function setMapped1($val) { - $this->mapped1 = $val; - } - - public function getMapped1() { - return $this->mapped1; - } - - public function setMapped2($val) { - $this->mapped2 = $val; - } - - public function getMapped2() { - return $this->mapped2; - } - - public function getMappedRelated1() { - return $this->mappedRelated1; - } -} - -/** @Entity */ -class MappedSuperclassRelated1 { - /** @Id @Column(type="integer") */ - private $id; - /** @Column(type="string") */ - private $name; -} - -/** @Entity */ -class EntitySubClass extends MappedSuperclassBase { - /** @Id @Column(type="integer") */ - private $id; - /** @Column(type="string") */ - private $name; - - public function setName($name) { - $this->name = $name; - } - - public function getName() { - return $this->name; - } - - public function setId($id) { - $this->id = $id; - } - - public function getId() { - return $this->id; - } -} - diff --git a/tests/Doctrine/Tests/ORM/Mapping/yaml/Doctrine.Tests.Models.DirectoryTree.Directory.dcm.yml b/tests/Doctrine/Tests/ORM/Mapping/yaml/Doctrine.Tests.Models.DirectoryTree.Directory.dcm.yml index c8393ee0f..d2b93d490 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/yaml/Doctrine.Tests.Models.DirectoryTree.Directory.dcm.yml +++ b/tests/Doctrine/Tests/ORM/Mapping/yaml/Doctrine.Tests.Models.DirectoryTree.Directory.dcm.yml @@ -4,13 +4,3 @@ Doctrine\Tests\Models\DirectoryTree\Directory: path: type: string length: 255 - oneToMany: - subDirectories: - targetEntity: Doctrine\Tests\Models\DirectoryTree\Directory - mappedBy: parentDirectory - cascade: - [ all ] - containedFiles: - targetEntity: Doctrine\Tests\Models\DirectoryTree\File - mappedBy: parentDirectory - cascade: [ remove ] diff --git a/tests/Doctrine/Tests/OrmFunctionalTestCase.php b/tests/Doctrine/Tests/OrmFunctionalTestCase.php index 2f305f9a8..5bb8cbf58 100644 --- a/tests/Doctrine/Tests/OrmFunctionalTestCase.php +++ b/tests/Doctrine/Tests/OrmFunctionalTestCase.php @@ -86,6 +86,11 @@ abstract class OrmFunctionalTestCase extends OrmTestCase 'Doctrine\Tests\Models\Navigation\NavTour', 'Doctrine\Tests\Models\Navigation\NavPointOfInterest', ), + 'directorytree' => array( + 'Doctrine\Tests\Models\DirectoryTree\AbstractContentItem', + 'Doctrine\Tests\Models\DirectoryTree\File', + 'Doctrine\Tests\Models\DirectoryTree\Directory', + ), ); protected function useModelSet($setName) @@ -162,6 +167,10 @@ abstract class OrmFunctionalTestCase extends OrmTestCase $conn->executeUpdate('DELETE FROM navigation_tours'); $conn->executeUpdate('DELETE FROM navigation_countries'); } + if (isset($this->_usedModelSets['directorytree'])) { + $conn->executeUpdate('DELETE FROM File'); + $conn->executeUpdate('DELETE FROM Directory'); + } $this->_em->clear(); }