Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
<?php
class Doctrine_Ticket_DC329_TestCase extends Doctrine_UnitTestCase
{
public function prepareTables()
{
$this->tables[] = "Ticket_DC329_Document";
$this->tables[] = "Ticket_DC329_DocumentRelation";
parent::prepareTables();
}
public function prepareData()
{
}
public function testInit()
{
}
// This produces a failing test
public function testTest()
{
$document1 = new Ticket_DC329_Document();
$document1->save();
$document2 = new Ticket_DC329_Document();
$document2->save();
$document3 = new Ticket_DC329_Document();
$document3->save();
$document1->RelatedDocuments[] = $document2;
$document1->RelatedDocuments[] = $document3;
$document1->save();
$document1->free(true);
$document2->free(true);
$documents = Doctrine_Core::getTable('Ticket_DC329_Document')->findAll();
$this->assertEqual(3, count($documents));
$this->assertEqual(2, count($documents[0]->RelatedDocuments));
$this->assertEqual(1, count($documents[1]->RelatedDocuments));
$documents[1]->save();
}
}
class Ticket_DC329_Document extends Doctrine_Record
{
public function setTableDefinition()
{
$this->setTableName('document');
$this->hasColumn('title', 'string', 255, array(
'type' => 'string',
'length' => 255,
));
}
public function setUp()
{
parent::setUp();
$this->hasMany('Ticket_DC329_Document as RelatedDocuments', array(
'refClass' => 'Ticket_DC329_DocumentRelation',
'local' => 'document1',
'foreign' => 'document2',
'equal' => true));
}
}
class Ticket_DC329_DocumentRelation extends Doctrine_Record
{
public function setTableDefinition()
{
$this->setTableName('document_relation');
$this->hasColumn('document1', 'integer', null, array(
'type' => 'integer',
'primary' => true,
));
$this->hasColumn('document2', 'integer', null, array(
'type' => 'integer',
'primary' => true,
));
}
public function setUp()
{
parent::setUp();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.