Skip to content
This repository has been archived by the owner on Feb 5, 2024. It is now read-only.

Commit

Permalink
adding tests for mapped superclass
Browse files Browse the repository at this point in the history
  • Loading branch information
dbu committed May 10, 2013
1 parent 7c7fa63 commit e43572f
Show file tree
Hide file tree
Showing 5 changed files with 112 additions and 0 deletions.
14 changes: 14 additions & 0 deletions tests/Doctrine/Tests/Models/Mapping/BaseArticle.php
@@ -0,0 +1,14 @@
<?php

namespace Doctrine\Tests\Models\Mapping;

/**
* @Document
*/
class BaseArticle
{
/** @Id */
public $id;
/** @Field(type="string") */
public $topic;
}
14 changes: 14 additions & 0 deletions tests/Doctrine/Tests/Models/Mapping/ExtendingClass.php
@@ -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;
}
14 changes: 14 additions & 0 deletions tests/Doctrine/Tests/Models/Mapping/HeadlineArticle.php
@@ -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;
}
14 changes: 14 additions & 0 deletions tests/Doctrine/Tests/Models/Mapping/MappedSuperclass.php
@@ -0,0 +1,14 @@
<?php

namespace Doctrine\Tests\Models\Mapping;

/**
* @MappedSuperclass
*/
class MappedSuperclass
{
/** @Id */
public $id;
/** @Field(type="string") */
public $topic;
}
@@ -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);
}
}

0 comments on commit e43572f

Please sign in to comment.