diff --git a/cake/console/libs/tasks/test.php b/cake/console/libs/tasks/test.php index 879e80349..c45f75fde 100644 --- a/cake/console/libs/tasks/test.php +++ b/cake/console/libs/tasks/test.php @@ -200,6 +200,26 @@ class TestTask extends Shell { return $extras; } +/** + * Get methods declared in the class given. + * No parent methods will be returned + * + * @param string $className Name of class to look at. + * @return array Array of method names. + **/ + function getTestableMethods($className) { + $classMethods = get_class_methods($className); + $parentMethods = get_class_methods(get_parent_class($className)); + $thisMethods = array_diff($classMethods, $parentMethods); + $out = array(); + foreach ($thisMethods as $method) { + if (substr($method, 0, 1) != '_') { + $out[] = $method; + } + } + return $out; + } + /** * Create a test for a Model object. * diff --git a/cake/tests/cases/console/libs/tasks/test.test.php b/cake/tests/cases/console/libs/tasks/test.test.php index c8835cfcb..b131a604b 100644 --- a/cake/tests/cases/console/libs/tasks/test.test.php +++ b/cake/tests/cases/console/libs/tasks/test.test.php @@ -42,13 +42,25 @@ if (!class_exists('TestTask')) { } Mock::generatePartial( - 'ShellDispatcher', 'TestTestTaskMockShellDispatcher', - array('getInput', 'stdout', 'stderr', '_stop', '_initEnvironment') - ); + 'ShellDispatcher', 'TestTestTaskMockShellDispatcher', + array('getInput', 'stdout', 'stderr', '_stop', '_initEnvironment') +); Mock::generatePartial( - 'TestTask', 'MockTestTask', - array('in', 'out', 'createFile') - ); + 'TestTask', 'MockTestTask', + array('in', 'out', 'createFile') +); + +class TestTaskSubjectClass extends Object { + function methodOne() { + + } + function methodTwo() { + + } + function _noTest() { + + } +} /** * TestTaskTest class * @@ -96,5 +108,18 @@ class TestTaskTest extends CakeTestCase { $this->Task->expectAt(1, 'createFile', array($file, '*')); $this->Task->bake('Model', 'MyClass'); } + +/** + * Test that method introspection pulls all relevant non parent class + * methods into the test case. + * + * @return void + **/ + function testMethodIntrospection() { + $result = $this->Task->getTestableMethods('TestTaskSubjectClass'); + $expected = array('methodOne', 'methodTwo'); + $this->assertEqual($result, $expected); + + } } ?> \ No newline at end of file