Skip to content

Instantly share code, notes, and snippets.

@withremote
Created January 8, 2015 15:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save withremote/7b7c8fed47f39524c0ba to your computer and use it in GitHub Desktop.
Save withremote/7b7c8fed47f39524c0ba to your computer and use it in GitHub Desktop.
Session library override if running tests
<?php
class MY_Session extends CI_Session {
protected $cliTestingDriver = 'codeception';
public function __construct(array $params = array())
{
parent::__construct($params);
/** alow for sessions ot be saved if in CLI mode and running tests */
if (is_cli() && defined('CODECEPTION_TEST')) {
$this->valid_drivers = array_merge($this->valid_drivers, array($this->cliTestingDriver));
// Save a copy of parameters in case drivers need access
$this->params = $params;
// Load driver and get array reference
$this->load_driver($this->cliTestingDriver);
// Delete 'old' flashdata (from last request)
$this->_flashdata_sweep();
// Mark all new flashdata as old (data will be deleted before next request)
$this->_flashdata_mark();
// Delete expired tempdata
$this->_tempdata_sweep();
log_message('debug', 'MY_Session routines successfully run with Testing driver "'.$this->cliTestingDriver.'"');
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment