Skip to content

Commit

Permalink
The SessionHandlerInterface requires some methods to return boolean
Browse files Browse the repository at this point in the history
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 f1d1b99
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 13 deletions.
10 changes: 4 additions & 6 deletions src/Network/Session/DatabaseSession.php
Expand Up @@ -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;
}

/**
Expand All @@ -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]
));
Expand All @@ -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;
}
}
9 changes: 2 additions & 7 deletions tests/TestCase/Network/Session/DatabaseSessionTest.php
Expand Up @@ -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);
}
Expand Down

0 comments on commit f1d1b99

Please sign in to comment.