<?php


// Need a way to change dependencies (core libs and laoded libs)
// Need a way to set the CI class

class CI_TestCase extends PHPUnit_Framework_TestCase {
	
	protected $ci_config;
	protected $ci_instance;
	protected static $ci_test_instance;
		
	private $global_map = array(
		'benchmark'	=> 'bm',
		'config'	=> 'cfg',
		'hooks'		=> 'ext',
		'utf8'		=> 'uni',
		'router'	=> 'rtr',
		'output'	=> 'out',
		'security'	=> 'sec',
		'input'		=> 'in',
		'lang'		=> 'lang',
		// @todo the loader is an edge case
		'loader'	=> 'load',
		'model'		=> 'model'
	);
	
	// --------------------------------------------------------------------
	
	public function __construct()
	{
		parent::__construct();
		
		$this->ci_config = array();
	}
	
	// --------------------------------------------------------------------
	
	public function setUp()
	{
		if (method_exists($this, 'set_up'))
		{
			$this->set_up();
		}
	}
	
	// --------------------------------------------------------------------
	
	public function tearDown() 
	{
		if (method_exists($this, 'tear_down'))
		{
			$this->tear_down();
		}
	}
	
	// --------------------------------------------------------------------
	
	function ci_set_config($key, $val = '')
	{
		if (is_array($key))
		{
			$this->ci_config = $key;
		}
		else
		{
			$this->ci_config[$key] = $val;
		}
	}
	
	// --------------------------------------------------------------------
	
	function ci_instance($obj = FALSE)
	{
		if ( ! is_object($obj))
		{
			return $this->ci_instance;
		}
		
		$this->ci_instance = $obj;
	}
	
	// --------------------------------------------------------------------
	
	function ci_instance_var($name, $obj = FALSE)
	{
		if ( ! is_object($obj))
		{
			return $this->ci_instance->$name;
		}
		
		$this->ci_instance->$name =& $obj;
	}
	
	// --------------------------------------------------------------------

	/**
	 * Grab a core class
	 *
	 * Loads the correct core class without extensions
	 * and returns a reference to the class name in the
	 * globals array with the correct key. This way the
	 * test can modify the variable it assigns to and
	 * still maintain the global.
	 */
	function &ci_core_class($name)
	{
		$name = strtolower($name);
		
		if (isset($this->global_map[$name]))
		{
			$class_name = ucfirst($name);
			$global_name = $this->global_map[$name];
		}
		elseif (in_array($name, $this->global_map))
		{
			$class_name = ucfirst(array_search($name, $this->global_map));
			$global_name = $name;
		}
		else
		{
			throw new Exception('Not a valid core class.');
		}
		
		if ( ! class_exists('CI_'.$class_name))
		{
			require_once BASEPATH.'core/'.$class_name.'.php';
		}
		
		$GLOBALS[strtoupper($global_name)] = 'CI_'.$class_name;
		return $GLOBALS[strtoupper($global_name)];
	}
	
	// --------------------------------------------------------------------
	
	// convenience function for global mocks
	function ci_set_core_class($name, $obj)
	{
		$orig =& $this->ci_core_class($name);
		$orig = $obj;
	}
	
	// --------------------------------------------------------------------
	// Internals
	// --------------------------------------------------------------------
	
	/**
	 * Overwrite runBare
	 *
	 * PHPUnit instantiates the test classes before
	 * running them individually. So right before a test
	 * runs we set our instance. Normally this step would
	 * happen in setUp, but someone is bound to forget to
	 * call the parent method and debugging this is no fun.
	 */
	public function runBare()
	{
		self::$ci_test_instance = $this;
		parent::runBare();
	}
	
	// --------------------------------------------------------------------
	
	public static function instance()
	{
		return self::$ci_test_instance;
	}
	
	// --------------------------------------------------------------------
	
	function ci_get_config()
	{
		return $this->ci_config;
	}

	// --------------------------------------------------------------------
	
	/**
	 * This overload is useful to create a stub, that need to have a specific method.
	 */
	function __call($method, $args)
	{
		if ($this->{$method} instanceof Closure) 
		{
			return call_user_func_array($this->{$method},$args);
		} 
		else 
		{
			return parent::__call($method, $args);
		}
	}
}

// EOF