Skip to content

Commit

Permalink
Merge branch 'session-php-serialize'
Browse files Browse the repository at this point in the history
  • Loading branch information
cboden committed May 25, 2016
2 parents a177819 + f5e8a18 commit b3b10e3
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/Ratchet/Session/Serialize/PhpHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,21 @@

class PhpHandler implements HandlerInterface {
/**
* Simply reverse behaviour of unserialize method.
* {@inheritdoc}
*/
function serialize(array $data) {
throw new \RuntimeException("Serialize PhpHandler:serialize code not written yet, write me!");
$preSerialized = array();
$serialized = '';

if (count($data)) {
foreach ($data as $bucket => $bucketData) {
$preSerialized[] = $bucket . '|' . serialize($bucketData);
}
$serialized = implode('', $preSerialized);
}

return $serialized;
}

/**
Expand Down
7 changes: 7 additions & 0 deletions tests/unit/Session/Serialize/PhpHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,11 @@ public function serializedProvider() {
public function testUnserialize($in, $expected) {
$this->assertEquals($expected, $this->_handler->unserialize($in));
}

/**
* @dataProvider serializedProvider
*/
public function testSerialize($serialized, $original) {
$this->assertEquals($serialized, $this->_handler->serialize($original));
}
}

0 comments on commit b3b10e3

Please sign in to comment.