Skip to content

Commit

Permalink
Make sure all handlers return boolean as required, and test this.
Browse files Browse the repository at this point in the history
  • Loading branch information
yunosh committed Dec 14, 2015
1 parent f1239b0 commit 5bce18a
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 20 deletions.
Expand Up @@ -45,14 +45,14 @@ public function __construct(array $params = array())
*/
public function open($save_path = null, $session_name = null)
{
call_user_func($this->_params['open'], $save_path, $session_name);
return call_user_func($this->_params['open'], $save_path, $session_name);
}

/**
*/
public function close()
{
call_user_func($this->_params['close']);
return call_user_func($this->_params['close']);
}

/**
Expand Down
Expand Up @@ -56,6 +56,7 @@ public function __construct(array $params = array())
*/
public function open($save_path = null, $session_name = null)
{
return true;
}

/**
Expand Down Expand Up @@ -97,7 +98,7 @@ public function read($id)
$this->_open($id);

if (!$this->_fp) {
return '';
return false;
}

$data = '';
Expand Down
Expand Up @@ -83,6 +83,7 @@ public function __construct(array $params = array())
*/
public function open($save_path = null, $session_name = null)
{
return true;
}

/**
Expand All @@ -92,6 +93,7 @@ public function close()
if (isset($this->_id)) {
$this->_memcache->unlock($this->_id);
}
return true;
}

/**
Expand Down
Expand Up @@ -65,6 +65,7 @@ public function __construct(array $params = array())
*/
public function open($save_path = null, $session_name = null)
{
return true;
}

/**
Expand Down
Expand Up @@ -53,17 +53,23 @@ public function __construct(array $params = array())
public function open($save_path = null, $session_name = null)
{
foreach ($this->_stack as $val) {
$val->open($save_path, $session_name);
if (!$val->open($save_path, $session_name)) {
return false;
}
}
return true;
}

/**
*/
public function close()
{
foreach ($this->_stack as $val) {
$val->close();
if (!$val->close()) {
return false;
}
}
return true;
}

/**
Expand Down
30 changes: 15 additions & 15 deletions framework/SessionHandler/test/Horde/SessionHandler/Storage/Base.php
Expand Up @@ -13,9 +13,9 @@ class Horde_SessionHandler_Storage_Base extends Horde_Test_Case

protected function _write()
{
self::$handler->open(self::$dir, 'sessionname');
$this->assertTrue(self::$handler->open(self::$dir, 'sessionname'));
$this->assertSame('', self::$handler->read('sessionid'));
self::$handler->write('sessionid', 'sessiondata');
$this->assertTrue(self::$handler->write('sessionid', 'sessiondata'));
}

protected function _read()
Expand All @@ -25,45 +25,45 @@ protected function _read()

protected function _reopen()
{
self::$handler->close();
self::$handler->open(self::$dir, 'sessionname');
$this->assertTrue(self::$handler->close());
$this->assertTrue(self::$handler->open(self::$dir, 'sessionname'));
$this->assertEquals('sessiondata', self::$handler->read('sessionid'));
self::$handler->close();
$this->assertTrue(self::$handler->close());
}

protected function _list()
{
self::$handler->close();
self::$handler->open(self::$dir, 'sessionname');
$this->assertTrue(self::$handler->close());
$this->assertTrue(self::$handler->open(self::$dir, 'sessionname'));
self::$handler->read('sessionid2');
self::$handler->write('sessionid2', 'sessiondata2');
$this->assertTrue(self::$handler->write('sessionid2', 'sessiondata2'));
/* List while session is active. */
$ids = self::$handler->getSessionIDs();
sort($ids);
$this->assertEquals(array('sessionid', 'sessionid2'), $ids);
self::$handler->close();
$this->assertTrue(self::$handler->close());

/* List while session is inactive. */
self::$handler->open(self::$dir, 'sessionname');
$this->assertTrue(self::$handler->open(self::$dir, 'sessionname'));
$ids = self::$handler->getSessionIDs();
sort($ids);
$this->assertEquals(array('sessionid', 'sessionid2'), $ids);
self::$handler->close();
$this->assertTrue(self::$handler->close());
}

protected function _destroy()
{
self::$handler->open(self::$dir, 'sessionname');
$this->assertTrue(self::$handler->open(self::$dir, 'sessionname'));
self::$handler->read('sessionid2');
self::$handler->destroy('sessionid2');
$this->assertTrue(self::$handler->destroy('sessionid2'));
$this->assertEquals(array('sessionid'),
self::$handler->getSessionIDs());
}

protected function _gc()
{
self::$handler->open(self::$dir, 'sessionname');
self::$handler->gc(-1);
$this->assertTrue(self::$handler->open(self::$dir, 'sessionname'));
$this->assertTrue(self::$handler->gc(-1));
$this->assertEquals(array(),
self::$handler->getSessionIDs());
}
Expand Down

0 comments on commit 5bce18a

Please sign in to comment.