public function __construct() { $test = CI_TestCase::instance(); $cls =& $test->ci_core_class('cfg'); // set predictable config values $test->ci_set_config(array('index_page' => 'index.php', 'base_url' => 'http://example.com/', 'subclass_prefix' => 'MY_')); $this->config = new $cls(); }
public function __construct() { $test = CI_TestCase::instance(); $cls =& $test->ci_core_class('cfg'); // set predictable config values $test->ci_set_config(array('index_page' => 'index.php', 'base_url' => 'http://example.com/', 'subclass_prefix' => 'MY_', 'enable_query_strings' => FALSE, 'permitted_uri_chars' => 'a-z 0-9~%.:_\\-')); $this->config = new $cls(); if ($this->config->item('enable_query_strings') !== TRUE or is_cli()) { $this->_permitted_uri_chars = $this->config->item('permitted_uri_chars'); } }
function load_class($class, $directory = 'libraries', $prefix = 'CI_') { if ($directory !== 'core' or $prefix !== 'CI_') { throw new Exception('Not Implemented: Non-core load_class()'); } $test = CI_TestCase::instance(); $obj =& $test->ci_core_class($class); if (is_string($obj)) { throw new Exception('Bad Isolation: Use ci_set_core_class to set ' . $class); } return $obj; }
/** * Initialize both database and forge components */ public static function init($driver) { if (empty(static::$db) && empty(static::$forge)) { $config = Mock_Database_DB::config($driver); $connection = new Mock_Database_DB($config); $db = Mock_Database_DB::DB($connection->set_dsn($driver), TRUE); CI_TestCase::instance()->ci_instance_var('db', $db); $loader = new CI_Loader(); $loader->dbforge(); $forge = CI_TestCase::instance()->ci_instance_var('dbforge'); static::$db = $db; static::$forge = $forge; static::$driver = $driver; } return static::$db; }
/** * Initialize both database and forge components */ public static function init($driver) { if (empty(self::$db) && empty(self::$forge)) { // E_DEPRECATED notices thrown by mysql_connect(), mysql_pconnect() // on PHP 5.5+ cause the tests to fail if ($driver === 'mysql' && version_compare(PHP_VERSION, '5.5', '>=')) { error_reporting(E_ALL & ~E_DEPRECATED); } $config = Mock_Database_DB::config($driver); $connection = new Mock_Database_DB($config); $db = Mock_Database_DB::DB($connection->set_dsn($driver), TRUE); CI_TestCase::instance()->ci_instance_var('db', $db); $loader = new CI_Loader(); $loader->dbforge(); $forge = CI_TestCase::instance()->ci_instance_var('dbforge'); self::$db = $db; self::$forge = $forge; self::$driver = $driver; } return self::$db; }
/** * Main DB method wrapper * * @param string Group or DSN string * @param bool * @return object */ public static function DB($group, $query_builder = FALSE) { // Create dummy driver and builder files to "load" - the mocks have // already triggered autoloading of the real files $case = CI_TestCase::instance(); $driver = self::$dbdriver; $subdriver = self::$subdriver; $case->ci_vfs_create(array('DB_driver.php' => '', 'DB_result.php' => '', 'DB_forge.php' => '', 'DB_query_builder.php' => ''), '', $case->ci_base_root, 'database'); if (file_exists(SYSTEM_PATH . 'database/drivers/' . $driver . '/' . $driver . '_driver.php')) { $case->ci_vfs_create(array($driver . '_driver.php' => '', $driver . '_result.php' => '', $driver . '_forge.php' => ''), '', $case->ci_base_root, 'database/drivers/' . $driver); } if ($subdriver) { $case->ci_vfs_create(array($driver . '_' . $subdriver . '_driver.php' => '', $driver . '_' . $subdriver . '_forge.php' => ''), '', $case->ci_base_root, 'database/drivers/' . $driver . '/subdrivers'); } include_once SYSTEM_PATH . 'database/DB.php'; try { $db = DB($group, $query_builder); } catch (Exception $e) { throw new RuntimeException($e->getMessage()); } return $db; }
/** * 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(); }
function &get_config() { $test = CI_TestCase::instance(); $config = $test->ci_get_config(); return $config; }
function setUp() { parent::setUp(); // you'll want to add class members here. You can access the CI instance // object using $this->CI. You can test models, libraries, or helpers here. }