Skip to content
This repository has been archived by the owner on Jan 31, 2020. It is now read-only.

Commit

Permalink
Merge branch 'hotfix/46'
Browse files Browse the repository at this point in the history
Close #46
Close #44
Fixes #35
Fixes #36
Fixes #41
Fixes #42
  • Loading branch information
weierophinney committed Jun 24, 2016
2 parents dbd504c + 220dadc commit f44101f
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 5 deletions.
6 changes: 4 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

All notable changes to this project will be documented in this file, in reverse chronological order by release.

## 2.7.2 - TBD
## 2.7.2 - 2016-06-24

### Added

Expand All @@ -18,7 +18,9 @@ All notable changes to this project will be documented in this file, in reverse

### Fixed

- Nothing.
- [#46](https://github.com/zendframework/zend-session/pull/46) provides fixes to
each of the `Cache` and `DbTaleGateway` save handlers to ensure they work
when used under PHP 7.

## 2.7.1 - 2016-05-11

Expand Down
2 changes: 1 addition & 1 deletion src/SaveHandler/Cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public function close()
*/
public function read($id)
{
return $this->getCacheStorage()->getItem($id);
return (string) $this->getCacheStorage()->getItem($id);
}

/**
Expand Down
6 changes: 5 additions & 1 deletion src/SaveHandler/DbTableGateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public function read($id)
if ($row = $rows->current()) {
if ($row->{$this->options->getModifiedColumn()} +
$row->{$this->options->getLifetimeColumn()} > time()) {
return $row->{$this->options->getDataColumn()};
return (string) $row->{$this->options->getDataColumn()};
}
$this->destroy($id);
}
Expand Down Expand Up @@ -149,6 +149,10 @@ public function write($id, $data)
*/
public function destroy($id)
{
if (! (bool) $this->read($id)) {
return true;
}

return (bool) $this->tableGateway->delete([
$this->options->getIdColumn() => $id,
$this->options->getNameColumn() => $this->sessionName,
Expand Down
13 changes: 13 additions & 0 deletions test/SaveHandler/CacheTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,4 +103,17 @@ public function testReadWriteTwice()

$this->assertEquals($this->testArray, unserialize($saveHandler->read($id)));
}

public function testReadShouldAlwaysReturnString()
{
$cacheStorage = $this->prophesize('Zend\Cache\Storage\StorageInterface');
$cacheStorage->getItem('242')->willReturn(null);
$this->usedSaveHandlers[] = $saveHandler = new Cache($cacheStorage->reveal());

$id = '242';

$data = $saveHandler->read($id);

$this->assertTrue(is_string($data));
}
}
47 changes: 46 additions & 1 deletion test/SaveHandler/DbTableGatewayTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,13 @@ class DbTableGatewayTest extends \PHPUnit_Framework_TestCase
*/
protected $usedSaveHandlers = [];

/**
* Test data container.
*
* @var array
*/
private $testArray;

/**
* Setup performed prior to each test method
*
Expand Down Expand Up @@ -123,10 +130,48 @@ public function testReadWriteTwice()
$this->assertEquals($this->testArray, unserialize($saveHandler->read($id)));
}

public function testReadShouldAlwaysReturnString()
{
$this->usedSaveHandlers[] = $saveHandler = new DbTableGateway($this->tableGateway, $this->options);
$saveHandler->open('savepath', 'sessionname');

$id = '242';

$data = $saveHandler->read($id);

$this->assertTrue(is_string($data));
}

public function testDestroyReturnsTrueEvenWhenSessionDoesNotExist()
{
$this->usedSaveHandlers[] = $saveHandler = new DbTableGateway($this->tableGateway, $this->options);
$saveHandler->open('savepath', 'sessionname');

$id = '242';

$result = $saveHandler->destroy($id);

$this->assertTrue($result);
}

public function testDestroyReturnsTrueWhenSessionIsDeleted()
{
$this->usedSaveHandlers[] = $saveHandler = new DbTableGateway($this->tableGateway, $this->options);
$saveHandler->open('savepath', 'sessionname');

$id = '242';

$this->assertTrue($saveHandler->write($id, serialize($this->testArray)));

$result = $saveHandler->destroy($id);

$this->assertTrue($result);
}

/**
* Sets up the database connection and creates the table for session data
*
* @param Zend\Session\SaveHandler\DbTableGatewayOptions $options
* @param \Zend\Session\SaveHandler\DbTableGatewayOptions $options
* @return void
*/
protected function setupDb(DbTableGatewayOptions $options)
Expand Down
12 changes: 12 additions & 0 deletions test/SaveHandler/MongoDBTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,4 +153,16 @@ public function testWriteExceptionEdgeCaseForChangedSessionName()
$saveHandler->open('savepath', 'sessionname_changed');
$saveHandler->write($id, serialize($data));
}

public function testReadShouldAlwaysReturnString()
{
$saveHandler = new MongoDB($this->mongoClient, $this->options);
$this->assertTrue($saveHandler->open('savepath', 'sessionname'));

$id = '242';

$data = $saveHandler->read($id);

$this->assertTrue(is_string($data));
}
}

0 comments on commit f44101f

Please sign in to comment.