[ Index ] |
|
Code source de PRADO 3.0.6 |
1 <?php 2 3 if(!defined('PRADO_FRAMEWORK')) 4 define('PRADO_FRAMEWORK',realpath(dirname(__FILE__).'/../../framework')); 5 6 $TEST_TOOLS = dirname(__FILE__); 7 8 require_once ($TEST_TOOLS.'/simpletest/unit_tester.php'); 9 require_once ($TEST_TOOLS.'/simpletest/web_tester.php'); 10 require_once ($TEST_TOOLS.'/simpletest/mock_objects.php'); 11 require_once ($TEST_TOOLS.'/simpletest/reporter.php'); 12 13 require_once(PRADO_FRAMEWORK.'/prado.php'); 14 15 class TMockApplication extends TApplication 16 { 17 public function run() 18 { 19 $this->initApplication(); 20 } 21 } 22 23 class TestFolder 24 { 25 public $name=''; 26 public $url=''; 27 public $subFolders=array(); 28 public $testFiles=array(); 29 30 public function __construct($path,$rootPath,$rootUri) 31 { 32 $script = basename($_SERVER['SCRIPT_NAME']); 33 $this->url="$rootUri/$script?target=".strtr(substr($path,strlen($rootPath)+1),"\\",'/'); 34 $this->name=basename($path); 35 $dir=opendir($path); 36 while(($entry=readdir($dir))!==false) 37 { 38 $fullpath="$path/$entry"; 39 if($entry!=='.' && $entry!=='..' && $entry!=='.svn' && is_dir($fullpath)) 40 { 41 $folder=new TestFolder($fullpath,$rootPath,$rootUri); 42 if(!empty($folder->subFolders) || !empty($folder->testFiles)) 43 $this->subFolders[]=$folder; 44 } 45 else if(is_file($fullpath) && (strncmp($entry,'ut',2)===0 46 || preg_match('/test.*\.php/', strtolower($entry)))) 47 { 48 $this->testFiles[$entry]="$rootUri/$script?target=".strtr(substr($fullpath,strlen($rootPath)+1),"\\",'/'); 49 } 50 } 51 closedir($dir); 52 } 53 54 public function getHtml($level=0) 55 { 56 $str=str_repeat(' ',$level*4)."[ <a href=\"{$this->url}\">{$this->name}</a> ]<br/>\n"; 57 foreach($this->subFolders as $folder) 58 $str.=$folder->getHtml($level+1); 59 foreach($this->testFiles as $name=>$url) 60 $str.=str_repeat(' ',($level+1)*4)."<a href=\"$url\">$name</a><br/>\n"; 61 return $str; 62 } 63 } 64 65 class PradoUnitTester 66 { 67 private $_root; 68 69 function __construct($root, $app_dir) 70 { 71 $this->_root = $root; 72 Prado::setPathOfAlias('Tests', $root); 73 $app = new TMockApplication($app_dir); 74 $app->run(); 75 } 76 77 function addTests($test,$path,$recursive) 78 { 79 $dir=opendir($path); 80 while(($entry=readdir($dir))!==false) 81 { 82 if(is_file($path.'/'.$entry) && (strncmp($entry,'ut',2)===0||preg_match('/test.*\.php/', strtolower($entry)))) 83 $test->addTestFile($path.'/'.$entry); 84 else if($entry!=='.' && $entry!=='..' && $entry!=='.svn' && is_dir($path.'/'.$entry) && $recursive) 85 $this->addTests($test,$path.'/'.$entry,$recursive); 86 } 87 closedir($dir); 88 } 89 90 function run($reporter) 91 { 92 $rootPath=realpath($this->_root); 93 $rootUri=dirname($_SERVER['PHP_SELF']); 94 if(isset($_GET['target'])) 95 { 96 $target=$_GET['target']; 97 $recursive=true; 98 $fullpath=realpath("$rootPath/$target"); 99 if($fullpath===false || strpos($fullpath,$rootPath)!==0) 100 die('invalid test target'); 101 102 if(is_dir($fullpath)) 103 { 104 105 $test=new GroupTest(basename($rootPath)."/$target"); 106 $this->addTests($test,$fullpath,$recursive); 107 $test->run($reporter); 108 //$test->run(new HtmlReporterWithCoverage('index.php',$rootPath)); 109 } 110 else 111 { 112 $testClass=basename($fullpath,'.php'); 113 include_once($fullpath); 114 $test=new $testClass(basename($rootPath)."/$target"); 115 $test->run($reporter); 116 } 117 } 118 else 119 { 120 echo "<html> 121 <head> 122 <title>Prado Unit Tests</title> 123 <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"> 124 </head> 125 <body> 126 <h1>Prado Unit Tests</h1> 127 "; 128 $root=new TestFolder($rootPath,$rootPath,$rootUri); 129 echo $root->getHtml(); 130 echo "</body>\n</html>"; 131 } 132 } 133 } 134 135 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Sun Feb 25 21:07:04 2007 | par Balluche grâce à PHPXref 0.7 |