From 8fe4d88003c3284a3241faea2c2bc58133f09af5 Mon Sep 17 00:00:00 2001 From: michaelward82 Date: Sat, 14 Sep 2013 14:35:54 +0100 Subject: [PATCH 1/2] Adds new IdiormMethodMissingException class for missing magic method calls to ORM and IdiormResultSet --- idiorm.php | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/idiorm.php b/idiorm.php index dd5cea20..f792ae4c 100644 --- a/idiorm.php +++ b/idiorm.php @@ -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)); + } } /** @@ -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; } @@ -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 {} \ No newline at end of file From eb3ab47d6dac2d298544d28877ad811c88d18441 Mon Sep 17 00:00:00 2001 From: michaelward82 Date: Sat, 14 Sep 2013 14:38:28 +0100 Subject: [PATCH 2/2] Adds regression tests for missing magic method calls to ORM and IdiormResultSet --- test/ORMTest.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/test/ORMTest.php b/test/ORMTest.php index ebd3d17f..e0e4900d 100644 --- a/test/ORMTest.php +++ b/test/ORMTest.php @@ -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(); + } } \ No newline at end of file