public function testParse()
 {
     $fn = function ($param1 = true, $param2 = 'bho') {
         // function body
     };
     $reflector = new \ReflectionFunction($fn);
     $comment = $reflector->getDocComment();
     $parser = new DocBlockParser($comment);
     $this->assertEquals('Anonymous function description splitted in two lines', $parser->getDescription());
     $this->assertFalse($parser->hasParam('param4'));
     $this->assertTrue($parser->hasParam('param1'));
     $param1 = $parser->getParam('param1');
     $this->assertEquals('param1', $param1['name']);
     $this->assertEquals('bool', $param1['type']);
     $this->assertEquals('parameter1 description', $param1['description']);
     $this->assertEquals('parameter1 description', $parser->getParamDescription('param1'));
     $this->assertEquals('', $parser->getParamDescription('param4'));
     $params = $parser->getParams();
     $this->assertTrue(is_array($params));
     $this->assertEquals(3, count($params));
     $this->assertEquals('param1', $params['param1']['name']);
     $this->assertEquals('bool', $params['param1']['type']);
     $this->assertEquals('parameter1 description', $params['param1']['description']);
     $this->assertEquals('param3', $params['param3']['name']);
     $this->assertEquals('string', $params['param3']['type']);
     $this->assertEquals('', $params['param3']['description']);
 }
Beispiel #2
0
 /**
  * @param callable $code
  */
 public function buildFromCode($code)
 {
     $this->assertCallable($code);
     $this->setCode($code);
     $reflector = new \ReflectionFunction($code);
     $parser = new DocBlockParser($reflector->getDocComment());
     $this->setDescription($parser->getDescription());
     foreach ($reflector->getParameters() as $parameter) {
         $description = $parser->getParamDescription($parameter->getName());
         $this->addParameter($parameter, $description);
     }
 }