public function testMethods()
 {
     $class = new PhpClass();
     $this->assertTrue($class->getMethods()->isEmpty());
     $this->assertSame($class, $class->setMethod($method = new PhpMethod('foo')));
     $this->assertSame(['foo' => $method], $class->getMethods()->toArray());
     $this->assertTrue($class->hasMethod('foo'));
     $this->assertSame($method, $class->getMethod('foo'));
     $this->assertSame($class, $class->removeMethod($method));
     $this->assertEquals([], $class->getMethods()->toArray());
     $class->setMethod($orphaned = new PhpMethod('orphaned'));
     $this->assertSame($class, $orphaned->getParent());
     $this->assertTrue($class->hasMethod($orphaned));
     $this->assertSame($class, $class->setMethods([$method, $method2 = new PhpMethod('bar')]));
     $this->assertSame(['foo' => $method, 'bar' => $method2], $class->getMethods()->toArray());
     $this->assertEquals(['foo', 'bar'], $class->getMethodNames()->toArray());
     $this->assertNull($orphaned->getParent());
     $this->assertSame($method, $class->getMethod($method));
     $this->assertTrue($class->hasMethod($method));
     $this->assertSame($class, $class->removeMethod($method));
     $this->assertFalse($class->hasMethod($method));
     $this->assertFalse($class->getMethods()->isEmpty());
     $class->clearMethods();
     $this->assertTrue($class->getMethods()->isEmpty());
     try {
         $this->assertEmpty($class->getMethod('method-not-found'));
     } catch (\InvalidArgumentException $e) {
         $this->assertNotNull($e);
     }
 }
 public function testMethods()
 {
     $class = new PhpClass();
     $this->assertEquals(array(), $class->getMethods());
     $this->assertSame($class, $class->setMethod($method = new PhpMethod('foo')));
     $this->assertSame(array('foo' => $method), $class->getMethods());
     $this->assertTrue($class->hasMethod('foo'));
     $this->assertSame($method, $class->getMethod('foo'));
     $this->assertSame($class, $class->removeMethod($method));
     $this->assertEquals(array(), $class->getMethods());
     $class->setMethod($orphaned = new PhpMethod('orphaned'));
     $this->assertSame($class, $orphaned->getParent());
     $this->assertTrue($class->hasMethod($orphaned));
     $this->assertSame($class, $class->setMethods([$method, $method2 = new PhpMethod('bar')]));
     $this->assertSame(['foo' => $method, 'bar' => $method2], $class->getMethods());
     $this->assertNull($orphaned->getParent());
 }
 public function visitMethod(PhpMethod $method)
 {
     $this->visitDocblock($method->getDocblock());
     if ($method->isAbstract()) {
         $this->writer->write('abstract ');
     }
     $this->writer->write($method->getVisibility() . ' ');
     if ($method->isStatic()) {
         $this->writer->write('static ');
     }
     $this->writer->write('function ');
     if ($method->isReferenceReturned()) {
         $this->writer->write('& ');
     }
     $this->writer->write($method->getName() . '(');
     $this->writeParameters($method->getParameters());
     $this->writer->write(")");
     $this->writeFunctionReturnType($method->getType());
     if ($method->isAbstract() || $method->getParent() instanceof PhpInterface) {
         $this->writer->write(";\n\n");
         return;
     }
     $this->writer->writeln(' {')->indent()->writeln(trim($method->getBody()))->outdent()->rtrim()->write("}\n\n");
 }