Skip to content
Permalink
Browse files

The SessionHandlerInterface requires some methods to return boolean

We were returning mixed types on DatabaseSession, which made hhvm super
unhappy. This also future-proofs the class for PHP 7
  • Loading branch information...
lorenzo committed Apr 1, 2015
1 parent 236b513 commit f1d1b9902d5d06ec0bf0a137176467dba73a9f4d
Showing with 6 additions and 13 deletions.
  1. +4 −6 src/Network/Session/DatabaseSession.php
  2. +2 −7 tests/TestCase/Network/Session/DatabaseSessionTest.php
@@ -121,10 +121,7 @@ public function write($id, $data)
$record = compact('data', 'expires');
$record[$this->_table->primaryKey()] = $id;
$result = $this->_table->save(new Entity($record));
if ($result) {
return $result->toArray();
}
return false;
return (bool)$result;
}
/**
@@ -135,7 +132,7 @@ public function write($id, $data)
*/
public function destroy($id)
{
return $this->_table->delete(new Entity(
return (bool)$this->_table->delete(new Entity(
[$this->_table->primaryKey() => $id],
['markNew' => false]
));
@@ -149,6 +146,7 @@ public function destroy($id)
*/
public function gc($maxlifetime)
{
return $this->_table->deleteAll(['expires <' => time() - $maxlifetime]);
$this->_table->deleteAll(['expires <' => time() - $maxlifetime]);
return true;
}
}
@@ -97,14 +97,9 @@ public function testOpen()
public function testWrite()
{
$result = $this->storage->write('foo', 'Some value');
$expected = [
'id' => 'foo',
'data' => 'Some value',
];
$expires = $result['expires'];
unset($result['expires']);
$this->assertEquals($expected, $result);
$this->assertTrue($result);
$expires = TableRegistry::get('Sessions')->get('foo')->expires;
$expected = time() + ini_get('session.gc_maxlifetime');
$this->assertWithinRange($expected, $expires, 1);
}

0 comments on commit f1d1b99

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