Skip to content

Commit

Permalink
Merge pull request #14 from chadicus/master
Browse files Browse the repository at this point in the history
Add NullSerializer
  • Loading branch information
chadicus authored Sep 24, 2018
2 parents 49e1a10 + 47030a5 commit 9468360
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 0 deletions.
35 changes: 35 additions & 0 deletions src/Serializer/NullSerializer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

namespace SubjectivePHP\Psr\SimpleCache\Serializer;

use SubjectivePHP\Psr\SimpleCache\InvalidArgumentException;

/**
* Serializer implementation that does nothing with the given data.
*/
final class NullSerializer implements SerializerInterface
{
/**
* Unserializes cached data into the original state.
*
* @param mixed $data The data to unserialize.
*
* @return mixed
*/
public function unserialize($data)
{
return $data;
}

/**
* Serializes the given data for storage in caching.
*
* @param mixed $value The data to serialize for caching.
*
* @return mixed The result of serializing the given $data.
*/
public function serialize($value)
{
return $value;
}
}
51 changes: 51 additions & 0 deletions tests/Serializer/NullSerializerTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php

namespace SubjectivePHPTest\Psr\SimpleCache\Serializer;

use SubjectivePHP\Psr\SimpleCache\Serializer\NullSerializer;

/**
* @coversDefaultClass \SubjectivePHP\Psr\SimpleCache\Serializer\NullSerializer
* @covers ::<private>
*/
final class NullSerializerTest extends \PHPUnit\Framework\TestCase
{
/**
* @var NullSerializer
*/
private $serializer;

/**
* Prepare each test
*
* @return void
*/
public function setUp()
{
$this->serializer = new NullSerializer();
}

/**
* @test
* @covers ::unserialize
*
* @return void
*/
public function unserialize()
{
$data = ['foo' => 'abc', 'bar' => 123];
$this->assertSame($data, $this->serializer->unserialize($data));
}

/**
* @test
* @covers ::serialize
*
* @return void
*/
public function serialize()
{
$data = ['foo' => 'abc', 'bar' => 123];
$this->assertSame($data, $this->serializer->serialize($data));
}
}

0 comments on commit 9468360

Please sign in to comment.