From 13047aa12e248a7252ba24de6caeae8835030f2b Mon Sep 17 00:00:00 2001 From: Benjamin Eberlei Date: Wed, 22 Sep 2010 00:15:45 +0200 Subject: [PATCH] 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(); }