Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invalid method calls to ORM cause recursion #152

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions idiorm.php
Original file line number Diff line number Diff line change
Expand Up @@ -1897,7 +1897,11 @@ public function __call($name, $arguments)
{
$method = strtolower(preg_replace('/([a-z])([A-Z])/', '$1_$2', $name));

return call_user_func_array(array($this, $method), $arguments);
if (method_exists($this, $method)) {
return call_user_func_array(array($this, $method), $arguments);
} else {
throw new IdiormMethodMissingException("Method $name() does not exist in class " . get_class($this));
}
}

/**
Expand Down Expand Up @@ -2147,7 +2151,11 @@ public function unserialize($serialized) {
*/
public function __call($method, $params = array()) {
foreach($this->_results as $model) {
call_user_func_array(array($model, $method), $params);
if (method_exists($model, $method)) {
call_user_func_array(array($model, $method), $params);
} else {
throw new IdiormMethodMissingException("Method $method() does not exist in class " . get_class($this));
}
}
return $this;
}
Expand All @@ -2157,3 +2165,5 @@ public function __call($method, $params = array()) {
* A placeholder for exceptions eminating from the IdiormString class
*/
class IdiormStringException extends Exception {}

class IdiormMethodMissingException extends Exception {}
15 changes: 15 additions & 0 deletions test/ORMTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,19 @@ public function testGetLastPdoStatement() {
$this->assertInstanceOf('MockPDOStatement', $statement);
}

/**
* @expectedException IdiormMethodMissingException
*/
public function testInvalidORMFunctionCallShouldCreateException() {
$orm = ORM::for_table('test');
$orm->invalidFunctionCall();
}

/**
* @expectedException IdiormMethodMissingException
*/
public function testInvalidResultsSetFunctionCallShouldCreateException() {
$resultSet = ORM::for_table('test')->find_result_set();
$resultSet->invalidFunctionCall();
}
}