Added test case and models for sfDoctrine-style inheritance in record
and table classes.
This commit is contained in:
parent
9dcceb6c13
commit
2ee78d7d85
13
models/BaseSymfonyRecord.php
Normal file
13
models/BaseSymfonyRecord.php
Normal file
@ -0,0 +1,13 @@
|
||||
<?php
|
||||
abstract class BaseSymfonyRecord extends Doctrine_Record
|
||||
{
|
||||
public function setUp()
|
||||
{
|
||||
}
|
||||
|
||||
public function setTableDefinition()
|
||||
{
|
||||
$this->hasColumn('name', 'string', 30);
|
||||
}
|
||||
|
||||
}
|
15
models/PluginSymfonyRecord.php
Normal file
15
models/PluginSymfonyRecord.php
Normal file
@ -0,0 +1,15 @@
|
||||
<?php
|
||||
require_once('BaseSymfonyRecord.php');
|
||||
|
||||
abstract class PluginSymfonyRecord extends BaseSymfonyRecord
|
||||
{
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
}
|
||||
|
||||
public function setTableDefinition()
|
||||
{
|
||||
parent::setTableDefinition();
|
||||
}
|
||||
}
|
5
models/PluginSymfonyRecordTable.php
Normal file
5
models/PluginSymfonyRecordTable.php
Normal file
@ -0,0 +1,5 @@
|
||||
<?php
|
||||
class PluginSymfonyRecordTable extends Doctrine_Table
|
||||
{
|
||||
|
||||
}
|
14
models/SymfonyRecord.php
Normal file
14
models/SymfonyRecord.php
Normal file
@ -0,0 +1,14 @@
|
||||
<?php
|
||||
class SymfonyRecord extends PluginSymfonyRecord
|
||||
{
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
}
|
||||
|
||||
public function setTableDefinition()
|
||||
{
|
||||
parent::setTableDefinition();
|
||||
}
|
||||
}
|
7
models/SymfonyRecordTable.php
Normal file
7
models/SymfonyRecordTable.php
Normal file
@ -0,0 +1,7 @@
|
||||
<?php
|
||||
require_once('PluginSymfonyRecordTable.php');
|
||||
|
||||
class SymfonyRecordTable extends PluginSymfonyRecordTable
|
||||
{
|
||||
|
||||
}
|
59
tests/Record/InheritanceTestCase.php
Normal file
59
tests/Record/InheritanceTestCase.php
Normal file
@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Doctrine_Record_Inheritance_TestCase
|
||||
*
|
||||
* This test case demonstrates the use of inheritance involving subclasses of
|
||||
* Doctrine_Record. This type of inheritance is heavily used in sfDoctrine,
|
||||
* and as new inheritance-related features get added to Doctrine it seems to
|
||||
* be an area where subtle breakage can sneak in.
|
||||
*
|
||||
* @package Doctrine
|
||||
* @author David Brewer <dbrewer@secondstory.com>
|
||||
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
|
||||
* @category Object Relational Mapping
|
||||
* @link www.phpdoctrine.com
|
||||
* @since 1.0
|
||||
* @version $Revision$
|
||||
*/
|
||||
|
||||
class Doctrine_Record_Inheritance_TestCase extends Doctrine_UnitTestCase
|
||||
{
|
||||
public function prepareTables()
|
||||
{
|
||||
$this->tables = array_merge($this->tables, array('SymfonyRecord'));
|
||||
parent::prepareTables();
|
||||
}
|
||||
public function prepareData()
|
||||
{
|
||||
parent::prepareData();
|
||||
}
|
||||
|
||||
public function testInit()
|
||||
{
|
||||
$record = new SymfonyRecord();
|
||||
$record['name'] = 'Test me';
|
||||
$record->save();
|
||||
}
|
||||
|
||||
public function testInstantiatingRecordWithAbstractParents()
|
||||
{
|
||||
// load our record
|
||||
$record = Doctrine_Query::create()->query(
|
||||
'SELECT * FROM SymfonyRecord r', array())->getFirst();
|
||||
|
||||
// did we get a record object?
|
||||
$this->assertTrue($record instanceof SymfonyRecord);
|
||||
$this->assertTrue($record->exists());
|
||||
|
||||
// does it have the appropriate parentage?
|
||||
$this->assertTrue($record instanceof PluginSymfonyRecord);
|
||||
$this->assertTrue($record instanceof BaseSymfonyRecord);
|
||||
$this->assertTrue($record instanceof Doctrine_Record);
|
||||
|
||||
// does it have the expected data?
|
||||
$this->assertEqual($record['name'], 'Test me');
|
||||
|
||||
|
||||
}
|
||||
}
|
@ -210,6 +210,7 @@ $record->addTestCase(new Doctrine_Record_SerializeUnserialize_TestCase());
|
||||
$record->addTestCase(new Doctrine_Record_Lock_TestCase());
|
||||
$record->addTestCase(new Doctrine_Record_ZeroValues_TestCase());
|
||||
//$record->addTestCase(new Doctrine_Record_SaveBlankRecord_TestCase());
|
||||
$record->addTestCase(new Doctrine_Record_Inheritance_TestCase());
|
||||
$test->addTestCase($record);
|
||||
|
||||
$test->addTestCase(new Doctrine_CustomPrimaryKey_TestCase());
|
||||
|
Loading…
x
Reference in New Issue
Block a user