Skip to content

Instantly share code, notes, and snippets.

@Maks3w
Last active March 16, 2017 06:39
Show Gist options
  • Save Maks3w/4273aadc970e8b2d3a90 to your computer and use it in GitHub Desktop.
Save Maks3w/4273aadc970e8b2d3a90 to your computer and use it in GitHub Desktop.
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
namespace ZendTest\Serializer\Adapter;
use Zend\Json\Encoder;
use Zend\Serializer;
use ZendTest\Serializer\TestAsset\Dummy;
/**
* @covers Zend\Serializer\Adapter\PhpCode
*/
class PhpCodeTest extends \PHPUnit_Framework_TestCase
{
/** @var Serializer\Adapter\PhpCode */
private $adapter;
public function setUp()
{
$this->adapter = new Serializer\Adapter\PhpCode();
}
/**
* @dataProvider serializedValuesProvider
*/
public function testSerialize($unserialized, $serialized)
{
$this->assertEquals($serializeValue, $this->adapter->serialize($unserialized));
}
/**
* @dataProvider serializedValuesProvider
*/
public function testUnserialize($unserialized, $serialized)
{
$this->assertEquals($unserializeValue, $this->adapter->unserialize($serialized));
}
public function serializedValuesProvider()
{
return [
// Description => [unserialized, serialized]
'String' => ['test', serialize('test')],
'true' => [true, serialize(true)],
'false' => [false, serialize(false)],
'null' => [null, serialize(null)],
'int' => [1, serialize(1)],
'float' => [1.2, serialize(1.2)],
// Boolean as string
'"true"' => ['true', serialize('true')],
'"false"' => ['false', serialize('false')],
'"null"' => ['null', serialize('null')],
'"1"' => ['1', serialize('1')],
'"1.2"' => ['1.2', serialize('1.2')],
'PHP Code with tags' => ['<?php echo "test"; ?>', serialize('<?php echo "test"; ?>')],
];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment