public
Last active

  • Download Gist
DC329TestCase.php
PHP
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
<?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();
}
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.