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

Commit f44101f

Browse files
committed
Merge branch 'hotfix/46'
Close #46 Close #44 Fixes #35 Fixes #36 Fixes #41 Fixes #42
2 parents dbd504c + 220dadc commit f44101f

File tree

6 files changed

+81
-5
lines changed

6 files changed

+81
-5
lines changed

CHANGELOG.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

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

5-
## 2.7.2 - TBD
5+
## 2.7.2 - 2016-06-24
66

77
### Added
88

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

1919
### Fixed
2020

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

2325
## 2.7.1 - 2016-05-11
2426

src/SaveHandler/Cache.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public function close()
8181
*/
8282
public function read($id)
8383
{
84-
return $this->getCacheStorage()->getItem($id);
84+
return (string) $this->getCacheStorage()->getItem($id);
8585
}
8686

8787
/**

src/SaveHandler/DbTableGateway.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ public function read($id)
102102
if ($row = $rows->current()) {
103103
if ($row->{$this->options->getModifiedColumn()} +
104104
$row->{$this->options->getLifetimeColumn()} > time()) {
105-
return $row->{$this->options->getDataColumn()};
105+
return (string) $row->{$this->options->getDataColumn()};
106106
}
107107
$this->destroy($id);
108108
}
@@ -149,6 +149,10 @@ public function write($id, $data)
149149
*/
150150
public function destroy($id)
151151
{
152+
if (! (bool) $this->read($id)) {
153+
return true;
154+
}
155+
152156
return (bool) $this->tableGateway->delete([
153157
$this->options->getIdColumn() => $id,
154158
$this->options->getNameColumn() => $this->sessionName,

test/SaveHandler/CacheTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,4 +103,17 @@ public function testReadWriteTwice()
103103

104104
$this->assertEquals($this->testArray, unserialize($saveHandler->read($id)));
105105
}
106+
107+
public function testReadShouldAlwaysReturnString()
108+
{
109+
$cacheStorage = $this->prophesize('Zend\Cache\Storage\StorageInterface');
110+
$cacheStorage->getItem('242')->willReturn(null);
111+
$this->usedSaveHandlers[] = $saveHandler = new Cache($cacheStorage->reveal());
112+
113+
$id = '242';
114+
115+
$data = $saveHandler->read($id);
116+
117+
$this->assertTrue(is_string($data));
118+
}
106119
}

test/SaveHandler/DbTableGatewayTest.php

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,13 @@ class DbTableGatewayTest extends \PHPUnit_Framework_TestCase
4747
*/
4848
protected $usedSaveHandlers = [];
4949

50+
/**
51+
* Test data container.
52+
*
53+
* @var array
54+
*/
55+
private $testArray;
56+
5057
/**
5158
* Setup performed prior to each test method
5259
*
@@ -123,10 +130,48 @@ public function testReadWriteTwice()
123130
$this->assertEquals($this->testArray, unserialize($saveHandler->read($id)));
124131
}
125132

133+
public function testReadShouldAlwaysReturnString()
134+
{
135+
$this->usedSaveHandlers[] = $saveHandler = new DbTableGateway($this->tableGateway, $this->options);
136+
$saveHandler->open('savepath', 'sessionname');
137+
138+
$id = '242';
139+
140+
$data = $saveHandler->read($id);
141+
142+
$this->assertTrue(is_string($data));
143+
}
144+
145+
public function testDestroyReturnsTrueEvenWhenSessionDoesNotExist()
146+
{
147+
$this->usedSaveHandlers[] = $saveHandler = new DbTableGateway($this->tableGateway, $this->options);
148+
$saveHandler->open('savepath', 'sessionname');
149+
150+
$id = '242';
151+
152+
$result = $saveHandler->destroy($id);
153+
154+
$this->assertTrue($result);
155+
}
156+
157+
public function testDestroyReturnsTrueWhenSessionIsDeleted()
158+
{
159+
$this->usedSaveHandlers[] = $saveHandler = new DbTableGateway($this->tableGateway, $this->options);
160+
$saveHandler->open('savepath', 'sessionname');
161+
162+
$id = '242';
163+
164+
$this->assertTrue($saveHandler->write($id, serialize($this->testArray)));
165+
166+
$result = $saveHandler->destroy($id);
167+
168+
$this->assertTrue($result);
169+
}
170+
126171
/**
127172
* Sets up the database connection and creates the table for session data
128173
*
129-
* @param Zend\Session\SaveHandler\DbTableGatewayOptions $options
174+
* @param \Zend\Session\SaveHandler\DbTableGatewayOptions $options
130175
* @return void
131176
*/
132177
protected function setupDb(DbTableGatewayOptions $options)

test/SaveHandler/MongoDBTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,4 +153,16 @@ public function testWriteExceptionEdgeCaseForChangedSessionName()
153153
$saveHandler->open('savepath', 'sessionname_changed');
154154
$saveHandler->write($id, serialize($data));
155155
}
156+
157+
public function testReadShouldAlwaysReturnString()
158+
{
159+
$saveHandler = new MongoDB($this->mongoClient, $this->options);
160+
$this->assertTrue($saveHandler->open('savepath', 'sessionname'));
161+
162+
$id = '242';
163+
164+
$data = $saveHandler->read($id);
165+
166+
$this->assertTrue(is_string($data));
167+
}
156168
}

0 commit comments

Comments
 (0)