From 6696c0d267c8e05e3c497588041b5169d057b401 Mon Sep 17 00:00:00 2001 From: Mike Cao Date: Wed, 18 Dec 2013 23:59:20 -0800 Subject: [PATCH] Dispatcher should check for valid callback. --- flight/core/Dispatcher.php | 4 +++- tests/DispatcherTest.php | 7 +++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/flight/core/Dispatcher.php b/flight/core/Dispatcher.php index 10aa004..c5aab29 100644 --- a/flight/core/Dispatcher.php +++ b/flight/core/Dispatcher.php @@ -141,7 +141,9 @@ class Dispatcher { self::invokeMethod($callback, $params) : self::callFunction($callback, $params); } - return null; + else { + throw new \Exception('Invalid callback specified.'); + } } /** diff --git a/tests/DispatcherTest.php b/tests/DispatcherTest.php index 3222a96..56e9acf 100644 --- a/tests/DispatcherTest.php +++ b/tests/DispatcherTest.php @@ -82,4 +82,11 @@ class DispatcherTest extends PHPUnit_Framework_TestCase $this->assertEquals('Hello, Fred! Have a nice day!', $result); } + + // Test an invalid callback + function testInvalidCallback() { + $this->setExpectedException('Exception', 'Invalid callback specified.'); + + $this->dispatcher->execute(array('NonExistentClass', 'nonExistentMethod')); + } }