Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Adding method extraction and test case.

  • Loading branch information...
commit f20a7e4f611cc304a9550ea6767fa7f0d47bd497 1 parent dee9b63
@markstory markstory authored
View
20 cake/console/libs/tasks/test.php
@@ -201,6 +201,26 @@ function __extras($class) {
}
/**
+ * 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.
*
* @return void
View
37 cake/tests/cases/console/libs/tasks/test.test.php
@@ -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);
+
+ }
}
?>
Please sign in to comment.
Something went wrong with that request. Please try again.