cvs: pear /QA_Peardoc_Coverage/QA/Peardoc Coverage.php /QA_Peardoc_Coverage/QA/Peardoc/Coverage ClassList.php MethodList.php
/QA_Peardoc_Coverage/QA/Peardoc/Coverage/Renderer ExtendetPackageList.php /QA_Peardoc_Coverage/tests QA_Peardoc_Coverage_ClassListTest.php
QA_Peardoc_Coverage_MethodListTest.php
| From: | Christian Weiske | Date: | Mon, 30 Oct 2006 15:00:32 +0000 |
| Subject: | cvs: pear /QA_Peardoc_Coverage/QA/Peardoc Coverage.php /QA_Peardoc_Coverage/QA/Peardoc/Coverage ClassList.php MethodList.php /QA_Peardoc_Coverage/QA/Peardoc/Coverage/Renderer ExtendetPackageList.php /QA_Peardoc_Coverage/tests QA_Peardoc_Coverage_ClassListTest.php QA_Peardoc_Coverage_MethodListTest.php |
||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-42890@lists.php.net to get a copy of this message | ||
cweiske Mon Oct 30 15:00:32 2006 UTC
Modified files:
/pear/QA_Peardoc_Coverage/QA/Peardoc Coverage.php
/pear/QA_Peardoc_Coverage/QA/Peardoc/Coverage ClassList.php
MethodList.php
/pear/QA_Peardoc_Coverage/QA/Peardoc/Coverage/Renderer
ExtendetPackageList.php
/pear/QA_Peardoc_Coverage/tests
QA_Peardoc_Coverage_ClassListTest.php
QA_Peardoc_Coverage_MethodListTest.php
Log:
- Support for multiple classes per file
- Better extendet stats
http://cvs.php.net/viewvc.cgi/pear/QA_Peardoc_Coverage/QA/Peardoc/Coverage.php?r1=1.2&r2=1.3&diff_format=u Index: pear/QA_Peardoc_Coverage/QA/Peardoc/Coverage.php diff -u pear/QA_Peardoc_Coverage/QA/Peardoc/Coverage.php:1.2 pear/QA_Peardoc_Coverage/QA/Peardoc/Coverage.php:1.3 --- pear/QA_Peardoc_Coverage/QA/Peardoc/Coverage.php:1.2 Mon Oct 30 13:12:21 2006 +++ pear/QA_Peardoc_Coverage/QA/Peardoc/Coverage.php Mon Oct 30 15:00:32 2006 @@ -412,50 +412,51 @@ } foreach ( - QA_Peardoc_Coverage_ClassList::getClassList($strPackageDir) + QA_Peardoc_Coverage_ClassList::getFileList($strPackageDir) as $strClassFile ) { - - $arClass = QA_Peardoc_Coverage_MethodList::getMethods($strClassFile); - if ($arClass === false) { - continue; - } - list($strClassName, $arMethods) = $arClass; - - //Check if class is documented - $strClassDocId = $strBaseId . '.' . strtolower(str_replace('_', '-', $strClassName)); - - if (!isset($arDocClasses[$strClassName]) && !$this->existsId($strClassDocId)) { - //FIXME: if classname is the same as package name -> short version - //class is not documented - $arDoc[$strClassName] = null; + $arClasses = QA_Peardoc_Coverage_MethodList::getMethods($strClassFile); + if (count($arClasses) == 0) { continue; } - - $arDocMethods = array(); - foreach ($baseElement->getElementsByTagName('function') as $funcElement) { - $arDocMethods[$funcElement->nodeValue] = true; - } - - //check if methods exist - foreach ($arMethods as $strMethod => $bDocBlock) { - //omit constructors - if ($strMethod == $strClassName || $strMethod == '__construct') { + foreach ($arClasses as $strClassName => $arMethods) { + if ($strClassName[0] == '*') { continue; } + //Check if class is documented + $strClassDocId = $strBaseId . '.' . strtolower(str_replace('_', '-', $strClassName)); - if (isset($arDocMethods[$strMethod])) { - //first check if the method is in a <function> tag - $arDoc[$strClassName][$strMethod] = true; - } else { - //then check if the method has its own section - $strMethodDocId = $strClassDocId . '.' . strtolower(str_replace('_', '-', $strMethod)); + if (!isset($arDocClasses[$strClassName]) && !$this->existsId($strClassDocId)) { + //FIXME: if classname is the same as package name -> short version + //class is not documented + $arDoc[$strClassName] = null; + continue; + } - $arDoc[$strClassName][$strMethod] = $this->existsId($strMethodDocId); + $arDocMethods = array(); + foreach ($baseElement->getElementsByTagName('function') as $funcElement) { + $arDocMethods[$funcElement->nodeValue] = true; } - }//foreach method - }//foreach class + //check if methods exist + foreach ($arMethods as $strMethod => $bDocBlock) { + //omit constructors + if ($strMethod == $strClassName || $strMethod == '__construct') { + continue; + } + + if (isset($arDocMethods[$strMethod])) { + //first check if the method is in a <function> tag + $arDoc[$strClassName][$strMethod] = true; + } else { + //then check if the method has its own section + $strMethodDocId = $strClassDocId . '.' . strtolower(str_replace('_', '-', $strMethod)); + + $arDoc[$strClassName][$strMethod] = $this->existsId($strMethodDocId); + } + }//foreach method + }//foreach class + }//foreach file return $arDoc; }//public function getPackageCoverage($strPackage, $strCategory, $strBaseId, $strPackageDir) http://cvs.php.net/viewvc.cgi/pear/QA_Peardoc_Coverage/QA/Peardoc/Coverage/ClassList.php?r1=1.1&r2=1.2&diff_format=u Index: pear/QA_Peardoc_Coverage/QA/Peardoc/Coverage/ClassList.php diff -u pear/QA_Peardoc_Coverage/QA/Peardoc/Coverage/ClassList.php:1.1 pear/QA_Peardoc_Coverage/QA/Peardoc/Coverage/ClassList.php:1.2 --- pear/QA_Peardoc_Coverage/QA/Peardoc/Coverage/ClassList.php:1.1 Thu Oct 26 06:26:12 2006 +++ pear/QA_Peardoc_Coverage/QA/Peardoc/Coverage/ClassList.php Mon Oct 30 15:00:32 2006 @@ -109,7 +109,7 @@ * (or relative to package dir) * @return array Array with absolute file paths */ - public static function getClassList($strPackageDir, $bAbsolute = true) + public static function getFileList($strPackageDir, $bAbsolute = true) { if (!file_exists($strPackageDir) || !is_dir($strPackageDir)) { throw new Exception("Package directory does not exist: " . $strPackageDir); @@ -138,7 +138,27 @@ chdir($strPath); return $arFiles; - }//public static function getClassList($strPackageDir, $bAbsolute = true) + }//public static function getFileList($strPackageDir, $bAbsolute = true) + + + + /** + * Tries to find classnames in a given file + * + * @param string $strClassFile .php filename + * @return array Array of classnames defined in the file + */ + public static function getClassnamesFromFilename($strClassFile) + { + //simple: open file and search for "class classname" + $strContent = file_get_contents($strClassFile); + + if (preg_match_all('/' . "(?:\r|\n)" . '\\s*(?:abstract\\s+)?(?:final\\s+)?(?:[Cc]lass|interface)\\s+([A-Za-z0-9_]+)/', $strContent, $arMatches)) { + return $arMatches[1]; + } else { + return array(); + } + }//public static function getClassnamesFromFilename($strClassFile) }//class QA_Peardoc_Coverage_Classlist ?> \ No newline at end of file http://cvs.php.net/viewvc.cgi/pear/QA_Peardoc_Coverage/QA/Peardoc/Coverage/MethodList.php?r1=1.1&r2=1.2&diff_format=u Index: pear/QA_Peardoc_Coverage/QA/Peardoc/Coverage/MethodList.php diff -u pear/QA_Peardoc_Coverage/QA/Peardoc/Coverage/MethodList.php:1.1 pear/QA_Peardoc_Coverage/QA/Peardoc/Coverage/MethodList.php:1.2 --- pear/QA_Peardoc_Coverage/QA/Peardoc/Coverage/MethodList.php:1.1 Thu Oct 26 06:26:12 2006 +++ pear/QA_Peardoc_Coverage/QA/Peardoc/Coverage/MethodList.php Mon Oct 30 15:00:32 2006 @@ -1,4 +1,5 @@ <?php +require_once 'QA/Peardoc/Coverage/ClassList.php'; /** * Returns a method list for the class @@ -9,11 +10,11 @@ class QA_Peardoc_Coverage_MethodList { /** - * Returns a method list for the class + * Returns a class => method list for the classes * defined in the given filename. * * @param string $strClassFile Path of a .php file to load - * @return array Array with classname and methods + * @return array Array with classname => methods => bool array */ public static function getMethods($strClassFile) { @@ -21,15 +22,16 @@ throw new Exception('File does not exist: ' . $strClassFile); } - $strClassName = self::getClassnameFromFilename($strClassFile); + $arClassnames = QA_Peardoc_Coverage_ClassList::getClassnamesFromFilename($strClassFile); - if ($strClassName === false) { - return false; + if (count($arClassnames) == 0) { + return array(); } $bWaitForClassname = false; $bWaitForMethodname = false; $arMethods = array(); + $strClassName = '*funcs*'; foreach ( token_get_all( file_get_contents($strClassFile) @@ -43,42 +45,23 @@ } else if ($nId == T_FUNCTION) { $bWaitForMethodname = true; } else if ($bWaitForClassname && $nId == T_STRING) { + //classname found $strClassName = $strText; + $arMethods[$strClassName] = array(); $bWaitForClassname = false; } else if ($bWaitForMethodname && $nId == T_STRING) { + //methodname found $strMethodname = $strText; //FIXME: check if docblock //FIXME: use public methods only - $arMethods[$strMethodname] = false; + $arMethods[$strClassName][$strMethodname] = false; $bWaitForMethodname = false; } } } - return array($strClassName, $arMethods); + return $arMethods; }//public static function getMethods($strClassFile) - - - /** - * Tries to guess a classname from a given filename - * - * @param string $strClassFile .php filename - * @return string Class name OR false if no class found - */ - public static function getClassnameFromFilename($strClassFile) - { - //simple: open file and search for "class classname" - $strContent = file_get_contents($strClassFile); - - if (preg_match('/' . "(?:\r|\n)" . '\\s*(?:abstract\\s+)?(?:final\\s+)?(?:[Cc]lass|interface)\\s+([A-Za-z0-9_]+)/', $strContent, $arMatches)) { - return $arMatches[1]; - } else { - //no match? - //throw new Exception('No classname in ' . $strClassFile); - return false; - } - }//public static function getClassnameFromFilename($strClassFile) - }//class QA_Peardoc_Coverage_MethodList ?> \ No newline at end of file http://cvs.php.net/viewvc.cgi/pear/QA_Peardoc_Coverage/QA/Peardoc/Coverage/Renderer/ExtendetPackageList.php?r1=1.1&r2=1.2&diff_format=u Index: pear/QA_Peardoc_Coverage/QA/Peardoc/Coverage/Renderer/ExtendetPackageList.php diff -u pear/QA_Peardoc_Coverage/QA/Peardoc/Coverage/Renderer/ExtendetPackageList.php:1.1 pear/QA_Peardoc_Coverage/QA/Peardoc/Coverage/Renderer/ExtendetPackageList.php:1.2 --- pear/QA_Peardoc_Coverage/QA/Peardoc/Coverage/Renderer/ExtendetPackageList.php:1.1 Thu Oct 26 06:26:12 2006 +++ pear/QA_Peardoc_Coverage/QA/Peardoc/Coverage/Renderer/ExtendetPackageList.php Mon Oct 30 15:00:32 2006 @@ -103,7 +103,7 @@ //not documented $out .= '<td style="background-color:' . self::$colNotDocumented - . '">not documented</td></tr>' . $n; + . '">undocumented</td></tr>' . $n; } else { //documented ++$nDoccedPackages; @@ -163,7 +163,7 @@ //FIXME: display not docced $out .= '<tr><td></td><td class="class">' . $strClass - . '</td><td style="background-color:' . self::$colMethodNotDocumented . '">poor</td></tr>' . $n; + . '</td><td style="background-color:' . self::$colMethodNotDocumented. '">undocumented</td></tr>' . $n; continue; } @@ -202,10 +202,10 @@ } if ($nMethods == $nMethodsDocced) { - $strState = 'perfect'; + $strState = 'perfect (' . $nMethodsDocced . ')'; $col = self::$colMethodDocumented; } else if ($nMethodsDocced == 0) { - $strState = 'poor'; + $strState = 'poor (' . $nMethods . ')'; $col = self::$colMethodNotDocumented; } else { $strState = 'partly'; http://cvs.php.net/viewvc.cgi/pear/QA_Peardoc_Coverage/tests/QA_Peardoc_Coverage_ClassListTest.php?r1=1.2&r2=1.3&diff_format=u Index: pear/QA_Peardoc_Coverage/tests/QA_Peardoc_Coverage_ClassListTest.php diff -u pear/QA_Peardoc_Coverage/tests/QA_Peardoc_Coverage_ClassListTest.php:1.2 pear/QA_Peardoc_Coverage/tests/QA_Peardoc_Coverage_ClassListTest.php:1.3 --- pear/QA_Peardoc_Coverage/tests/QA_Peardoc_Coverage_ClassListTest.php:1.2 Mon Oct 30 13:12:21 2006 +++ pear/QA_Peardoc_Coverage/tests/QA_Peardoc_Coverage_ClassListTest.php Mon Oct 30 15:00:32 2006 @@ -58,13 +58,20 @@ { $strAuthDir = $this->strPearDir . '/Auth'; $this->assertTrue(file_exists($strAuthDir)); - $ar = QA_Peardoc_Coverage_ClassList::getClassList($strAuthDir, false); + $ar = QA_Peardoc_Coverage_ClassList::getFileList($strAuthDir, false); $this->assertNotEquals(0, count($ar)); $this->assertTrue(in_array('Auth.php', $ar)); $this->assertTrue(in_array('Auth/Auth.php', $ar)); $this->assertTrue(in_array('Container/Array.php', $ar)); $this->assertFalse(in_array('tests/DBContainer.php', $ar)); + + $ar2 = QA_Peardoc_Coverage_ClassList::getClassnamesFromFilename($strAuthDir . '/Auth.php'); + $this->assertEquals(1, count($ar2)); + $this->assertTrue(in_array('Auth', $ar2)); + $ar2 = QA_Peardoc_Coverage_ClassList::getClassnamesFromFilename($strAuthDir . '/Container/Array.php'); + $this->assertEquals(1, count($ar2)); + $this->assertTrue(in_array('Auth_Container_Array', $ar2)); }//public function testAuth() @@ -73,11 +80,22 @@ { $strMdb2Dir = $this->strPearDir . '/MDB2'; $this->assertTrue(file_exists($strMdb2Dir)); - $ar = QA_Peardoc_Coverage_ClassList::getClassList($strMdb2Dir, false); + $ar = QA_Peardoc_Coverage_ClassList::getFileList($strMdb2Dir, false); $this->assertNotEquals(0, count($ar)); $this->assertTrue(in_array('MDB2.php', $ar)); - } + + $ar2 = QA_Peardoc_Coverage_ClassList::getClassnamesFromFilename($strMdb2Dir. '/MDB2.php'); + $this->assertNotEquals(1, count($ar2)); + $this->assertTrue(in_array('MDB2' , $ar2)); + $this->assertTrue(in_array('MDB2_Error' , $ar2)); + $this->assertTrue(in_array('MDB2_Driver_Common' , $ar2)); + $this->assertTrue(in_array('MDB2_Result' , $ar2)); + $this->assertTrue(in_array('MDB2_Result_Common' , $ar2)); + $this->assertTrue(in_array('MDB2_Row' , $ar2)); + $this->assertTrue(in_array('MDB2_Statement_Common' , $ar2)); + $this->assertTrue(in_array('MDB2_Module_Common' , $ar2)); + }//public function testMDB2() } http://cvs.php.net/viewvc.cgi/pear/QA_Peardoc_Coverage/tests/QA_Peardoc_Coverage_MethodListTest.php?r1=1.1&r2=1.2&diff_format=u Index: pear/QA_Peardoc_Coverage/tests/QA_Peardoc_Coverage_MethodListTest.php diff -u pear/QA_Peardoc_Coverage/tests/QA_Peardoc_Coverage_MethodListTest.php:1.1 pear/QA_Peardoc_Coverage/tests/QA_Peardoc_Coverage_MethodListTest.php:1.2 --- pear/QA_Peardoc_Coverage/tests/QA_Peardoc_Coverage_MethodListTest.php:1.1 Thu Oct 26 06:26:12 2006 +++ pear/QA_Peardoc_Coverage/tests/QA_Peardoc_Coverage_MethodListTest.php Mon Oct 30 15:00:32 2006 @@ -11,6 +11,7 @@ require_once "PHPUnit2/Framework/IncompleteTestError.php"; require_once "QA/Peardoc/Coverage/MethodList.php"; +require_once dirname(__FILE__) . '/config.php'; /** * Test class for QA_Peardoc_Coverage_MethodList. @@ -37,6 +38,9 @@ * @access protected */ protected function setUp() { + $this->strPearDir = $GLOBALS['testConfig']['PearDir']; + $this->assertTrue(file_exists($this->strPearDir)); + $this->assertTrue(is_dir($this->strPearDir)); } /** @@ -49,19 +53,57 @@ } /** - * @todo Implement testGetMethods(). + * */ - public function testGetMethods() { - // Remove the following line when you implement this test. - throw new PHPUnit2_Framework_IncompleteTestError; + public function testGetMethodsAuth() { + $strAuthDir = $this->strPearDir . '/Auth'; + $strAuthFile = $strAuthDir . '/Auth.php'; + $this->assertTrue(file_exists($strAuthFile)); + + $ar = QA_Peardoc_Coverage_MethodList::getMethods($strAuthFile); + $this->assertTrue(isset($ar['Auth'])); + $this->assertTrue(isset($ar['Auth']['Auth'])); + $this->assertTrue(isset($ar['Auth']['applyAuthOptions'])); + $this->assertTrue(isset($ar['Auth']['_loadStorage'])); } /** - * @todo Implement testGetClassnameFromFilename(). + * */ - public function testGetClassnameFromFilename() { - // Remove the following line when you implement this test. - throw new PHPUnit2_Framework_IncompleteTestError; + public function testGetMethodsMDB2() { + $strMdb2Dir = $this->strPearDir . '/MDB2'; + $strMdb2File = $strMdb2Dir. '/MDB2.php'; + $this->assertTrue(file_exists($strMdb2File)); + + $ar = QA_Peardoc_Coverage_MethodList::getMethods($strMdb2File); + $this->assertTrue(isset($ar['MDB2'])); + $this->assertTrue(isset($ar['MDB2_Error'])); + $this->assertTrue(isset($ar['MDB2_Driver_Common'])); + $this->assertTrue(isset($ar['MDB2_Result'])); + $this->assertTrue(isset($ar['MDB2_Result_Common'])); + $this->assertTrue(isset($ar['MDB2_Row'])); + $this->assertTrue(isset($ar['MDB2_Statement_Common'])); + $this->assertTrue(isset($ar['MDB2_Module_Common'])); + + $this->assertTrue(isset($ar['MDB2']['setOptions'])); + $this->assertTrue(isset($ar['MDB2']['classExists'])); + $this->assertTrue(isset($ar['MDB2']['loadClass'])); + $this->assertTrue(isset($ar['MDB2']['factory'])); + $this->assertTrue(isset($ar['MDB2']['connect'])); + $this->assertTrue(isset($ar['MDB2']['singleton'])); + + $this->assertTrue(isset($ar['MDB2_Error']['MDB2_Error'])); + $this->assertTrue(isset($ar['MDB2_Error']['MDB2_Error'])); + + $this->assertTrue(isset($ar['MDB2_Driver_Common']['__construct'])); + $this->assertTrue(isset($ar['MDB2_Driver_Common']['__destruct'])); + $this->assertTrue(isset($ar['MDB2_Driver_Common']['MDB2_Driver_Common'])); + $this->assertTrue(isset($ar['MDB2_Driver_Common']['free'])); + $this->assertTrue(isset($ar['MDB2_Driver_Common']['errorInfo'])); + + $this->assertTrue(isset($ar['MDB2_Result_Common']['seek'])); + $this->assertTrue(isset($ar['MDB2_Result_Common']['fetchRow'])); + $this->assertTrue(isset($ar['MDB2_Result_Common']['fetchOne'])); } }
http://cvs.php.net/viewvc.cgi/pear/QA_Peardoc_Coverage/QA/Peardoc/Coverage.php?r1=1.2&r2=1.3&diff_format=u Index: pear/QA_Peardoc_Coverage/QA/Peardoc/Coverage.php diff -u pear/QA_Peardoc_Coverage/QA/Peardoc/Coverage.php:1.2 pear/QA_Peardoc_Coverage/QA/Peardoc/Coverage.php:1.3 --- pear/QA_Peardoc_Coverage/QA/Peardoc/Coverage.php:1.2 Mon Oct 30 13:12:21 2006 +++ pear/QA_Peardoc_Coverage/QA/Peardoc/Coverage.php Mon Oct 30 15:00:32 2006 @@ -412,50 +412,51 @@ } foreach ( - QA_Peardoc_Coverage_ClassList::getClassList($strPackageDir) + QA_Peardoc_Coverage_ClassList::getFileList($strPackageDir) as $strClassFile ) { - - $arClass = QA_Peardoc_Coverage_MethodList::getMethods($strClassFile); - if ($arClass === false) { - continue; - } - list($strClassName, $arMethods) = $arClass; - - //Check if class is documented - $strClassDocId = $strBaseId . '.' . strtolower(str_replace('_', '-', $strClassName)); - - if (!isset($arDocClasses[$strClassName]) && !$this->existsId($strClassDocId)) { - //FIXME: if classname is the same as package name -> short version - //class is not documented - $arDoc[$strClassName] = null; + $arClasses = QA_Peardoc_Coverage_MethodList::getMethods($strClassFile); + if (count($arClasses) == 0) { continue; } - - $arDocMethods = array(); - foreach ($baseElement->getElementsByTagName('function') as $funcElement) { - $arDocMethods[$funcElement->nodeValue] = true; - } - - //check if methods exist - foreach ($arMethods as $strMethod => $bDocBlock) { - //omit constructors - if ($strMethod == $strClassName || $strMethod == '__construct') { + foreach ($arClasses as $strClassName => $arMethods) { + if ($strClassName[0] == '*') { continue; } + //Check if class is documented + $strClassDocId = $strBaseId . '.' . strtolower(str_replace('_', '-', $strClassName)); - if (isset($arDocMethods[$strMethod])) { - //first check if the method is in a <function> tag - $arDoc[$strClassName][$strMethod] = true; - } else { - //then check if the method has its own section - $strMethodDocId = $strClassDocId . '.' . strtolower(str_replace('_', '-', $strMethod)); + if (!isset($arDocClasses[$strClassName]) && !$this->existsId($strClassDocId)) { + //FIXME: if classname is the same as package name -> short version + //class is not documented + $arDoc[$strClassName] = null; + continue; + } - $arDoc[$strClassName][$strMethod] = $this->existsId($strMethodDocId); + $arDocMethods = array(); + foreach ($baseElement->getElementsByTagName('function') as $funcElement) { + $arDocMethods[$funcElement->nodeValue] = true; } - }//foreach method - }//foreach class + //check if methods exist + foreach ($arMethods as $strMethod => $bDocBlock) { + //omit constructors + if ($strMethod == $strClassName || $strMethod == '__construct') { + continue; + } + + if (isset($arDocMethods[$strMethod])) { + //first check if the method is in a <function> tag + $arDoc[$strClassName][$strMethod] = true; + } else { + //then check if the method has its own section + $strMethodDocId = $strClassDocId . '.' . strtolower(str_replace('_', '-', $strMethod)); + + $arDoc[$strClassName][$strMethod] = $this->existsId($strMethodDocId); + } + }//foreach method + }//foreach class + }//foreach file return $arDoc; }//public function getPackageCoverage($strPackage, $strCategory, $strBaseId, $strPackageDir) http://cvs.php.net/viewvc.cgi/pear/QA_Peardoc_Coverage/QA/Peardoc/Coverage/ClassList.php?r1=1.1&r2=1.2&diff_format=u Index: pear/QA_Peardoc_Coverage/QA/Peardoc/Coverage/ClassList.php diff -u pear/QA_Peardoc_Coverage/QA/Peardoc/Coverage/ClassList.php:1.1 pear/QA_Peardoc_Coverage/QA/Peardoc/Coverage/ClassList.php:1.2 --- pear/QA_Peardoc_Coverage/QA/Peardoc/Coverage/ClassList.php:1.1 Thu Oct 26 06:26:12 2006 +++ pear/QA_Peardoc_Coverage/QA/Peardoc/Coverage/ClassList.php Mon Oct 30 15:00:32 2006 @@ -109,7 +109,7 @@ * (or relative to package dir) * @return array Array with absolute file paths */ - public static function getClassList($strPackageDir, $bAbsolute = true) + public static function getFileList($strPackageDir, $bAbsolute = true) { if (!file_exists($strPackageDir) || !is_dir($strPackageDir)) { throw new Exception("Package directory does not exist: " . $strPackageDir); @@ -138,7 +138,27 @@ chdir($strPath); return $arFiles; - }//public static function getClassList($strPackageDir, $bAbsolute = true) + }//public static function getFileList($strPackageDir, $bAbsolute = true) + + + + /** + * Tries to find classnames in a given file + * + * @param string $strClassFile .php filename + * @return array Array of classnames defined in the file + */ + public static function getClassnamesFromFilename($strClassFile) + { + //simple: open file and search for "class classname" + $strContent = file_get_contents($strClassFile); + + if (preg_match_all('/' . "(?:\r|\n)" . '\\s*(?:abstract\\s+)?(?:final\\s+)?(?:[Cc]lass|interface)\\s+([A-Za-z0-9_]+)/', $strContent, $arMatches)) { + return $arMatches[1]; + } else { + return array(); + } + }//public static function getClassnamesFromFilename($strClassFile) }//class QA_Peardoc_Coverage_Classlist ?> \ No newline at end of file http://cvs.php.net/viewvc.cgi/pear/QA_Peardoc_Coverage/QA/Peardoc/Coverage/MethodList.php?r1=1.1&r2=1.2&diff_format=u Index: pear/QA_Peardoc_Coverage/QA/Peardoc/Coverage/MethodList.php diff -u pear/QA_Peardoc_Coverage/QA/Peardoc/Coverage/MethodList.php:1.1 pear/QA_Peardoc_Coverage/QA/Peardoc/Coverage/MethodList.php:1.2 --- pear/QA_Peardoc_Coverage/QA/Peardoc/Coverage/MethodList.php:1.1 Thu Oct 26 06:26:12 2006 +++ pear/QA_Peardoc_Coverage/QA/Peardoc/Coverage/MethodList.php Mon Oct 30 15:00:32 2006 @@ -1,4 +1,5 @@ <?php +require_once 'QA/Peardoc/Coverage/ClassList.php'; /** * Returns a method list for the class @@ -9,11 +10,11 @@ class QA_Peardoc_Coverage_MethodList { /** - * Returns a method list for the class + * Returns a class => method list for the classes * defined in the given filename. * * @param string $strClassFile Path of a .php file to load - * @return array Array with classname and methods + * @return array Array with classname => methods => bool array */ public static function getMethods($strClassFile) { @@ -21,15 +22,16 @@ throw new Exception('File does not exist: ' . $strClassFile); } - $strClassName = self::getClassnameFromFilename($strClassFile); + $arClassnames = QA_Peardoc_Coverage_ClassList::getClassnamesFromFilename($strClassFile); - if ($strClassName === false) { - return false; + if (count($arClassnames) == 0) { + return array(); } $bWaitForClassname = false; $bWaitForMethodname = false; $arMethods = array(); + $strClassName = '*funcs*'; foreach ( token_get_all( file_get_contents($strClassFile) @@ -43,42 +45,23 @@ } else if ($nId == T_FUNCTION) { $bWaitForMethodname = true; } else if ($bWaitForClassname && $nId == T_STRING) { + //classname found $strClassName = $strText; + $arMethods[$strClassName] = array(); $bWaitForClassname = false; } else if ($bWaitForMethodname && $nId == T_STRING) { + //methodname found $strMethodname = $strText; //FIXME: check if docblock //FIXME: use public methods only - $arMethods[$strMethodname] = false; + $arMethods[$strClassName][$strMethodname] = false; $bWaitForMethodname = false; } } } - return array($strClassName, $arMethods); + return $arMethods; }//public static function getMethods($strClassFile) - - - /** - * Tries to guess a classname from a given filename - * - * @param string $strClassFile .php filename - * @return string Class name OR false if no class found - */ - public static function getClassnameFromFilename($strClassFile) - { - //simple: open file and search for "class classname" - $strContent = file_get_contents($strClassFile); - - if (preg_match('/' . "(?:\r|\n)" . '\\s*(?:abstract\\s+)?(?:final\\s+)?(?:[Cc]lass|interface)\\s+([A-Za-z0-9_]+)/', $strContent, $arMatches)) { - return $arMatches[1]; - } else { - //no match? - //throw new Exception('No classname in ' . $strClassFile); - return false; - } - }//public static function getClassnameFromFilename($strClassFile) - }//class QA_Peardoc_Coverage_MethodList ?> \ No newline at end of file http://cvs.php.net/viewvc.cgi/pear/QA_Peardoc_Coverage/QA/Peardoc/Coverage/Renderer/ExtendetPackageList.php?r1=1.1&r2=1.2&diff_format=u Index: pear/QA_Peardoc_Coverage/QA/Peardoc/Coverage/Renderer/ExtendetPackageList.php diff -u pear/QA_Peardoc_Coverage/QA/Peardoc/Coverage/Renderer/ExtendetPackageList.php:1.1 pear/QA_Peardoc_Coverage/QA/Peardoc/Coverage/Renderer/ExtendetPackageList.php:1.2 --- pear/QA_Peardoc_Coverage/QA/Peardoc/Coverage/Renderer/ExtendetPackageList.php:1.1 Thu Oct 26 06:26:12 2006 +++ pear/QA_Peardoc_Coverage/QA/Peardoc/Coverage/Renderer/ExtendetPackageList.php Mon Oct 30 15:00:32 2006 @@ -103,7 +103,7 @@ //not documented $out .= '<td style="background-color:' . self::$colNotDocumented - . '">not documented</td></tr>' . $n; + . '">undocumented</td></tr>' . $n; } else { //documented ++$nDoccedPackages; @@ -163,7 +163,7 @@ //FIXME: display not docced $out .= '<tr><td></td><td class="class">' . $strClass - . '</td><td style="background-color:' . self::$colMethodNotDocumented . '">poor</td></tr>' . $n; + . '</td><td style="background-color:' . self::$colMethodNotDocumented. '">undocumented</td></tr>' . $n; continue; } @@ -202,10 +202,10 @@ } if ($nMethods == $nMethodsDocced) { - $strState = 'perfect'; + $strState = 'perfect (' . $nMethodsDocced . ')'; $col = self::$colMethodDocumented; } else if ($nMethodsDocced == 0) { - $strState = 'poor'; + $strState = 'poor (' . $nMethods . ')'; $col = self::$colMethodNotDocumented; } else { $strState = 'partly'; http://cvs.php.net/viewvc.cgi/pear/QA_Peardoc_Coverage/tests/QA_Peardoc_Coverage_ClassListTest.php?r1=1.2&r2=1.3&diff_format=u Index: pear/QA_Peardoc_Coverage/tests/QA_Peardoc_Coverage_ClassListTest.php diff -u pear/QA_Peardoc_Coverage/tests/QA_Peardoc_Coverage_ClassListTest.php:1.2 pear/QA_Peardoc_Coverage/tests/QA_Peardoc_Coverage_ClassListTest.php:1.3 --- pear/QA_Peardoc_Coverage/tests/QA_Peardoc_Coverage_ClassListTest.php:1.2 Mon Oct 30 13:12:21 2006 +++ pear/QA_Peardoc_Coverage/tests/QA_Peardoc_Coverage_ClassListTest.php Mon Oct 30 15:00:32 2006 @@ -58,13 +58,20 @@ { $strAuthDir = $this->strPearDir . '/Auth'; $this->assertTrue(file_exists($strAuthDir)); - $ar = QA_Peardoc_Coverage_ClassList::getClassList($strAuthDir, false); + $ar = QA_Peardoc_Coverage_ClassList::getFileList($strAuthDir, false); $this->assertNotEquals(0, count($ar)); $this->assertTrue(in_array('Auth.php', $ar)); $this->assertTrue(in_array('Auth/Auth.php', $ar)); $this->assertTrue(in_array('Container/Array.php', $ar)); $this->assertFalse(in_array('tests/DBContainer.php', $ar)); + + $ar2 = QA_Peardoc_Coverage_ClassList::getClassnamesFromFilename($strAuthDir . '/Auth.php'); + $this->assertEquals(1, count($ar2)); + $this->assertTrue(in_array('Auth', $ar2)); + $ar2 = QA_Peardoc_Coverage_ClassList::getClassnamesFromFilename($strAuthDir . '/Container/Array.php'); + $this->assertEquals(1, count($ar2)); + $this->assertTrue(in_array('Auth_Container_Array', $ar2)); }//public function testAuth() @@ -73,11 +80,22 @@ { $strMdb2Dir = $this->strPearDir . '/MDB2'; $this->assertTrue(file_exists($strMdb2Dir)); - $ar = QA_Peardoc_Coverage_ClassList::getClassList($strMdb2Dir, false); + $ar = QA_Peardoc_Coverage_ClassList::getFileList($strMdb2Dir, false); $this->assertNotEquals(0, count($ar)); $this->assertTrue(in_array('MDB2.php', $ar)); - } + + $ar2 = QA_Peardoc_Coverage_ClassList::getClassnamesFromFilename($strMdb2Dir. '/MDB2.php'); + $this->assertNotEquals(1, count($ar2)); + $this->assertTrue(in_array('MDB2' , $ar2)); + $this->assertTrue(in_array('MDB2_Error' , $ar2)); + $this->assertTrue(in_array('MDB2_Driver_Common' , $ar2)); + $this->assertTrue(in_array('MDB2_Result' , $ar2)); + $this->assertTrue(in_array('MDB2_Result_Common' , $ar2)); + $this->assertTrue(in_array('MDB2_Row' , $ar2)); + $this->assertTrue(in_array('MDB2_Statement_Common' , $ar2)); + $this->assertTrue(in_array('MDB2_Module_Common' , $ar2)); + }//public function testMDB2() } http://cvs.php.net/viewvc.cgi/pear/QA_Peardoc_Coverage/tests/QA_Peardoc_Coverage_MethodListTest.php?r1=1.1&r2=1.2&diff_format=u Index: pear/QA_Peardoc_Coverage/tests/QA_Peardoc_Coverage_MethodListTest.php diff -u pear/QA_Peardoc_Coverage/tests/QA_Peardoc_Coverage_MethodListTest.php:1.1 pear/QA_Peardoc_Coverage/tests/QA_Peardoc_Coverage_MethodListTest.php:1.2 --- pear/QA_Peardoc_Coverage/tests/QA_Peardoc_Coverage_MethodListTest.php:1.1 Thu Oct 26 06:26:12 2006 +++ pear/QA_Peardoc_Coverage/tests/QA_Peardoc_Coverage_MethodListTest.php Mon Oct 30 15:00:32 2006 @@ -11,6 +11,7 @@ require_once "PHPUnit2/Framework/IncompleteTestError.php"; require_once "QA/Peardoc/Coverage/MethodList.php"; +require_once dirname(__FILE__) . '/config.php'; /** * Test class for QA_Peardoc_Coverage_MethodList. @@ -37,6 +38,9 @@ * @access protected */ protected function setUp() { + $this->strPearDir = $GLOBALS['testConfig']['PearDir']; + $this->assertTrue(file_exists($this->strPearDir)); + $this->assertTrue(is_dir($this->strPearDir)); } /** @@ -49,19 +53,57 @@ } /** - * @todo Implement testGetMethods(). + * */ - public function testGetMethods() { - // Remove the following line when you implement this test. - throw new PHPUnit2_Framework_IncompleteTestError; + public function testGetMethodsAuth() { + $strAuthDir = $this->strPearDir . '/Auth'; + $strAuthFile = $strAuthDir . '/Auth.php'; + $this->assertTrue(file_exists($strAuthFile)); + + $ar = QA_Peardoc_Coverage_MethodList::getMethods($strAuthFile); + $this->assertTrue(isset($ar['Auth'])); + $this->assertTrue(isset($ar['Auth']['Auth'])); + $this->assertTrue(isset($ar['Auth']['applyAuthOptions'])); + $this->assertTrue(isset($ar['Auth']['_loadStorage'])); } /** - * @todo Implement testGetClassnameFromFilename(). + * */ - public function testGetClassnameFromFilename() { - // Remove the following line when you implement this test. - throw new PHPUnit2_Framework_IncompleteTestError; + public function testGetMethodsMDB2() { + $strMdb2Dir = $this->strPearDir . '/MDB2'; + $strMdb2File = $strMdb2Dir. '/MDB2.php'; + $this->assertTrue(file_exists($strMdb2File)); + + $ar = QA_Peardoc_Coverage_MethodList::getMethods($strMdb2File); + $this->assertTrue(isset($ar['MDB2'])); + $this->assertTrue(isset($ar['MDB2_Error'])); + $this->assertTrue(isset($ar['MDB2_Driver_Common'])); + $this->assertTrue(isset($ar['MDB2_Result'])); + $this->assertTrue(isset($ar['MDB2_Result_Common'])); + $this->assertTrue(isset($ar['MDB2_Row'])); + $this->assertTrue(isset($ar['MDB2_Statement_Common'])); + $this->assertTrue(isset($ar['MDB2_Module_Common'])); + + $this->assertTrue(isset($ar['MDB2']['setOptions'])); + $this->assertTrue(isset($ar['MDB2']['classExists'])); + $this->assertTrue(isset($ar['MDB2']['loadClass'])); + $this->assertTrue(isset($ar['MDB2']['factory'])); + $this->assertTrue(isset($ar['MDB2']['connect'])); + $this->assertTrue(isset($ar['MDB2']['singleton'])); + + $this->assertTrue(isset($ar['MDB2_Error']['MDB2_Error'])); + $this->assertTrue(isset($ar['MDB2_Error']['MDB2_Error'])); + + $this->assertTrue(isset($ar['MDB2_Driver_Common']['__construct'])); + $this->assertTrue(isset($ar['MDB2_Driver_Common']['__destruct'])); + $this->assertTrue(isset($ar['MDB2_Driver_Common']['MDB2_Driver_Common'])); + $this->assertTrue(isset($ar['MDB2_Driver_Common']['free'])); + $this->assertTrue(isset($ar['MDB2_Driver_Common']['errorInfo'])); + + $this->assertTrue(isset($ar['MDB2_Result_Common']['seek'])); + $this->assertTrue(isset($ar['MDB2_Result_Common']['fetchRow'])); + $this->assertTrue(isset($ar['MDB2_Result_Common']['fetchOne'])); } }