getMethodParameters() public static méthode

Returns the parameters of a function or method.
public static getMethodParameters ( ReflectionFunction | ReflectionMethod $method, boolean $forCall = FALSE ) : string
$method ReflectionFunction | ReflectionMethod
$forCall boolean
Résultat string
#!/usr/bin/env php
<?php 
require dirname(__DIR__) . '/PHPUnit/Autoload.php';
$buffer = '';
$class = new ReflectionClass('PHPUnit_Framework_Assert');
$methods = array();
foreach ($class->getMethods() as $method) {
    $docblock = $method->getDocComment();
    $name = $method->getName();
    if (strpos($name, 'assert') === 0 || strpos($docblock, '@return PHPUnit_Framework_Constraint') !== FALSE) {
        $methods[$name] = array('class' => 'PHPUnit_Framework_Assert', 'docblock' => $docblock, 'sigDecl' => str_replace(array('= false', '= true'), array('= FALSE', '= TRUE'), PHPUnit_Util_Class::getMethodParameters($method)), 'sigCall' => PHPUnit_Util_Class::getMethodParameters($method, TRUE));
    }
}
$class = new ReflectionClass('PHPUnit_Framework_TestCase');
foreach ($class->getMethods() as $method) {
    $docblock = $method->getDocComment();
    $name = $method->getName();
    if (strpos($docblock, '@return PHPUnit_Framework_MockObject_Matcher') !== FALSE || strpos($docblock, '@return PHPUnit_Framework_MockObject_Stub') !== FALSE) {
        $methods[$name] = array('class' => 'PHPUnit_Framework_TestCase', 'docblock' => $docblock, 'sigDecl' => str_replace(array('= false', '= true'), array('= FALSE', '= TRUE'), PHPUnit_Util_Class::getMethodParameters($method)), 'sigCall' => PHPUnit_Util_Class::getMethodParameters($method, TRUE));
    }
}
ksort($methods);
foreach ($methods as $name => $data) {
    $buffer .= sprintf("\n\n%s\nfunction %s(%s)\n{\n    return call_user_func_array(\n      '%s::%s',\n      func_get_args()\n    );\n}", str_replace('    ', '', $data['docblock']), $name, $data['sigDecl'], $data['class'], $name, $data['sigCall']);
}
$template = new Text_Template(dirname(__DIR__) . '/PHPUnit/Framework/Assert/Functions.php.in');
$template->setVar(array('functions' => $buffer));
$template->renderTo(dirname(__DIR__) . '/PHPUnit/Framework/Assert/Functions.php');
 /**
  * @param  string           $templateDir
  * @param  ReflectionMethod $method
  * @return string
  */
 protected static function generateMockedMethodDefinitionFromExisting($templateDir, ReflectionMethod $method)
 {
     if ($method->isPrivate()) {
         $modifier = 'private';
     } else {
         if ($method->isProtected()) {
             $modifier = 'protected';
         } else {
             $modifier = 'public';
         }
     }
     if ($method->isStatic()) {
         $static = TRUE;
     } else {
         $static = FALSE;
     }
     if ($method->returnsReference()) {
         $reference = '&';
     } else {
         $reference = '';
     }
     return self::generateMockedMethodDefinition($templateDir, $method->getDeclaringClass()->getName(), $method->getName(), $modifier, PHPUnit_Util_Class::getMethodParameters($method), PHPUnit_Util_Class::getMethodParameters($method, TRUE), $reference, $static);
 }
Exemple #3
0
 /**
  * Generates the definition of a method to be proxied.
  *
  * @param string $templateDir Location of the templates to be used to create the proxy.
  * @param \ReflectionMethod $method Name of the method to be reflected.
  * @return array Information about the method to be proxied.
  */
 protected static function generateProxiedMethodDefinition($templateDir, \ReflectionMethod $method)
 {
     if ($method->returnsReference()) {
         $reference = '&';
     } else {
         $reference = '';
     }
     $template = self::createTemplateObject($templateDir . 'proxied_method.tpl');
     $template->setVar(array('arguments_declaration' => \PHPUnit_Util_Class::getMethodParameters($method), 'arguments' => self::getMethodCallParameters($method), 'method_name' => $method->getName(), 'reference' => $reference));
     return $template->render();
 }
Exemple #4
0
 protected function generateConstructorCodeWithParentCall(ReflectionClass $class)
 {
     $constructor = $this->getConstructor($class);
     if ($constructor) {
         return sprintf("    public function __construct(%s) {\n" . "        \$args = func_get_args();\n" . "        \$this->invocationMocker = new PHPUnit_Framework_MockObject_InvocationMocker;\n" . "        \$class = new ReflectionClass(\$this);\n" . "        \$class->getParentClass()->getConstructor()->invokeArgs(\$this, \$args);\n" . "    }\n\n", PHPUnit_Util_Class::getMethodParameters($constructor));
     } else {
         return $this->generateConstructorCode($class);
     }
 }
#!/usr/bin/env php
<?php 
require_once 'PHPUnit/Framework/Assert.php';
require_once 'PHPUnit/Util/Class.php';
require_once 'Text/Template.php';
if ($argc == 3) {
    $methods = array();
    $class = new ReflectionClass('PHPUnit_Framework_Assert');
    foreach ($class->getMethods() as $method) {
        $name = $method->getName();
        if (strpos($name, 'assert') === 0) {
            $methods[$name] = str_replace(array('= false', '= true'), array('= FALSE', '= TRUE'), PHPUnit_Util_Class::getMethodParameters($method));
        }
    }
    ksort($methods);
    $rows = '';
    foreach ($methods as $methodName => $methodArguments) {
        $rows .= sprintf('
        <row>
          <indexterm><primary>%s()</primary></indexterm>
          <entry><literal>%s(%s)</literal></entry>
        </row>', $methodName, $methodName, $methodArguments);
    }
    $template = new Text_Template($argv[1]);
    $template->setVar(array('rows' => $rows));
    $template->renderTo($argv[2]);
}