Prechádzať zdrojové kódy

ZF-6544
- Added multi-line method body to test classes. Modified test case to use this.
- Altered file() call in getBody() to use FILE_IGNORE_NEW_LINES flag.
- Adjusted FileTest to account for new longer method body in test class.

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

carlton 16 rokov pred
rodič
commit
221f2943ff

+ 2 - 2
library/Zend/Reflection/Method.php

@@ -144,7 +144,7 @@ class Zend_Reflection_Method extends ReflectionMethod
     public function getBody()
     {
         $lines = array_slice(
-            file($this->getDeclaringClass()->getFileName()),
+            file($this->getDeclaringClass()->getFileName(), FILE_IGNORE_NEW_LINES),
             $this->getStartLine(),
             ($this->getEndLine() - $this->getStartLine()),
             true
@@ -162,7 +162,7 @@ class Zend_Reflection_Method extends ReflectionMethod
             array_push($lines, $lastLine);
         }
 
-        // just in case we had code on the braket lines
+        // just in case we had code on the bracket lines
         return rtrim(ltrim(implode("\n", $lines), '{'), '}');
     }
 }

+ 1 - 1
tests/Zend/Reflection/FileTest.php

@@ -115,7 +115,7 @@ class Zend_Reflection_FileTest extends PHPUnit_Framework_TestCase
         require_once $fileToRequire;
         $reflectionFile = new Zend_Reflection_File($fileToRequire);
         $this->assertEquals(9, $reflectionFile->getStartLine());
-        $this->assertEquals(169, $reflectionFile->getEndLine());
+        $this->assertEquals(172, $reflectionFile->getEndLine());
     }
     
     public function testFileGetDocblockReturnsFileDocblock()

+ 7 - 3
tests/Zend/Reflection/MethodTest.php

@@ -77,13 +77,17 @@ class Zend_Reflection_MethodTest extends PHPUnit_Framework_TestCase
     
     public function testGetBodyReturnsCorrectBody()
     {
-        $reflectionMethod = new Zend_Reflection_Method('Zend_Reflection_TestSampleClass5', 'doSomething');
-        $this->assertEquals("        return 'mixedValue';\n", $reflectionMethod->getBody());
+        $body = '        //we need a multi-line method body.
+        $assigned = 1;
+        $alsoAssigined = 2;
+        return \'mixedValue\';';
+        $reflectionMethod = new Zend_Reflection_Method('Zend_Reflection_TestSampleClass6', 'doSomething');
+        $this->assertEquals($body, $reflectionMethod->getBody());
     }
     
     public function testGetContentsReturnsCorrectContent()
     {
-        $reflectionMethod = new Zend_Reflection_Method('Zend_Reflection_TestSampleClass5', 'doSomething');
+		$reflectionMethod = new Zend_Reflection_Method('Zend_Reflection_TestSampleClass5', 'doSomething');
         $this->assertEquals("    {\n\n        return 'mixedValue';\n\n    }\n", $reflectionMethod->getContents(false));
     }
     

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

@@ -152,6 +152,9 @@ class Zend_Reflection_TestSampleClass6
      */
     public function doSomething($var)
     {
+        //we need a multi-line method body.
+        $assigned = 1;
+        $alsoAssigined = 2;
         return 'mixedValue';
     }
 }