Overview

Packages

  • Test

Classes

  • Horde_Test_AllTests
  • Horde_Test_Case
  • Horde_Test_Exception
  • Horde_Test_Factory_Alarm
  • Horde_Test_Factory_Cache
  • Horde_Test_Factory_Db
  • Horde_Test_Factory_Group
  • Horde_Test_Factory_History
  • Horde_Test_Factory_KolabStorage
  • Horde_Test_Factory_Perms
  • Horde_Test_Factory_Prefs
  • Horde_Test_Factory_Registry
  • Horde_Test_Factory_Session
  • Horde_Test_Factory_Share
  • Horde_Test_Functional
  • Horde_Test_Log
  • Horde_Test_Setup
  • Horde_Test_Stub_Cli
  • Horde_Test_Stub_Factory
  • Horde_Test_Stub_Parser
  • Horde_Test_Stub_Registry
  • Overview
  • Package
  • Class
  • Tree
  1: <?php
  2: /**
  3:  * Horde base test suite
  4:  *
  5:  * PHP version 5
  6:  *
  7:  * @category Horde
  8:  * @package  Test
  9:  * @author   Jan Schneider <jan@horde.org>
 10:  * @author   Gunnar Wrobel <wrobel@pardus.de>
 11:  * @license  http://www.horde.org/licenses/lgpl21 LGPL
 12:  * @link     http://www.horde.org/components/Horde_Test
 13:  */
 14: 
 15: if (!defined('PHPUnit_MAIN_METHOD')) {
 16:     define('PHPUnit_MAIN_METHOD', 'Horde_Test_AllTests::main');
 17: }
 18: 
 19: require_once 'PHPUnit/Autoload.php';
 20: 
 21: /**
 22:  * Horde base test suite
 23:  *
 24:  * Copyright 2009-2012 Horde LLC (http://www.horde.org/)
 25:  *
 26:  * See the enclosed file COPYING for license information (LGPL). If you
 27:  * did not receive this file, see http://www.horde.org/licenses/lgpl21.
 28:  *
 29:  * @category Horde
 30:  * @package  Test
 31:  * @author   Jan Schneider <jan@horde.org>
 32:  * @author   Gunnar Wrobel <wrobel@pardus.de>
 33:  * @license  http://www.horde.org/licenses/lgpl21 LGPL
 34:  * @link     http://www.horde.org/components/Horde_Test
 35:  */
 36: class Horde_Test_AllTests
 37: {
 38:     /** @todo: Use protected properties and LSB with PHP 5.3. */
 39:     private static $_file = __FILE__;
 40:     private static $_package = 'Horde_Test';
 41: 
 42:     /**
 43:      * Main entry point for running the suite.
 44:      */
 45:     public static function main($package = null, $file = null)
 46:     {
 47:         if ($package) {
 48:             self::$_package = $package;
 49:         }
 50:         if ($file) {
 51:             self::$_file = $file;
 52:         }
 53:         PHPUnit_TextUI_TestRunner::run(self::suite());
 54:     }
 55: 
 56:     /**
 57:      * Initialize the test suite class.
 58:      *
 59:      * @param string $package The name of the package tested by this suite.
 60:      * @param string $file    The path of the AllTests class.
 61:      *
 62:      * @return NULL
 63:      */
 64:     public static function init($package, $file)
 65:     {
 66:         self::$_package = $package;
 67:         self::$_file = $file;
 68:     }
 69: 
 70:     /**
 71:      * Collect the unit tests of this directory into a new suite.
 72:      *
 73:      * @return PHPUnit_Framework_TestSuite The test suite.
 74:      */
 75:     public static function suite()
 76:     {
 77:         self::setup();
 78: 
 79:         $suite = new PHPUnit_Framework_TestSuite('Horde Framework - ' . self::$_package);
 80: 
 81:         $basedir = dirname(self::$_file);
 82:         $baseregexp = preg_quote($basedir . DIRECTORY_SEPARATOR, '/');
 83: 
 84:         foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator($basedir)) as $file) {
 85:             if ($file->isFile() && preg_match('/Test.php$/', $file->getFilename())) {
 86:                 $pathname = $file->getPathname();
 87:                 if (include $pathname) {
 88:                     $class = str_replace(DIRECTORY_SEPARATOR, '_',
 89:                                          preg_replace("/^$baseregexp(.*)\.php/", '\\1', $pathname));
 90:                     try {
 91:                         $suite->addTestSuite(self::$_package . '_' . $class);
 92:                     } catch (InvalidArgumentException $e) {
 93:                         throw new Horde_Test_Exception(
 94:                             sprintf(
 95:                                 'Failed adding test suite "%s" from file "%s": %s',
 96:                                 self::$_package . '_' . $class,
 97:                                 $pathname,
 98:                                 $e->getMessage()
 99:                             )
100:                         );
101:                     }
102:                 }
103:             }
104:         }
105: 
106:         return $suite;
107:     }
108: 
109:     /**
110:      * Basic test suite setup. This includes error checking and autoloading.
111:      *
112:      * In the default situation this will set the error reporting to E_ALL |
113:      * E_STRICT and pull in Horde/Test/Autoload.php as autoloading
114:      * definition. If there is an Autoload.php alongside the AllTests.php
115:      * represented by self::$_file, then only this file will be used.
116:      *
117:      * In addition the setup() call will attempt to detect the "lib" directory
118:      * of the component currently under test and add it to the
119:      * include_path. This ensures that the component code from the checkout is
120:      * preferred over whatever else might be available in the default
121:      * include_path.
122:      *
123:      * @return NULL
124:      */
125:     public static function setup()
126:     {
127:         // Detect component root and add "lib" to the include path.
128:         for ($dirname = self::$_file, $i = 0;
129:              $dirname != '/', $i < 5;
130:              $dirname = dirname($dirname), $i++) {
131:             if (basename($dirname) == 'test' &&
132:                 file_exists(dirname($dirname) . '/lib')) {
133:                 set_include_path(
134:                     dirname($dirname) . '/lib' . PATH_SEPARATOR . get_include_path()
135:                 );
136:                 break;
137:             }
138:         }
139: 
140:         $autoload = dirname(self::$_file) . '/Autoload.php';
141:         if (!file_exists($autoload)) {
142:             // Catch strict standards
143:             error_reporting(E_ALL | E_STRICT);
144: 
145:             // Set up autoload
146:             require_once 'Horde/Test/Autoload.php';
147:         } else {
148:             require_once $autoload;
149:         }
150:     }
151: }
152: 
API documentation generated by ApiGen