Skip to content
Permalink
Browse files

Adding method extraction and test case.

  • Loading branch information...
markstory committed May 24, 2009
1 parent dee9b63 commit f20a7e4f611cc304a9550ea6767fa7f0d47bd497
Showing with 51 additions and 6 deletions.
  1. +20 −0 cake/console/libs/tasks/test.php
  2. +31 −6 cake/tests/cases/console/libs/tasks/test.test.php
@@ -200,6 +200,26 @@ function __extras($class) {
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.
*
@@ -42,13 +42,25 @@
}
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 @@ function testFilePathGeneration () {
$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);
}
}
?>

0 comments on commit f20a7e4

Please sign in to comment.
You can’t perform that action at this time.