示例#1
0
 public function testAddRelation()
 {
     $foreigntmap1 = new TableMap('bar');
     $foreigntmap1->setClassname('Bar');
     $this->databaseMap->addTableObject($foreigntmap1);
     $foreigntmap2 = new TableMap('baz');
     $foreigntmap2->setClassname('Baz');
     $this->databaseMap->addTableObject($foreigntmap2);
     $this->rmap1 = $this->tmap->addRelation('Bar', 'Bar', RelationMap::MANY_TO_ONE);
     $this->rmap2 = $this->tmap->addRelation('Bazz', 'Baz', RelationMap::ONE_TO_MANY);
     $this->tmap->getRelations();
     // now on to the test
     $this->assertEquals($this->rmap1->getLocalTable(), $this->tmap, 'adding a relation with HAS_ONE sets the local table to the current table');
     $this->assertEquals($this->rmap1->getForeignTable(), $foreigntmap1, 'adding a relation with HAS_ONE sets the foreign table according to the name given');
     $this->assertEquals(RelationMap::MANY_TO_ONE, $this->rmap1->getType(), 'adding a relation with HAS_ONE sets the foreign table type accordingly');
     $this->assertEquals($this->rmap2->getForeignTable(), $this->tmap, 'adding a relation with HAS_MANY sets the foreign table to the current table');
     $this->assertEquals($this->rmap2->getLocalTable(), $foreigntmap2, 'adding a relation with HAS_MANY sets the local table according to the name given');
     $this->assertEquals(RelationMap::ONE_TO_MANY, $this->rmap2->getType(), 'adding a relation with HAS_MANY sets the foreign table type accordingly');
     $expectedRelations = array('Bar' => $this->rmap1, 'Bazz' => $this->rmap2);
     $this->assertEquals($expectedRelations, $this->tmap->getRelations(), 'getRelations() returns an associative array of all the relations');
 }
示例#2
0
 public function testGetTableByPhpName()
 {
     try {
         $this->databaseMap->getTableByPhpName('Foo1');
         $this->fail('getTableByPhpName() throws an exception when called on an inexistent table');
     } catch (TableNotFoundException $e) {
         $this->assertTrue(true, 'getTableByPhpName() throws an exception when called on an inexistent table');
     }
     $tmap = $this->databaseMap->addTable('foo1');
     try {
         $this->databaseMap->getTableByPhpName('Foo1');
         $this->fail('getTableByPhpName() throws an exception when called on a table with no phpName');
     } catch (TableNotFoundException $e) {
         $this->assertTrue(true, 'getTableByPhpName() throws an exception when called on a table with no phpName');
     }
     $tmap2 = new TableMap('foo2');
     $tmap2->setClassname('Foo2');
     $this->databaseMap->addTableObject($tmap2);
     $this->assertEquals($tmap2, $this->databaseMap->getTableByPhpName('Foo2'), 'getTableByPhpName() returns tableMap when phpName was set by way of TableMap::setPhpName()');
 }