Skip to content
This repository was archived by the owner on Jan 31, 2020. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
2 changes: 1 addition & 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
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';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be no quote?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, the session handler interface defines strings (session id).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, but the tests is not proving the (string) cast then, as 242 must be string, and 242 is not string.

Copy link
Contributor Author

@zluiten zluiten Jun 20, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Casting is not necessary. It is a string because of the quotes (is_string('242') === true). The contents of the string is not of importance here.


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

$this->assertTrue(is_string($data));
}
}
12 changes: 12 additions & 0 deletions test/SaveHandler/DbTableGatewayTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,18 @@ 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));
}

/**
* Sets up the database connection and creates the table for session data
*
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));
}
}