Skip to content
Permalink
Browse files

Remove Cake\Error\SessionException

* With only one thrower this exception was not worth its weight.
  Replace with the base CakePHP exception.
* Update + fix tests for Cake\Model\Datasource\Session.
  • Loading branch information...
markstory committed Sep 16, 2012
1 parent 69778a0 commit 9f6dbc4a5d4582dc72124352598d0b0f96ff1a2c

This file was deleted.

Oops, something went wrong.
@@ -14,7 +14,10 @@
*/
namespace Cake\Model\Datasource;
use Cake\Core\App;
use Cake\Core\Configure;
use Cake\Model\Datasource\Session\SessionHandlerInterface;
use Cake\Error;
use Cake\Utility\Hash;
/**
@@ -435,7 +438,7 @@ public static function clear() {
* Sessions can be configured with a few shortcut names as well as have any number of ini settings declared.
*
* @return void
* @throws Cake\Error\SessionException Throws exceptions when ini_set() fails.
* @throws Cake\Error\Exception Throws exceptions when ini_set() fails.
*/
protected static function _configureSession() {
$sessionConfig = Configure::read('Session');
@@ -473,7 +476,7 @@ protected static function _configureSession() {
if (!empty($sessionConfig['ini']) && is_array($sessionConfig['ini'])) {
foreach ($sessionConfig['ini'] as $setting => $value) {
if (ini_set($setting, $value) === false) {
throw new Error\SessionException(sprintf(
throw new Error\Exception(sprintf(
__d('cake_dev', 'Unable to configure the session, setting %s failed.'),
$setting
));
@@ -504,17 +507,18 @@ protected static function _configureSession() {
*
* @param string $class
* @return void
* @throws Cake\Error\SessionException
* @throws Cake\Error\Exception
*/
protected static function _getHandler($class) {
$class = App::className($class, 'Model/Datasource/Session');
if (!class_exists($class)) {
throw new Error\SessionException(__d('cake_dev', 'Could not load %s to handle the session.', $class));
throw new Error\Exception(__d('cake_dev', 'Could not load %s to handle the session.', $class));
}
$handler = new $class();
if ($handler instanceof SessionHandlerInterface) {
return $handler;
}
throw new Error\SessionException(__d('cake_dev', 'Chosen SessionHandler does not implement SessionHandlerInterface it cannot be used with an engine key.'));
throw new Error\Exception(__d('cake_dev', 'Chosen SessionHandler does not implement SessionHandlerInterface it cannot be used with an engine key.'));
}
/**
@@ -18,6 +18,7 @@
*/
namespace Cake\Model\Datasource\Session;
use Cake\Core\Configure;
use Cake\Utility\ClassRegistry;
@@ -1,9 +1,5 @@
<?php
/**
* SessionTest file
*
* PHP 5
*
* CakePHP(tm) Tests <http://book.cakephp.org/2.0/en/development/testing.html>
* Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
*
@@ -12,16 +8,21 @@
*
* @copyright Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://book.cakephp.org/2.0/en/development/testing.html CakePHP(tm) Tests
* @package Cake.Test.Case.Model.Datasource
* @since CakePHP(tm) v 1.2.0.4206
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
namespace Cake\Test\TestCase\Model\Datasource;
App::uses('CakeSession', 'Model/Datasource');
App::uses('DatabaseSession', 'Model/Datasource/Session');
App::uses('CacheSession', 'Model/Datasource/Session');
use Cake\Cache\Cache;
use Cake\Core\App;
use Cake\Core\Configure;
use Cake\Core\Plugin;
use Cake\Model\Datasource\Session;
use Cake\Model\Datasource\Session\DatabaseSession;
use Cake\Model\Datasource\Session\CacheSession;
use Cake\TestSuite\TestCase;
class TestCakeSession extends CakeSession {
class TestCakeSession extends Session {
public static function setUserAgent($value) {
static::$_userAgent = $value;
@@ -50,11 +51,11 @@ protected function _writeSession() {
}
/**
* CakeSessionTest class
* SessionTest class
*
* @package Cake.Test.Case.Model.Datasource
*/
class CakeSessionTest extends CakeTestCase {
class SessionTest extends TestCase {
protected static $_gcDivisor;
@@ -541,6 +542,7 @@ public function testUsingAppLibsHandler() {
),
'Plugin' => array(CAKE . 'Test/TestApp/Plugin/')
), App::RESET);
Configure::write('App.namespace', 'TestApp');
Configure::write('Session', array(
'defaults' => 'cake',
'handler' => array(
@@ -562,8 +564,9 @@ public function testUsingPluginHandler() {
App::build(array(
'Plugin' => array(CAKE . 'Test/TestApp/Plugin/')
), App::RESET);
CakePlugin::load('TestPlugin');
Plugin::load('TestPlugin');
Configure::write('App.namespace', 'TestApp');
Configure::write('Session', array(
'defaults' => 'cake',
'handler' => array(
@@ -584,7 +587,7 @@ public function testUsingPluginHandler() {
*/
public function testReadAndWriteWithCacheStorage() {
Configure::write('Session.defaults', 'cache');
Configure::write('Session.handler.engine', 'TestCacheSession');
Configure::write('Session.handler.engine', __NAMESPACE__ . '\TestCacheSession');
TestCakeSession::init();
TestCakeSession::destroy();
@@ -620,13 +623,13 @@ public function testReadAndWriteWithCacheStorage() {
*/
public function testReadAndWriteWithCustomCacheConfig() {
Configure::write('Session.defaults', 'cache');
Configure::write('Session.handler.engine', 'TestCacheSession');
Configure::write('Session.handler.engine', __NAMESPACE__ . '\TestCacheSession');
Configure::write('Session.handler.config', 'session_test');
Cache::config('session_test', array(
Configure::write('Cache.session_test', [
'engine' => 'File',
'prefix' => 'session_test_',
));
]);
TestCakeSession::init();
TestCakeSession::start();
@@ -645,7 +648,7 @@ public function testReadAndWriteWithCustomCacheConfig() {
*/
public function testReadAndWriteWithDatabaseStorage() {
Configure::write('Session.defaults', 'database');
Configure::write('Session.handler.engine', 'TestDatabaseSession');
Configure::write('Session.handler.engine', __NAMESPACE__ . '\TestDatabaseSession');
Configure::write('Session.handler.table', 'sessions');
Configure::write('Session.handler.model', 'Session');
Configure::write('Session.handler.database', 'test');
@@ -706,21 +709,21 @@ public function testSessionTimeout() {
TestCakeSession::destroy();
TestCakeSession::write('Test', 'some value');
$this->assertWithinMargin(time() + $timeoutSeconds, CakeSession::$sessionTime, 1);
$this->assertWithinMargin(time() + $timeoutSeconds, Session::$sessionTime, 1);
$this->assertEquals(10, $_SESSION['Config']['countdown']);
$this->assertWithinMargin(CakeSession::$sessionTime, $_SESSION['Config']['time'], 1);
$this->assertWithinMargin(time(), CakeSession::$time, 1);
$this->assertWithinMargin(Session::$sessionTime, $_SESSION['Config']['time'], 1);
$this->assertWithinMargin(time(), Session::$time, 1);
$this->assertWithinMargin(time() + $timeoutSeconds, $_SESSION['Config']['time'], 1);
Configure::write('Session.harden', true);
TestCakeSession::destroy();
TestCakeSession::write('Test', 'some value');
$this->assertWithinMargin(time() + $timeoutSeconds, CakeSession::$sessionTime, 1);
$this->assertWithinMargin(time() + $timeoutSeconds, Session::$sessionTime, 1);
$this->assertEquals(10, $_SESSION['Config']['countdown']);
$this->assertWithinMargin(CakeSession::$sessionTime, $_SESSION['Config']['time'], 1);
$this->assertWithinMargin(time(), CakeSession::$time, 1);
$this->assertWithinMargin(CakeSession::$time + $timeoutSeconds, $_SESSION['Config']['time'], 1);
$this->assertWithinMargin(Session::$sessionTime, $_SESSION['Config']['time'], 1);
$this->assertWithinMargin(time(), Session::$time, 1);
$this->assertWithinMargin(Session::$time + $timeoutSeconds, $_SESSION['Config']['time'], 1);
}
/**

0 comments on commit 9f6dbc4

Please sign in to comment.
You can’t perform that action at this time.