1
0
mirror of synced 2024-12-13 22:56:04 +03:00

Fixed Mappedsuperclass Functional Test to work with new modelset and verify that relevant features work

This commit is contained in:
Benjamin Eberlei 2010-09-22 00:15:45 +02:00
parent 39f732ab91
commit 13047aa12e
6 changed files with 76 additions and 110 deletions

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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');
$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->persist($e);
$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());
/** @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;
$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());
}
}
/** @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;
}
}

View File

@ -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 ]

View File

@ -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();
}