This repository has been archived by the owner on Feb 5, 2024. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
112 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?php | ||
|
||
namespace Doctrine\Tests\Models\Mapping; | ||
|
||
/** | ||
* @Document | ||
*/ | ||
class BaseArticle | ||
{ | ||
/** @Id */ | ||
public $id; | ||
/** @Field(type="string") */ | ||
public $topic; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?php | ||
|
||
namespace Doctrine\Tests\Models\Mapping; | ||
|
||
/** | ||
* Model to test extending another model | ||
* | ||
* @Document | ||
*/ | ||
class ExtendingClass extends MappedSuperclass | ||
{ | ||
/** @Field(type="string") */ | ||
public $headline; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?php | ||
|
||
namespace Doctrine\Tests\Models\Mapping; | ||
|
||
/** | ||
* Model to test extending another model | ||
* | ||
* @Document | ||
*/ | ||
class HeadlineArticle extends BaseArticle | ||
{ | ||
/** @Field(type="string") */ | ||
public $headline; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?php | ||
|
||
namespace Doctrine\Tests\Models\Mapping; | ||
|
||
/** | ||
* @MappedSuperclass | ||
*/ | ||
class MappedSuperclass | ||
{ | ||
/** @Id */ | ||
public $id; | ||
/** @Field(type="string") */ | ||
public $topic; | ||
} |
56 changes: 56 additions & 0 deletions
56
tests/Doctrine/Tests/ODM/CouchDB/Functional/Mapping/DocumentInheritTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<?php | ||
|
||
namespace Doctrine\Tests\ODM\CouchDB\Functional\Mapping; | ||
|
||
use Doctrine\ODM\CouchDB\DocumentManager; | ||
use Doctrine\Tests\Models\Mapping\HeadlineArticle; | ||
use Doctrine\Tests\ODM\CouchDB\CouchDBFunctionalTestCase; | ||
use Doctrine\Tests\Models\Mapping\ExtendingClass; | ||
|
||
/** | ||
* Test about mapped superclass and about extending a base document | ||
*/ | ||
class DocumentInheritTest extends CouchDBFunctionalTestCase | ||
{ | ||
/** @var DocumentManager */ | ||
private $dm; | ||
|
||
public function setUp() | ||
{ | ||
$this->dm = $this->createDocumentManager(); | ||
} | ||
|
||
public function testLoadingParentClass() | ||
{ | ||
$document = new HeadlineArticle(); | ||
$document->topic = 'Superclass test'; | ||
$document->headline = 'test test test'; | ||
$this->dm->persist($document); | ||
$this->dm->flush(); | ||
$id = $document->id; | ||
|
||
$this->dm->clear(); | ||
|
||
$doc = $this->dm->find('Doctrine\Tests\Models\Mapping\HeadlineArticle', $id); | ||
$this->assertInstanceOf('\Doctrine\Tests\Models\Mapping\HeadlineArticle', $doc); | ||
$this->assertEquals('test test test', $doc->headline); | ||
$this->assertEquals('Superclass test', $doc->topic); | ||
} | ||
|
||
public function testLoadingMappedsuperclass() | ||
{ | ||
$document = new ExtendingClass(); | ||
$document->topic = 'Superclass test'; | ||
$document->headline = 'test test test'; | ||
$this->dm->persist($document); | ||
$this->dm->flush(); | ||
$id = $document->id; | ||
|
||
$this->dm->clear(); | ||
|
||
$doc = $this->dm->find('Doctrine\Tests\Models\Mapping\ExtendingClass', $id); | ||
$this->assertInstanceOf('\Doctrine\Tests\Models\Mapping\ExtendingClass', $doc); | ||
$this->assertEquals('test test test', $doc->headline); | ||
$this->assertEquals('Superclass test', $doc->topic); | ||
} | ||
} |