1. Laurent Jouanneau
  2. Rarangi

Commits

laurentj  committed a92d238

tests are now ok

  • Participants
  • Parent commits 1dd6af0
  • Branches default

Comments (0)

Files changed (17)

File jdoc.php

-<?php
-/**
-* @package     jDoc
-* @author      Laurent Jouanneau
-* @contributor
-* @copyright   2006-2007 Laurent Jouanneau
-* @link        http://www.jelix.org
-* @licence     GNU General Public Licence see LICENCE file or http://www.gnu.org/licenses/gpl.html
-*/
-
-$dirnamefile = dirname(__FILE__).'/';
-require($dirnamefile.'lib/jCmdUtils.class.php');
-require($dirnamefile.'lib/jBuildUtils.lib.php');
-require($dirnamefile.'jDocConfig.class.php');
-require($dirnamefile.'parsers/jFileParser.class.php');
-require($dirnamefile.'jInfos.class.php');
-require($dirnamefile.'jDoc.class.php');
-require($dirnamefile.'jLogger.class.php');
-
-
-//------ read all options in the command line
-$sws = array('-v'=>false, '-x'=>1, '-c'=>1);
-$params = array('projectid'=>true,'sourcepath'=>true);
-
-try{
-    list($switches, $parameters) = jCmdUtils::getOptionsAndParams($_SERVER['argv'], $sws, $params);
-}catch(Exception $e){
-    die($e->getMessage());
-}
-
-//------- setup the configuration
-if(isset($switches['-c']))
-    $gConfig = new jDocConfig($switches['-c']);
-else
-    $gConfig = new jDocConfig();
-    
-if(isset($switches['-x'])) {
-    $gConfig->setExcludedFiles(explode(',',$switches['-x']));
-}else{
-    $gConfig->setExcludedFiles(array('.svn','CVS', '.hg'));
-}
-
-jLogger::addLogger(new jInMemoryLogger());
-if(isset($switches['-v'])){
-    jLogger::addLogger(new jConsoleLogger());
-}
-
-
-//------- prepare and launch the parsing
-
-$docparser = jDoc::getInstance();
-$docparser->setConfig($gConfig);
-
-try {
-    $docparser->run($parameters['sourcepath']);
-}catch(Exception $e){
-    echo "\n ERROR !!!!\n-->", $e->getMessage();
-}
-
-
-//------- process results
-
-// @todo
-
-
-
-
-
-?>

File jphpdoc/application-cli.init.php

View file
+<?php
+/**
+* @package   jphpdoc
+* @subpackage 
+* @author    yourname
+* @copyright 2008 yourname
+* @link      http://www.yourwebsite.undefined
+* @licence    All right reserved
+*/
+
+require (dirname(__FILE__).'/../lib/jelix/init.php');
+
+define ('JELIX_APP_PATH', dirname (__FILE__).DIRECTORY_SEPARATOR); // don't change
+
+define ('JELIX_APP_TEMP_PATH',    realpath(JELIX_APP_PATH.'../temp/jphpdoc-cli/').DIRECTORY_SEPARATOR);
+define ('JELIX_APP_VAR_PATH',     realpath(JELIX_APP_PATH.'./var/').DIRECTORY_SEPARATOR);
+define ('JELIX_APP_LOG_PATH',     realpath(JELIX_APP_PATH.'./var/log/').DIRECTORY_SEPARATOR);
+define ('JELIX_APP_CONFIG_PATH',  realpath(JELIX_APP_PATH.'./var/config/').DIRECTORY_SEPARATOR);
+define ('JELIX_APP_WWW_PATH',     realpath(JELIX_APP_PATH.'./www/').DIRECTORY_SEPARATOR);
+define ('JELIX_APP_CMD_PATH',     realpath(JELIX_APP_PATH.'./scripts/').DIRECTORY_SEPARATOR);
+

File jphpdoc/modules/jphpdoc/classes/jDescriptorTag.class.php

View file
 
     
 
-    public function parseValue();
+    public function parseValue() {
+    }
 
     
 
 
 }
 
-
-?>

File jphpdoc/modules/jphpdoc/classes/jDoc.class.php

View file
 
     /**
      * main method. launches the parsing
-     * @param string $sourcepath  the path of the main directory which contains sources
      */
