Adding method extraction and test case.

This commit is contained in:
mark_story 2009-05-23 23:48:25 -04:00
parent dee9b6370b
commit f20a7e4f61
2 changed files with 51 additions and 6 deletions

View file

@ -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.
*

View file

@ -44,11 +44,23 @@ if (!class_exists('TestTask')) {
Mock::generatePartial(
'ShellDispatcher', 'TestTestTaskMockShellDispatcher',
array('getInput', 'stdout', 'stderr', '_stop', '_initEnvironment')
);
);
Mock::generatePartial(
'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);
}
}
?>