/** * Method from the TableMap API */ public function getRelations() { // table maps $authorTable = new TableMap(); $authorTable->setClassName('\\Foo\\Author'); $resellerTable = new TableMap(); $resellerTable->setClassName('\\Foo\\Reseller'); // relations $mainAuthorRelation = new RelationMap('MainAuthor'); $mainAuthorRelation->setType(RelationMap::MANY_TO_ONE); $mainAuthorRelation->setForeignTable($authorTable); $authorRelation = new RelationMap('Author'); $authorRelation->setType(RelationMap::ONE_TO_MANY); $authorRelation->setForeignTable($authorTable); $resellerRelation = new RelationMap('Reseller'); $resellerRelation->setType(RelationMap::MANY_TO_MANY); $resellerRelation->setLocalTable($resellerTable); return array($mainAuthorRelation, $authorRelation, $resellerRelation); }
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'); }
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()'); }