Skip to content

Commit

Permalink
Fixed Mappedsuperclass Functional Test to work with new modelset and …
Browse files Browse the repository at this point in the history
…verify that relevant features work
  • Loading branch information
beberlei committed Sep 21, 2010
1 parent 39f732a commit 13047aa
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 108 deletions.
23 changes: 19 additions & 4 deletions tests/Doctrine/Tests/Models/DirectoryTree/AbstractContentItem.php
Expand Up @@ -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;
}
}
18 changes: 10 additions & 8 deletions tests/Doctrine/Tests/Models/DirectoryTree/Directory.php
Expand Up @@ -24,16 +24,18 @@
*/
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;
}
}
15 changes: 15 additions & 0 deletions tests/Doctrine/Tests/Models/DirectoryTree/File.php
Expand Up @@ -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;
}
}
107 changes: 21 additions & 86 deletions tests/Doctrine/Tests/ORM/Functional/MappedSuperclassTest.php
Expand Up @@ -12,100 +12,35 @@
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());
}
}

/** @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;
}
$cleanFile = $this->_em->find(get_class($file), $file->getId());

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

Expand Up @@ -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 ]
9 changes: 9 additions & 0 deletions tests/Doctrine/Tests/OrmFunctionalTestCase.php
Expand Up @@ -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)
Expand Down Expand Up @@ -162,6 +167,10 @@ protected function tearDown()
$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();
}
Expand Down

0 comments on commit 13047aa

Please sign in to comment.