-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14 from chadicus/master
Add NullSerializer
- Loading branch information
Showing
2 changed files
with
86 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} | ||
} |