Skip to content

Commit

Permalink
Merge pull request #117 from moufmouf/getBeanClassName
Browse files Browse the repository at this point in the history
Adding a TDBMService::getBeanClassName method
  • Loading branch information
moufmouf committed Oct 6, 2016
2 parents 45e35c1 + bd33afd commit 5a65935
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/Mouf/Database/TDBM/TDBMService.php
Original file line number Diff line number Diff line change
Expand Up @@ -649,6 +649,22 @@ public function setTableToBeanMap(array $tableToBeanMap)
$this->tableToBeanMap = $tableToBeanMap;
}

/**
* Returns the fully qualified class name of the bean associated with table $tableName.
*
*
* @param string $tableName
* @return string
*/
public function getBeanClassName(string $tableName) : string
{
if (isset($this->tableToBeanMap[$tableName])) {
return $this->tableToBeanMap[$tableName];
} else {
throw new TDBMInvalidArgumentException(sprintf('Could not find a map between table "%s" and any bean. Does table "%s" exists?', $tableName, $tableName));
}
}

/**
* Saves $object by INSERTing or UPDAT(E)ing it in the database.
*
Expand Down
17 changes: 17 additions & 0 deletions tests/Mouf/Database/TDBM/TDBMDaoGeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,23 @@ private function recursiveDelete($str)
}
}

/**
* @depends testDaoGeneration
*/
public function testGetBeanClassName()
{
$this->assertEquals(UserBean::class, $this->tdbmService->getBeanClassName('users'));
}

/**
* @depends testDaoGeneration
*/
public function testGetBeanClassNameException()
{
$this->expectException(TDBMInvalidArgumentException::class);
$this->tdbmService->getBeanClassName('not_exists');
}

/**
* @depends testDaoGeneration
*/
Expand Down

0 comments on commit 5a65935

Please sign in to comment.