<?php

/**
 * This class bootstraps the CoreTest_ system (setups up autoload etc)
 */
class CoreTest_Bootstrap
{
    
/**
     * Singleton to determine if bootstrap has already been initalized
     *  This will ensure we don't keep doing the same work multiple times
     *
     * @var bool
     */
    
protected static $initialized false;

    
/**
     * Wrapper method for bootstrapping CoreLib
     */
    
public static function run()
    {
        if (!
self::$initialized) {

            
$bootstrap = new CoreTest_Bootstrap();

            
$bootstrap->initIncludePaths();
            
$bootstrap->initAutoload();

            
self::$initialized true;
        }
    }

    
/**
     * Wrapper method for registering autoloaders
     */
    
protected function initAutoload()
    {
        require_once 
'PHPUnitAutoload.php';

        
// Register our custom autoloader
        
PHPUnitAutoload::register();
    }


   
/**
    * Wrapper method for initializing include paths
    */
    
protected function initIncludePaths()
    {
        
$includePath    '.';
        
$rootTestDir    $includePath DIRECTORY_SEPARATOR 'test';

        
// Dirs that must be avail
        
$requiredDirs = array(
            
$rootTestDir,
            
$includePath DIRECTORY_SEPARATOR 'lib' // Needed so PHPUnit can require files internally
        
);

        foreach (
$requiredDirs as $requiredDir) {
            
$includePath .= ':' $requiredDir;
        }

        
// Using set_include_path, otherwise it will overwrite vs append
        
if (!set_include_path(get_include_path() . $includePath)) {
            throw new 
Exception('Unable to set include path (' $includePath ')');
        }
    }
}

CoreTest_Bootstrap::run();