Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Add removeMethod method in ClassGenerator #3965

Closed
wants to merge 2 commits into
from
Jump to file or symbol
Failed to load files and symbols.
+27 −1
Split
@@ -621,7 +621,7 @@ public function getMethods()
*/
public function getMethod($methodName)
{
- foreach ($this->getMethods() as $method) {
+ foreach ($this->methods as $method) {
if ($method->getName() == $methodName) {
return $method;
}
@@ -632,6 +632,22 @@ public function getMethod($methodName)
/**
* @param string $methodName
+ * @return ClassGenerator
+ */
+ public function removeMethod($methodName)
+ {
+ foreach ($this->methods as $key => $method) {
+ if ($method->getName() == $methodName) {
+ unset($this->methods[$key]);
+ break;
+ }
+ }
+
+ return $this;
+ }
+
+ /**
+ * @param string $methodName
* @return bool
*/
public function hasMethod($methodName)
@@ -173,6 +173,16 @@ public function testHasMethod()
$this->assertTrue($classGenerator->hasMethod('methodOne'));
}
+ public function testRemoveMethod()
+ {
+ $classGenerator = new ClassGenerator();
+ $classGenerator->addMethod('methodOne');
+ $this->assertTrue($classGenerator->hasMethod('methodOne'));
+
+ $classGenerator->removeMethod('methodOne');
+ $this->assertFalse($classGenerator->hasMethod('methodOne'));
+ }
+
/**
* @group ZF-7361
*/