[ Index ] |
|
Code source de Symfony 1.0.0 |
1 <?php 2 3 /** 4 * @package pake 5 * @author Fabien Potencier <fabien.potencier@symfony-project.com> 6 * @copyright 2004-2005 Fabien Potencier <fabien.potencier@symfony-project.com> 7 * @license see the LICENSE file included in the distribution 8 * @version SVN: $Id: pakeSimpletestTask.class.php 1791 2006-08-23 21:17:06Z fabien $ 9 */ 10 11 class pakeSimpletestTask 12 { 13 public static function import_default_tasks() 14 { 15 pake_desc('launch project test suite'); 16 pake_task('pakeSimpletestTask::test'); 17 } 18 19 public static function call_simpletest($task, $type = 'text', $dirs = array()) 20 { 21 // remove E_STRICT because simpletest is not E_STRICT compatible 22 $old_error_reporting = ini_get('error_reporting'); 23 if ($old_error_reporting & E_STRICT) 24 { 25 error_reporting($old_error_reporting ^ E_STRICT); 26 } 27 28 set_include_path('test'.PATH_SEPARATOR.'lib'.PATH_SEPARATOR.'classes'.PATH_SEPARATOR.get_include_path()); 29 30 include_once('simpletest/unit_tester.php'); 31 include_once('simpletest/web_tester.php'); 32 if (!class_exists('GroupTest')) 33 { 34 throw new pakeException('You must install SimpleTest to use this task.'); 35 } 36 37 require_once('simpletest/reporter.php'); 38 require_once('simpletest/mock_objects.php'); 39 40 $base_test_dir = 'test'; 41 $test_dirs = array(); 42 43 // run tests only in these subdirectories 44 if ($dirs) 45 { 46 foreach ($dirs as $dir) 47 { 48 $test_dirs[] = $base_test_dir.DIRECTORY_SEPARATOR.$dir; 49 } 50 } 51 else 52 { 53 $test_dirs[] = $base_test_dir; 54 } 55 56 $test = new GroupTest('Test suite in ('.implode(', ', $test_dirs).')'); 57 $files = pakeFinder::type('file')->name('*Test.php')->in($test_dirs); 58 foreach ($files as $file) 59 { 60 $test->addTestFile($file); 61 } 62 63 if (count($files)) 64 { 65 ob_start(); 66 if ($type == 'html') 67 { 68 $result = $test->run(new HtmlReporter()); 69 } 70 else if ($type == 'xml') 71 { 72 $result = $test->run(new XmlReporter()); 73 } 74 else 75 { 76 $result = $test->run(new TextReporter()); 77 } 78 $content = ob_get_contents(); 79 ob_end_clean(); 80 81 if ($task->is_verbose()) 82 { 83 echo $content; 84 } 85 } 86 else 87 { 88 throw new pakeException('No test to run.'); 89 } 90 91 error_reporting($old_error_reporting); 92 } 93 94 public static function run_test($task, $args) 95 { 96 $types = array('text', 'html', 'xml'); 97 $type = 'text'; 98 if (array_key_exists(0, $args) && in_array($args[0], $types)) 99 { 100 $type = $args[0]; 101 array_shift($args); 102 } 103 104 $dirs = array(); 105 if (is_array($args) && array_key_exists(0, $args)) 106 { 107 $dirs[] = $args[0]; 108 } 109 110 self::call_simpletest($task, $type, $dirs); 111 } 112 }
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Fri Mar 16 22:42:14 2007 | par Balluche grâce à PHPXref 0.7 |