-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
136 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,46 @@ | ||
<?php | ||
|
||
|
||
namespace Retrinko\Serializer\Test\Unit; | ||
|
||
|
||
use Retrinko\Serializer\SerializerFactory; | ||
use Retrinko\Serializer\Serializers\JsonSerializer; | ||
use Retrinko\Serializer\Serializers\NullSerializer; | ||
use Retrinko\Serializer\Serializers\PhpSerializer; | ||
|
||
class SerializerFactoryTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
public function supportedContentTypesProvider() | ||
{ | ||
return [ | ||
[PhpSerializer::SERIALIZED_CONTENT_TYPE, | ||
'Retrinko\Serializer\Serializers\PhpSerializer'], | ||
[JsonSerializer::SERIALIZED_CONTENT_TYPE, | ||
'Retrinko\Serializer\Serializers\JsonSerializer'], | ||
[NullSerializer::SERIALIZED_CONTENT_TYPE, | ||
'Retrinko\Serializer\Serializers\NullSerializer'] | ||
]; | ||
} | ||
|
||
/** | ||
* @dataProvider supportedContentTypesProvider | ||
* | ||
* @param string $contentType | ||
* @param string $expectedSerializerClass | ||
* | ||
* @throws \Retrinko\Serializer\Exceptions\Exception | ||
*/ | ||
public function test_bySerializedContentType_withSupportedContentType_returnsProperSerializer($contentType, $expectedSerializerClass) | ||
{ | ||
$this->assertTrue(SerializerFactory::bySerializedContentType($contentType) instanceof $expectedSerializerClass); | ||
} | ||
|
||
/** | ||
* @expectedException \Retrinko\Serializer\Exceptions\Exception | ||
*/ | ||
public function test_bySerializedContentType_withUnsupportedContentType_thowsException() | ||
{ | ||
SerializerFactory::bySerializedContentType('unsupported content type'); | ||
} | ||
} |
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,30 @@ | ||
<?php | ||
|
||
|
||
namespace Retrinko\Serializer\Test\Unit\Serializers; | ||
|
||
|
||
use Retrinko\Serializer\Serializers\JsonSerializer; | ||
|
||
class JsonSerizalizerTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
public function test_getSerializedContentType_returnsProperValue() | ||
{ | ||
$expected = 'application/json'; | ||
$this->assertEquals($expected, (new JsonSerializer())->getSerializedContentType()); | ||
} | ||
|
||
public function test_serialize_retrunsProperValue() | ||
{ | ||
$test = ['a', 'b', 'c']; | ||
$expected = json_encode($test); | ||
$this->assertEquals($expected, (new JsonSerializer())->serialize($test)); | ||
} | ||
|
||
public function test_unserialize_retrunsProperValue() | ||
{ | ||
$test = '["a","b","c"]'; | ||
$expected = json_decode($test, true); | ||
$this->assertEquals($expected, (new JsonSerializer())->unserialize($test)); | ||
} | ||
} |
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,30 @@ | ||
<?php | ||
|
||
|
||
namespace Retrinko\Serializer\Test\Unit\Serializers; | ||
|
||
|
||
use Retrinko\Serializer\Serializers\NullSerializer; | ||
|
||
class NullSerizalizerTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
public function test_getSerializedContentType_returnsProperValue() | ||
{ | ||
$expected = 'text/plain'; | ||
$this->assertEquals($expected, (new NullSerializer())->getSerializedContentType()); | ||
} | ||
|
||
public function test_serialize_retrunsProperValue() | ||
{ | ||
$test = ['a', 'b', 'c']; | ||
$expected = $test; | ||
$this->assertEquals($expected, (new NullSerializer())->serialize($test)); | ||
} | ||
|
||
public function test_unserialize_retrunsProperValue() | ||
{ | ||
$test = '["a","b","c"]'; | ||
$expected = $test; | ||
$this->assertEquals($expected, (new NullSerializer())->unserialize($test)); | ||
} | ||
} |
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,30 @@ | ||
<?php | ||
|
||
|
||
namespace Retrinko\Serializer\Test\Unit\Serializers; | ||
|
||
|
||
use Retrinko\Serializer\Serializers\PhpSerializer; | ||
|
||
class PhpSerizalizerTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
public function test_getSerializedContentType_returnsProperValue() | ||
{ | ||
$expected = 'application/php/serialize/base64_encode'; | ||
$this->assertEquals($expected, (new PhpSerializer())->getSerializedContentType()); | ||
} | ||
|
||
public function test_serialize_retrunsProperValue() | ||
{ | ||
$test = ['a', 'b', 'c']; | ||
$expected = base64_encode(serialize($test)); | ||
$this->assertEquals($expected, (new PhpSerializer())->serialize($test)); | ||
} | ||
|
||
public function test_unserialize_retrunsProperValue() | ||
{ | ||
$expected = ['a', 'b', 'c']; | ||
$test = base64_encode(serialize($expected)); | ||
$this->assertEquals($expected, (new PhpSerializer())->unserialize($test)); | ||
} | ||
} |