Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add PhpSerializeHandler for "php_serialize" handler #580

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
18 changes: 18 additions & 0 deletions src/Ratchet/Session/Serialize/PhpSerializeHandler.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php
namespace Ratchet\Session\Serialize;

class PhpSerializeHandler implements HandlerInterface {
/**
* {@inheritdoc}
*/
public function serialize(array $data) {
return serialize($data);
}

/**
* {@inheritdoc}
*/
public function unserialize($raw) {
return unserialize($raw);
}
}
13 changes: 7 additions & 6 deletions tests/unit/Session/Serialize/PhpHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* @covers Ratchet\Session\Serialize\PhpHandler
*/
class PhpHandlerTest extends \PHPUnit_Framework_TestCase {
/** @var PhpHandler */
protected $_handler;

public function setUp() {
Expand All @@ -15,13 +16,13 @@ public function setUp() {
public function serializedProvider() {
return array(
array(
'_sf2_attributes|a:2:{s:5:"hello";s:5:"world";s:4:"last";i:1332872102;}_sf2_flashes|a:0:{}'
, array(
'_sf2_attributes|a:2:{s:5:"hello";s:5:"world";s:4:"last";i:1332872102;}_sf2_flashes|a:0:{}',
array(
'_sf2_attributes' => array(
'hello' => 'world'
, 'last' => 1332872102
)
, '_sf2_flashes' => array()
'hello' => 'world',
'last' => 1332872102
),
'_sf2_flashes' => array()
)
)
);
Expand Down
44 changes: 44 additions & 0 deletions tests/unit/Session/Serialize/PhpSerializeHandlerTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php
namespace Ratchet\Session\Serialize;
use Ratchet\Session\Serialize\PhpSerializeHandler;

/**
* @covers Ratchet\Session\Serialize\PhpSerializeHandler
*/
class PhpSerializeHandlerTest extends \PHPUnit_Framework_TestCase {
/** @var PhpSerializeHandler */
protected $_handler;

public function setUp() {
$this->_handler = new PhpSerializeHandler;
}

public function serializedProvider() {
return array(
array(
'a:2:{s:15:"_sf2_attributes";a:2:{s:5:"hello";s:5:"world";s:4:"last";i:1332872102;}s:12:"_sf2_flashes";a:0:{}}',
array(
'_sf2_attributes' => array(
'hello' => 'world',
'last' => 1332872102
),
'_sf2_flashes' => array()
)
)
);
}

/**
* @dataProvider 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));
}
}