Browse Source

Fixed DatabaseSession unit test

Jose Lorenzo Rodriguez 12 years ago
parent
commit
3f2ed4e31a

+ 1 - 1
src/Network/Session.php

@@ -67,7 +67,7 @@ class Session {
  * - cache: Use the CakePHP caching system as an storage for the session, you will need
  *   to pass the `config` key with the name of an already configured Cache engine.
  * - database: Use the CakePHP ORM to persist and manage sessions. By default this requires
- *   a table in your database named `cake_sessions` or a `model` key in the configuration
+ *   a table in your database named `sessions` or a `model` key in the configuration
  *   to indicate which Table object to use.
  * - cake: Use files for storing the sessions, but let CakePHP manage them and decide
  *   where to store them.

+ 4 - 6
src/Network/Session/DatabaseSession.php

@@ -48,14 +48,12 @@ class DatabaseSession implements SessionHandlerInterface {
  * @param array $config The configuration for this engine. It requires the 'model'
  * key to be present corresponding to the Table to use for managing the sessions.
  */
-	public function __construct(array $config) {
-		$modelAlias = $config['model'];
-
-		if (empty($modelAlias)) {
-			$config = TableRegistry::exists('Sessions') ? [] : ['table' => 'cake_sessions'];
+	public function __construct(array $config = []) {
+		if (empty($config['model'])) {
+			$config = TableRegistry::exists('Sessions') ? [] : ['table' => 'sessions'];
 			$this->_table = TableRegistry::get('Sessions', $config);
 		} else {
-			$this->_table = TableRegistry::get($modelAlias);
+			$this->_table = TableRegistry::get($config['model']);
 		}
 
 		$this->_timeout = ini_get('session.gc_maxlifetime');

+ 3 - 32
tests/TestCase/Network/Session/DatabaseSessionTest.php

@@ -31,13 +31,6 @@ use Cake\TestSuite\TestCase;
 class DatabaseSessionTest extends TestCase {
 
 /**
- * sessionBackup
- *
- * @var array
- */
-	protected static $_sessionBackup;
-
-/**
  * fixtures
  *
  * @var string
@@ -45,29 +38,6 @@ class DatabaseSessionTest extends TestCase {
 	public $fixtures = ['core.session'];
 
 /**
- * test case startup
- *
- * @return void
- */
-	public static function setupBeforeClass() {
-		static::$_sessionBackup = Configure::read('Session');
-
-		Configure::write('Session.handler', array(
-			'model' => 'Sessions'
-		));
-		Configure::write('Session.timeout', 100);
-	}
-
-/**
- * cleanup after test case.
- *
- * @return void
- */
-	public static function teardownAfterClass() {
-		Configure::write('Session', static::$_sessionBackup);
-	}
-
-/**
  * setUp
  *
  * @return void
@@ -129,7 +99,7 @@ class DatabaseSessionTest extends TestCase {
 		unset($result['expires']);
 		$this->assertEquals($expected, $result);
 
-		$expected = time() + (Configure::read('Session.timeout') * 60);
+		$expected = time() + ini_get('session.gc_maxlifetime');
 		$this->assertWithinMargin($expires, $expected, 1);
 	}
 
@@ -178,8 +148,8 @@ class DatabaseSessionTest extends TestCase {
  */
 	public function testGc() {
 		TableRegistry::clear();
-		Configure::write('Session.timeout', 0);
 
+		ini_set('session.gc_maxlifetime', 0);
 		$storage = new DatabaseSession();
 		$storage->write('foo', 'Some value');
 
@@ -187,4 +157,5 @@ class DatabaseSessionTest extends TestCase {
 		$storage->gc(0);
 		$this->assertFalse($storage->read('foo'));
 	}
+
 }