Просмотр исходного кода

[ZF-6726]
Altered test cases to allow a new line immediately after tag name and to allow multiple whitespaces.
Altered generic Tag class and Return and Param special cases to pass new tests.



git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@18072 44c647ce-9c0f-0410-b52a-842ac1e357ba

carlton 16 лет назад
Родитель
Сommit
88c7d47171

+ 3 - 3
library/Zend/Reflection/Docblock/Tag.php

@@ -58,7 +58,7 @@ class Zend_Reflection_Docblock_Tag implements Reflector
     {
         $matches = array();
 
-        if (!preg_match('#^@(\w+)\s#', $tagDocblockLine, $matches)) {
+        if (!preg_match('#^@(\w+)(\s|$)#', $tagDocblockLine, $matches)) {
             require_once 'Zend/Reflection/Exception.php';
             throw new Zend_Reflection_Exception('No valid tag name found within provided docblock line.');
         }
@@ -109,13 +109,13 @@ class Zend_Reflection_Docblock_Tag implements Reflector
         $matches = array();
 
         // find the line
-        if (!preg_match('#^@(\w+)\s(.*)?#', $tagDocblockLine, $matches)) {
+        if (!preg_match('#^@(\w+)(?:\s+([^\s].*)|$)?#', $tagDocblockLine, $matches)) {
             require_once 'Zend/Reflection/Exception.php';
             throw new Zend_Reflection_Exception('Provided docblock line does not contain a valid tag');
         }
 
         $this->_name = $matches[1];
-        if ($matches[2]) {
+        if (isset($matches[2]) && $matches[2]) {
             $this->_description = $matches[2];
         }
     }

+ 1 - 1
library/Zend/Reflection/Docblock/Tag/Param.php

@@ -49,7 +49,7 @@ class Zend_Reflection_Docblock_Tag_Param extends Zend_Reflection_Docblock_Tag
     {
         $matches = array();
 
-        if (!preg_match('#^@(\w+)\s(\w+)(?:\s(\$\S+))?(?:\s(.*))?#s', $tagDocblockLine, $matches)) {
+        if (!preg_match('#^@(\w+)\s+(\w+)(?:\s+(\$\S+))?(?:\s+(.*))?#s', $tagDocblockLine, $matches)) {
             require_once 'Zend/Reflection/Exception.php';
             throw new Zend_Reflection_Exception('Provided docblock line is does not contain a valid tag');
         }

+ 1 - 1
library/Zend/Reflection/Docblock/Tag/Return.php

@@ -43,7 +43,7 @@ class Zend_Reflection_Docblock_Tag_Return extends Zend_Reflection_Docblock_Tag
      */
     public function __construct($tagDocblockLine)
     {
-        if (!preg_match('#^@(\w+)\s(\w+)(?:\s(.*))?#', $tagDocblockLine, $matches)) {
+        if (!preg_match('#^@(\w+)\s+(\w+)(?:\s+(.*))?#', $tagDocblockLine, $matches)) {
             require_once 'Zend/Reflection/Exception.php';
             throw new Zend_Reflection_Exception('Provided docblock line is does not contain a valid tag');
         }

+ 10 - 0
tests/Zend/Reflection/Docblock/Tag/ParamTest.php

@@ -64,5 +64,15 @@ class Zend_Reflection_Docblock_Tag_ParamTest extends PHPUnit_Framework_TestCase
         $this->assertEquals($paramTag->getVariableName(), '$one');
     }
     
+    public function testAllowsMultipleSpacesInDocblockTagLine()
+    {
+    	$classReflection = new Zend_Reflection_Class('Zend_Reflection_TestSampleClass6');
+    	
+        $paramTag = $classReflection->getMethod('doSomething')->getDocblock()->getTag('param');
+        
+        $this->assertEquals($paramTag->getType(), 'int', 'Second Match Failed');
+    	$this->assertEquals($paramTag->getVariableName(), '$var', 'Third Match Failed');
+    	$this->assertEquals($paramTag->getDescription(),'Description of $var', 'Final Match Failed');
+    }
 }
     

+ 9 - 0
tests/Zend/Reflection/Docblock/Tag/ReturnTest.php

@@ -55,5 +55,14 @@ class Zend_Reflection_Docblock_Tag_ReturnTest extends PHPUnit_Framework_TestCase
         $this->assertEquals($paramTag->getType(), 'mixed');
     }
     
+    public function testAllowsMultipleSpacesInDocblockTagLine()
+    {
+    	$classReflection = new Zend_Reflection_Class('Zend_Reflection_TestSampleClass6');
+    	
+        $paramTag = $classReflection->getMethod('doSomething')->getDocblock()->getTag('return');
+        
+        $this->assertEquals($paramTag->getType(), 'string', 'Second Match Failed');
+    	$this->assertEquals($paramTag->getDescription(),'Description of return value', 'Final Match Failed');
+    }    
 }
     

+ 16 - 1
tests/Zend/Reflection/Docblock/TagTest.php

@@ -54,5 +54,20 @@ class Zend_Reflection_Docblock_TagTest extends PHPUnit_Framework_TestCase
         $authorTag = $classReflection->getDocblock()->getTag('author');
         $this->assertEquals($authorTag->getDescription(), 'Ralph Schindler <ralph.schindler@zend.com>');
     }
+
+    public function testAllowsJustTagNameInDocblockTagLine()
+    {
+    	$classReflection = new Zend_Reflection_Class('Zend_Reflection_TestSampleClass6');
+    	
+        $tag = $classReflection->getMethod('doSomething')->getDocblock()->getTag('emptyTag');
+        $this->assertEquals($tag->getName(), 'emptyTag', 'Factory First Match Failed');
+    }
     
-}
+    public function testAllowsMultipleWhitespacesBeforeDescription()
+    {
+		$classReflection = new Zend_Reflection_Class('Zend_Reflection_TestSampleClass6');
+    	
+        $tag = $classReflection->getMethod('doSomething')->getDocblock()->getTag('descriptionTag');
+        $this->assertEquals($tag->getDescription(), 'A tag with just a description', 'Final Match Failed');
+    }
+}

+ 29 - 0
tests/Zend/Reflection/_files/TestSampleClass.php

@@ -123,7 +123,36 @@ class Zend_Reflection_TestSampleClass5 {
     
 }
 
+/**
+ * TestSampleClass6 Docblock Short Desc
+ * 
+ * Testing for formatted dockblock tags. See ZF-6726.
+ * (This long description should be longer than 3 lines.
+ * It indeed is longer than 3 lines
+ * now.)
+ * 
+ * @author Carlton Gibson <carlton.gibson@noumenal.co.uk>
+ */
+class Zend_Reflection_TestSampleClass6 {
 
+    /**
+     * Method ShortDescription
+     * 
+     * Notice the multiple spaces aligning the columns in the docblock
+     * tags. (This long description should be longer than 3 lines.
+	 * It indeed is longer than 3 lines
+	 * now.)
+	 *
+	 * @emptyTag
+	 * @descriptionTag           A tag with just a description
+	 * @param   int     $var     Description of $var
+	 * @return  string           Description of return value
+     */
+    public function doSomething($var)
+    {
+        return 'mixedValue';
+    }
+}
 
 /**
  * Enter description here...