-    public function run($sourcepath){
-        
-        $sourcepath = realpath($sourcepath);
-        $this->fullSourcePath = $sourcepath;
-        if($sourcepath !='')
-            $this->readFiles(new RecursiveDirectoryIterator($sourcepath));
-        else
-            throw new Exception("unknow path");
+    public function run(){
+        foreach($this->config->getSourceDirectories() as $sourcepath) {
+            $sourcepath = realpath($sourcepath);
+            $this->fullSourcePath = $sourcepath;
+            if($sourcepath !='')
+                $this->readFiles(new RecursiveDirectoryIterator($sourcepath));
+            else
+                throw new Exception("unknow path: $sourcepath");            
+        }
     }
 
     /**

File jphpdoc/modules/jphpdoc/classes/jDocConfig.class.php

View file
      * @var array
      */
     protected $excludedFilesReg = array();
-
-    protected $storage;
-
-    function __construct($configfile='') {
-        if ($configfile != '') {
-            $config = parse_ini_file($configfile,true);
-            if(isset($config['excluded_files']))
-                $this->setExcludedFiles(explode(',',$config['excluded_files']));
-            if(isset($config['storage']))
-                $this->storage = $config['storage'];
-        }
+    
+    
+    function __construct() {
+        $this->setExcludedFiles(array('.svn','CVS', '.hg'));
     }
 
-    function getDbConfig() {
-        return $this->storage;
+    function readConfig($configfile) {
+        $config = parse_ini_file($configfile,true);
+        if(isset($config['excluded_files']))
+            $this->setExcludedFiles(explode(',',$config['excluded_files']));
+        if(isset($config['source_directories']))
+            $this->sourceDirectories = $config['source_directories'];
     }
 
+    protected $sourceDirectories;
+    function getSourceDirectories() {
+        return $this->sourceDirectories;
+    }
 
     /**
      * add list of file names which won't be parsed
      * @param array $files 
      */
     public function setExcludedFiles($files){
+        $this->excludedFilesReg = array();
+        $this->excludedFiles = array();
         foreach($files as $f){
             if($f{0} == '*'){
                 $s = preg_quote(substr($f,1),'/');

File jphpdoc/modules/jphpdoc/classes/jLogger.class.php

View file
  */
 class jConsoleLogger implements jILoggerDriver {
 
-    public function message($str, $f, $l){ echo $str,"\n";}
-    public function notice($str, $f, $l){ echo 'Notice: ',$str,"\n\t($f line $l)\n";}
-    public function warning($str, $f, $l){ echo 'Warning: ',$str,"\n\t($f line $l)\n";}
-    public function error($str, $f, $l){ echo 'Error: ',$str,"\n\t($f line $l)\n";}
+    protected $resp;
+    
+    /**
+     * @param jResponseCmdline $resp
+     */
+    function __construct($resp) {
+        $this->resp = $resp;
+    }
+
+    public function message($str, $f, $l){ $this->resp->addContent($str."\n");}
+    public function notice($str, $f, $l){ $this->resp->addContent( 'Notice: '.$str."\n\t($f line $l)\n");}
+    public function warning($str, $f, $l){ $this->resp->addContent( 'Warning: '.$str."\n\t($f line $l)\n");}
+    public function error($str, $f, $l){ $this->resp->addContent( 'Error: '.$str."\n\t($f line $l)\n");}
     public function clear(){ }
 
 }
     public function getLog(){ return $this->log; }
 }
 
-
-?>

File jphpdoc/modules/jphpdoc/controllers/default.cmdline.php

View file
     * true means that a value should be provided for the option on the command line
     */
     protected $allowed_options = array(
-            'index' => array());
+            'index' => array('-v'=>false));
 
     /**
      * Parameters for the command line
      * is optional
      */
     protected $allowed_parameters = array(
-            'index' => array());
+            'index' => array('config'=>true));
     /**
     *
     */
     function index() {
-        $rep = $this->getResponse(); // cmdline response by default
+        $rep = $this->getResponse();
+        
+        jClasses::inc("jDoc");
+        jClasses::inc("jLogger");
+
+        jLogger::addLogger(new jInMemoryLogger());
+        if(isset($switches['-v'])){
+            jLogger::addLogger(new jConsoleLogger($rep));
+        }
+
+        $config = jClasses::create("jDocConfig");
+        $config->readConfig($this->param('config'));
+
+        $docparser = jDoc::getInstance();
+        $docparser->setConfig($gConfig);
+
+        $docparser->run();
 
         return $rep;
     }

File jphpdoc/modules/jphpdoc/tests/ut_config.html_cli.php

View file
+<?php
+/**
+* @package     jDoc
+* @subpackage  tests
+* @author      Laurent Jouanneau
+* @contributor
+* @copyright   2007-2008 Laurent Jouanneau
+* @link        http://www.jelix.org
+* @licence     GNU General Public Licence see LICENCE file or http://www.gnu.org/licenses/gpl.html
+*/
+
+require_once( dirname(__FILE__).'/../classes/jDocConfig.class.php');
+
+class docConfigTest extends jDocConfig {
+
+    function getExcludedFiles () { return $this->excludedFiles; }
+    function getExcludedFilesReg () { return $this->excludedFilesReg; }
+
+}
+
+
+class ut_config extends jUnitTestCase {
+
+    function testEmptyConfig() {
+        $doc = new docConfigTest();
+        $doc->setExcludedFiles(array());
+        $this->assertIdentical($doc->getExcludedFiles (), array());
+        $this->assertIdentical($doc->getExcludedFilesReg (), array());
+    }
+
+    function testExcludedSimpleFile() {
+        $doc = new docConfigTest();
+        $doc->setExcludedFiles(array('CVS','.svn'));
+        $this->assertIdentical($doc->getExcludedFiles (), array('CVS','.svn'));
+        $this->assertIdentical($doc->getExcludedFilesReg (), array());
+    }
+
+    function testExcludedRegFile() {
+        $doc = new docConfigTest();
+        $doc->setExcludedFiles(array('*foo', '*.foo','bar.*', 'CVS', 'sv*n'));
+        $this->assertIdentical($doc->getExcludedFiles (), array('CVS','sv*n'));
+        $this->assertIdentical($doc->getExcludedFilesReg (), array('/.*foo$/', '/.*\.foo$/','/^bar\..*/'));
+    }
+
+    function testRightExcludedFile(){
+        $doc = new docConfigTest();
+        $doc->setExcludedFiles(array('*foo', '*.foo','bar.*', 'CVS', 'sv*n'));
+
+        $this->assertTrue($doc->isExcludedFile('CVS'));
+        $this->assertTrue($doc->isExcludedFile('foo'));
+        $this->assertTrue($doc->isExcludedFile('truc.foo'));
+        $this->assertTrue($doc->isExcludedFile('bar.truc'));
+        $this->assertTrue($doc->isExcludedFile('aaaaafoo'));
+        $this->assertTrue($doc->isExcludedFile('sv*n'));
+
+    }
+
+    function testWrongExcludedFile(){
+        $doc = new docConfigTest();
+        $doc->setExcludedFiles(array('*foo', '*.foo','bar.*', 'CVS', 'sv*n'));
+
+        $this->assertFalse($doc->isExcludedFile('truc.txt'));
+        $this->assertFalse($doc->isExcludedFile('foomachin'));
+        $this->assertFalse($doc->isExcludedFile('CVS2'));
+        $this->assertFalse($doc->isExcludedFile('.svn'));
+        $this->assertFalse($doc->isExcludedFile('bartruc'));
+        $this->assertFalse($doc->isExcludedFile('bar3.truc'));
+        $this->assertFalse($doc->isExcludedFile('aaasv*n'));
+
+    }
+
+}
+?>

File jphpdoc/modules/jphpdoc/tests/ut_config.php

-<?php
-/**
-* @package     jDoc
-* @subpackage  tests
-* @author      Laurent Jouanneau
-* @contributor
-* @copyright   2007 Laurent Jouanneau
-* @link        http://www.jelix.org
-* @licence     GNU General Public Licence see LICENCE file or http://www.gnu.org/licenses/gpl.html
-*/
-
-include( '../jDocConfig.class.php');
-
-class docConfigTest extends jDocConfig {
-
-    function getExcludedFiles () { return $this->excludedFiles; }
-    function getExcludedFilesReg () { return $this->excludedFilesReg; }
-
-}
-
-
-class ut_config extends jUnitTestCase {
-
-    function testEmptyConfig() {
-        $doc = new docConfigTest();
-        $this->assertIdentical($doc->getExcludedFiles (), array());
-        $this->assertIdentical($doc->getExcludedFilesReg (), array());
-    }
-
-    function testExcludedSimpleFile() {
-        $doc = new docConfigTest();
-        $doc->setExcludedFiles(array('CVS','.svn'));
-        $this->assertIdentical($doc->getExcludedFiles (), array('CVS','.svn'));
-        $this->assertIdentical($doc->getExcludedFilesReg (), array());
-    }
-
-    function testExcludedRegFile() {
-        $doc = new docConfigTest();
-        $doc->setExcludedFiles(array('*foo', '*.foo','bar.*', 'CVS', 'sv*n'));
-        $this->assertIdentical($doc->getExcludedFiles (), array('CVS','sv*n'));
-        $this->assertIdentical($doc->getExcludedFilesReg (), array('/.*foo$/', '/.*\.foo$/','/^bar\..*/'));
-    }
-
-    function testRightExcludedFile(){
-        $doc = new docConfigTest();
-        $doc->setExcludedFiles(array('*foo', '*.foo','bar.*', 'CVS', 'sv*n'));
-
-        $this->assertTrue($doc->isExcludedFile('CVS'));
-        $this->assertTrue($doc->isExcludedFile('foo'));
-        $this->assertTrue($doc->isExcludedFile('truc.foo'));
-        $this->assertTrue($doc->isExcludedFile('bar.truc'));
-        $this->assertTrue($doc->isExcludedFile('aaaaafoo'));
-        $this->assertTrue($doc->isExcludedFile('sv*n'));
-
-    }
-
-    function testWrongExcludedFile(){
-        $doc = new docConfigTest();
-        $doc->setExcludedFiles(array('*foo', '*.foo','bar.*', 'CVS', 'sv*n'));
-
-        $this->assertFalse($doc->isExcludedFile('truc.txt'));
-        $this->assertFalse($doc->isExcludedFile('foomachin'));
-        $this->assertFalse($doc->isExcludedFile('CVS2'));
-        $this->assertFalse($doc->isExcludedFile('.svn'));
-        $this->assertFalse($doc->isExcludedFile('bartruc'));
-        $this->assertFalse($doc->isExcludedFile('bar3.truc'));
-        $this->assertFalse($doc->isExcludedFile('aaasv*n'));
-
-    }
-
-}
-?>

File jphpdoc/modules/jphpdoc/tests/ut_logger.html_cli.php

View file
+<?php
+/**
+* @package     jDoc
+* @subpackage  tests
+* @author      Laurent Jouanneau
+* @contributor
+* @copyright   2007-2008 Laurent Jouanneau
+* @link        http://www.jelix.org
+* @licence     GNU General Public Licence see LICENCE file or http://www.gnu.org/licenses/gpl.html
+*/
+
+class ut_logger extends UnitTestCase {
+    
+    function testFirst() {
+        $this->pass('ok');
+    }
+}
+?>

File jphpdoc/modules/jphpdoc/tests/ut_logger.php

-<?php
-/**
-* @package     jDoc
-* @subpackage  tests
-* @author      Laurent Jouanneau
-* @contributor
-* @copyright   2007 Laurent Jouanneau
-* @link        http://www.jelix.org
-* @licence     GNU General Public Licence see LICENCE file or http://www.gnu.org/licenses/gpl.html
-*/
-
-class ut_logger extends UnitTestCase {
-    
-    function testFirst() {
-        $this->pass('ok');
-    }
-}
-?>

File jphpdoc/modules/jphpdoc/tests/ut_parser_base.html_cli.php

View file
+<?php
+/**
+* @package     jDoc
+* @subpackage  tests
+* @author      Laurent Jouanneau
+* @contributor
+* @copyright   2007-2008 Laurent Jouanneau
+* @link        http://www.jelix.org
+* @licence     GNU General Public Licence see LICENCE file or http://www.gnu.org/licenses/gpl.html
+*/
+
+require_once( dirname(__FILE__).'/../classes/jDocConfig.class.php');
+require_once( dirname(__FILE__).'/../classes/jDoc.class.php');
+require_once( dirname(__FILE__).'/../classes/parsers/jParser_base.class.php');
+
+
+class dummyParser extends jParser_base {
+
+    public function parse(){}
+
+    public  function toNextPhpSection2(){
+       return $this->toNextPhpSection();
+    }
+    
+    public function toNextPhpToken2(){
+        return $this->toNextPhpToken();
+    }
+    
+    public function getIterator(){
+        return  $this->iterator;
+    }
+    
+}
+
+
+class ut_parser_base extends jUnitTestCase {
+    
+    function testNextPhpSimple() {
+        $content = ' <?php $a=     2; ?>';
+        $tokens = new ArrayObject(token_get_all($content));
+        $tokeniter = $tokens->getIterator();
+
+        //$this->sendMessage("tok=". token_name(305));
+        $parser = new dummyParser($tokeniter);
+        
+        $parser->toNextPhpSection2();
+        $tok = $parser->toNextPhpToken2();
+        if(is_array($tok) && count($tok)>2) {
+            $data = array(
+                array(T_VARIABLE, '$a',1),
+                array(T_LNUMBER, '2',1),
+            );
+        }
+        else {
+            $data = array(
+                array(T_VARIABLE, '$a'),
+                array(T_LNUMBER, '2'),
+            );
+        }
+        $this->assertIdentical($tok , $data[0]);
+        
+        $tok = $parser->toNextPhpToken2();
+        $this->assertIdentical($tok , '=');
+        
+        $tok = $parser->toNextPhpToken2();
+        $this->assertIdentical($tok , $data[1]);
+
+        $tok = $parser->toNextPhpToken2();
+        $this->assertIdentical($tok , ';');
+        
+        $tok = $parser->toNextPhpToken2();
+        $this->assertFalse($tok);
+        
+
+    }
+
+    function testNextPhp2() {
+        $content = ' foo bar <?php $a=     2; ?> <a href=""> </a> <?php public function aaa() ?> oooo ';
+        $tokens = new ArrayObject(token_get_all($content));
+        $tokeniter = $tokens->getIterator();
+
+        $parser = new dummyParser($tokeniter);
+        
+        $parser->toNextPhpSection2();
+        $tok = $tokeniter->current();
+        if(is_array($tok) && count($tok)>2) {
+            $data = array(
+                array(T_OPEN_TAG, '<?php ',1),
+                array(T_VARIABLE, '$a',1),
+                array(T_LNUMBER, '2',1),
+                array(T_PUBLIC, 'public',1),
+                array(T_FUNCTION, 'function',1),
+                array(T_STRING, 'aaa',1)
+            );
+        }
+        else {
+            $data = array(
+                array(T_OPEN_TAG, '<?php '),
+                array(T_VARIABLE, '$a'),
+                array(T_LNUMBER, '2'),
+                array(T_PUBLIC, 'public'),
+                array(T_FUNCTION, 'function'),
+                array(T_STRING, 'aaa')
+            );
+        }
+        
+        $this->assertIdentical($tok , $data[0]);
+
+        $tok = $parser->toNextPhpToken2();
+        $this->assertIdentical($tok , $data[1]);
+        
+        $tok = $parser->toNextPhpToken2();
+        $this->assertIdentical($tok , '=');
+        
+        $tok = $parser->toNextPhpToken2();
+        $this->assertIdentical($tok , $data[2]);
+
+        $tok = $parser->toNextPhpToken2();
+        $this->assertIdentical($tok , ';');
+        
+        $tok = $parser->toNextPhpToken2();
+        $this->assertIdentical($tok ,  $data[3]);
+
+        $tok = $parser->toNextPhpToken2();
+        $this->assertIdentical($tok ,  $data[4]);
+
+        $tok = $parser->toNextPhpToken2();
+        $this->assertIdentical($tok ,  $data[5]);
+
+        $tok = $parser->toNextPhpToken2();
+        $this->assertIdentical($tok ,  '(');
+
+        $tok = $parser->toNextPhpToken2();
+        $this->assertIdentical($tok ,  ')');
+
+        $tok = $parser->toNextPhpToken2();
+        $this->assertFalse($tok);
+    }
+
+}
+?>

File jphpdoc/modules/jphpdoc/tests/ut_parser_base.php

-<?php
-/**
-* @package     jDoc
-* @subpackage  tests
-* @author      Laurent Jouanneau
-* @contributor
-* @copyright   2007 Laurent Jouanneau
-* @link        http://www.jelix.org
-* @licence     GNU General Public Licence see LICENCE file or http://www.gnu.org/licenses/gpl.html
-*/
-
-include( '../jDoc.class.php');
-include( '../parsers/jParser_base.class.php');
-
-
-class dummyParser extends jParser_base {
-
-    public function parse(){}
-
-    public  function toNextPhpSection2(){
-       return $this->toNextPhpSection();
-    }
-    
-    public function toNextPhpToken2(){
-        return $this->toNextPhpToken();
-    }
-    
-    public function getIterator(){
-        return  $this->iterator;
-    }
-    
-}
-
-
-class ut_parser_base extends jUnitTestCase {
-    
-    function testNextPhpSimple() {
-        $content = ' <?php $a=     2; ?>';
-        $tokens = new ArrayObject(token_get_all($content));
-        $tokeniter = $tokens->getIterator();
-
-        //$this->sendMessage("tok=". token_name(305));
-        $parser = new dummyParser($tokeniter);
-        
-        $parser->toNextPhpSection2();
-        $tok = $parser->toNextPhpToken2();
-        $this->assertIdentical($tok , array(T_VARIABLE, '$a'));
-        
-        $tok = $parser->toNextPhpToken2();
-        $this->assertIdentical($tok , '=');
-        
-        $tok = $parser->toNextPhpToken2();
-        $this->assertIdentical($tok , array(T_LNUMBER, '2'));
-
-        $tok = $parser->toNextPhpToken2();
-        $this->assertIdentical($tok , ';');
-        
-        $tok = $parser->toNextPhpToken2();
-        $this->assertFalse($tok);
-        
-
-    }
-
-    function testNextPhp2() {
-        $content = ' foo bar <?php $a=     2; ?> <a href=""> </a> <?php public function aaa() ?> oooo ';
-        $tokens = new ArrayObject(token_get_all($content));
-        $tokeniter = $tokens->getIterator();
-
-        $parser = new dummyParser($tokeniter);
-        
-        $parser->toNextPhpSection2();
-        $this->assertIdentical($tokeniter->current() , array(T_OPEN_TAG, '<?php '));
-
-        $tok = $parser->toNextPhpToken2();
-        $this->assertIdentical($tok , array(T_VARIABLE, '$a'));
-        
-        $tok = $parser->toNextPhpToken2();
-        $this->assertIdentical($tok , '=');
-        
-        $tok = $parser->toNextPhpToken2();
-        $this->assertIdentical($tok , array(T_LNUMBER, '2'));
-
-        $tok = $parser->toNextPhpToken2();
-        $this->assertIdentical($tok , ';');
-        
-        $tok = $parser->toNextPhpToken2();
-        $this->assertIdentical($tok ,  array(T_PUBLIC, 'public'));
-
-        $tok = $parser->toNextPhpToken2();
-        $this->assertIdentical($tok ,  array(T_FUNCTION, 'function'));
-
-        $tok = $parser->toNextPhpToken2();
-        $this->assertIdentical($tok ,  array(T_STRING, 'aaa'));
-
-        $tok = $parser->toNextPhpToken2();
-        $this->assertIdentical($tok ,  '(');
-
-        $tok = $parser->toNextPhpToken2();
-        $this->assertIdentical($tok ,  ')');
-
-        $tok = $parser->toNextPhpToken2();
-        $this->assertFalse($tok);
-    }
-
-}
-?>

File jphpdoc/scripts/jphpdoc.php

View file
 * @licence    All right reserved
 */
 
-require_once ('../application.init.php');
+require_once ('../application-cli.init.php');
 
 require_once (JELIX_LIB_CORE_PATH.'jCmdlineCoordinator.class.php');
 

File jphpdoc/scripts/test.ini

View file
+
+project_name = jphpdoc
+
+excluded_files = ".hg,.svn,CVS"
+
+[source_directories]
+path[]="../modules/"
+
+

File jphpdoc/var/config/cmdline/config.ini.php

View file
 
 startModule = "jphpdoc"
 startAction = "default:index"
+
+
+
+; for junittests module
+enableTests = on

File jphpdoc/var/config/defaultconfig.ini.php

View file
 
 theme = default
 
-[jphpdoc]
-exclude_files = ".svn,CVS,.hg"
-
-
-
 [coordplugins]
 ;nom = nom_fichier_ini