Skip to content
Permalink
Browse files

Adding Shell::hasMethod and tests for it.

  • Loading branch information...
markstory committed Oct 10, 2010
1 parent 18c5a62 commit cd18c8214c64858092def81e295b028ac669d33c
Showing with 39 additions and 1 deletion.
  1. +15 −1 cake/console/libs/shell.php
  2. +24 −0 cake/tests/cases/console/libs/shell.test.php
@@ -305,7 +305,21 @@ public function hasTask($task) {
* @return boolean
*/
public function hasMethod($name) {
if (empty($this->_reflection)) {
$this->_reflection = new ReflectionClass($this);
}
try {
$method = $this->_reflection->getMethod($name);
if (!$method->isPublic() || substr($name, 0, 1) === '_') {
return false;
}
if ($method->getDeclaringClass() != $this->_reflection) {
return false;
}
return true;
} catch (ReflectionException $e) {
return false;
}
}
/**
@@ -57,6 +57,18 @@ class TestShell extends Shell {
protected function _stop($status = 0) {
$this->stopped = $status;
}
public function do_something() {
}
public function _secret() {
}
protected function no_access() {
}
}
/**
@@ -578,4 +590,16 @@ function testHasTask() {
$this->assertTrue($this->Shell->hasTask('db_config'));
$this->assertTrue($this->Shell->hasTask('DbConfig'));
}
/**
* test the hasMethod
*
* @return void
*/
function testHasMethod() {
$this->assertTrue($this->Shell->hasMethod('do_something'));
$this->assertFalse($this->Shell->hasMethod('hr'), 'hr is callable');
$this->assertFalse($this->Shell->hasMethod('_secret'), '_secret is callable');
$this->assertFalse($this->Shell->hasMethod('no_access'), 'no_access is callable');
}
}

0 comments on commit cd18c82

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