home *** CD-ROM | disk | FTP | other *** search
/ Enter 2004 June / ENTER.ISO / files / xampp-win32-1.4.5-installer.exe / xampp / clitest.php < prev    next >
Encoding:
PHP Script  |  2004-03-24  |  5.6 KB  |  141 lines

  1.  
  2. <?php
  3. // +----------------------------------------------------------------------+
  4. // | PHP Version 4                                                        |
  5. // +----------------------------------------------------------------------+
  6. // | Copyright (c) 1998-2004 Manuel Lemos, Paul Cooper                    |
  7. // | All rights reserved.                                                 |
  8. // +----------------------------------------------------------------------+
  9. // | MDB is a merge of PEAR DB and Metabases that provides a unified DB   |
  10. // | API as well as database abstraction for PHP applications.            |
  11. // | This LICENSE is in the BSD license style.                            |
  12. // |                                                                      |
  13. // | Redistribution and use in source and binary forms, with or without   |
  14. // | modification, are permitted provided that the following conditions   |
  15. // | are met:                                                             |
  16. // |                                                                      |
  17. // | Redistributions of source code must retain the above copyright       |
  18. // | notice, this list of conditions and the following disclaimer.        |
  19. // |                                                                      |
  20. // | Redistributions in binary form must reproduce the above copyright    |
  21. // | notice, this list of conditions and the following disclaimer in the  |
  22. // | documentation and/or other materials provided with the distribution. |
  23. // |                                                                      |
  24. // | Neither the name of Manuel Lemos, Tomas V.V.Cox, Stig. S. Bakken,    |
  25. // | Lukas Smith nor the names of his contributors may be used to endorse |
  26. // | or promote products derived from this software without specific prior|
  27. // | written permission.                                                  |
  28. // |                                                                      |
  29. // | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS  |
  30. // | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT    |
  31. // | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS    |
  32. // | FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE      |
  33. // | REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,          |
  34. // | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
  35. // | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS|
  36. // |  OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED  |
  37. // | AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT          |
  38. // | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY|
  39. // | WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE          |
  40. // | POSSIBILITY OF SUCH DAMAGE.                                          |
  41. // +----------------------------------------------------------------------+
  42. // | Author: Paul Cooper <pgc@ucecom.com>                                 |
  43. // +----------------------------------------------------------------------+
  44. //
  45. // $Id: clitest.php,v 1.8.4.3 2004/01/08 13:43:00 lsmith Exp $
  46.  
  47. /*
  48.  This is a small test suite for MDB using PHPUnit
  49.  
  50.  This is the command line version and should be used like so;
  51.  
  52.  php -q clitest.php
  53.  
  54.  This will run through all tests in all testcases (as defined in
  55.  test_setup.php). To run individual tests add their names to the command
  56.  line and all testcases will be searched for matching test names, e.g.
  57.  
  58.  php -q clitest.php teststorage testreplace
  59. */
  60.  
  61. // BC hack to define PATH_SEPARATOR for version of PHP prior 4.3
  62. if(!defined('PATH_SEPARATOR')) {
  63.     if(defined('DIRECTORY_SEPARATOR') && DIRECTORY_SEPARATOR == "\\") {
  64.         define('PATH_SEPARATOR', ';');
  65.     } else {
  66.         define('PATH_SEPARATOR', ':');
  67.     }
  68. }
  69. ini_set('include_path', '..'.PATH_SEPARATOR.ini_get('include_path'));
  70.  
  71. require_once('PHPUnit.php');
  72. require_once('test_setup.php');
  73. require_once('testUtils.php');
  74. require_once('MDB.php');
  75. require_once('Console_TestListener.php');
  76.  
  77. MDB::loadFile('Manager');
  78. MDB::loadFile('Date');
  79.  
  80. PEAR::setErrorHandling(PEAR_ERROR_CALLBACK, 'handle_pear_error');
  81. function handle_pear_error ($error_obj)
  82. {
  83.     print '<pre><b>PEAR-Error</b><br />';
  84.     echo $error_obj->getMessage().': '.$error_obj->getUserinfo();
  85.     print '</pre>';
  86. }
  87.  
  88. foreach ($testcases as $testcase) {
  89.     include_once($testcase.'.php');
  90. }
  91.  
  92. $database = 'driver_test';
  93.  
  94. $inputMethods = $argv;
  95. array_shift($inputMethods);
  96.  
  97. $testmethods = NULL;
  98.  
  99. if ($argc > 1) {
  100.     foreach ($testcases as $testcase) {
  101.         $possibleMethods = getTests($testcase);
  102.         $intersect = array_intersect($possibleMethods, $inputMethods);
  103.         if (count($intersect) > 0) {
  104.             $testmethods[$testcase] = array_flip($intersect);
  105.         }
  106.     }
  107. }
  108.  
  109. if (!is_array($testmethods)) {
  110.     foreach ($testcases as $testcase) {
  111.         $testmethods[$testcase] = array_flip(getTests($testcase));
  112.     }
  113. }
  114.  
  115. foreach ($dbarray as $db) {
  116.     $dsn = $db['dsn'];
  117.     $options = $db['options'];
  118.  
  119.     $display_dsn = $dsn['phptype'] . "://" . $dsn['username'] . ":" . $dsn['password'] . "@" . $dsn['hostspec'] . "/" . $database;
  120.     echo "=== Start test of $display_dsn ===\n";
  121.  
  122.     $suite = new PHPUnit_TestSuite();
  123.  
  124.     foreach ($testcases as $testcase) {
  125.         if (is_array($testmethods[$testcase])) {
  126.             $methods = array_keys($testmethods[$testcase]);
  127.             foreach ($methods as $method) {
  128.                 $suite->addTest(new $testcase($method));
  129.             }
  130.         }
  131.     }
  132.  
  133.     $result = new PHPUnit_TestResult;
  134.     $result->addListener(new Console_TestListener);
  135.  
  136.     $suite->run($result);
  137.  
  138.     echo "=== End test of $display_dsn ===\n\n";
  139. }
  140.  
  141. ?>